1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Replace _IRR_DEBUG_BREAK_IF with assertions

This commit is contained in:
Lars Mueller 2025-04-04 01:26:02 +02:00 committed by Lars Müller
parent 2f464843cb
commit 5f1ff453c9
22 changed files with 96 additions and 91 deletions

View file

@ -11,6 +11,7 @@
#include "IIndexBuffer.h"
#include "EHardwareBufferFlags.h"
#include "EPrimitiveTypes.h"
#include <cassert>
namespace irr
{
@ -121,7 +122,7 @@ public:
/** \return Pointer to indices array. */
inline const u16 *getIndices() const
{
_IRR_DEBUG_BREAK_IF(getIndexBuffer()->getType() != video::EIT_16BIT);
assert(getIndexBuffer()->getType() == video::EIT_16BIT);
return static_cast<const u16*>(getIndexBuffer()->getData());
}
@ -129,7 +130,7 @@ public:
/** \return Pointer to indices array. */
inline u16 *getIndices()
{
_IRR_DEBUG_BREAK_IF(getIndexBuffer()->getType() != video::EIT_16BIT);
assert(getIndexBuffer()->getType() == video::EIT_16BIT);
return static_cast<u16*>(getIndexBuffer()->getData());
}

View file

@ -5,6 +5,7 @@
#pragma once
#include "irrTypes.h"
#include <cassert>
namespace irr
{
@ -118,7 +119,7 @@ public:
bool drop() const
{
// someone is doing bad reference counting.
_IRR_DEBUG_BREAK_IF(ReferenceCounter <= 0)
assert(ReferenceCounter > 0);
--ReferenceCounter;
if (!ReferenceCounter) {

View file

@ -16,6 +16,7 @@
#include <list>
#include <optional>
#include <string>
#include <cassert>
namespace irr
{
@ -268,7 +269,7 @@ public:
return false;
// The iterator must be set since the parent is not null.
_IRR_DEBUG_BREAK_IF(!child->ThisIterator.has_value());
assert(child->ThisIterator.has_value());
auto it = *child->ThisIterator;
child->ThisIterator = std::nullopt;
child->Parent = nullptr;

View file

@ -8,6 +8,7 @@
#include "CVertexBuffer.h"
#include "CIndexBuffer.h"
#include "S3DVertex.h"
#include <cassert>
namespace irr
{
@ -200,7 +201,7 @@ public:
//! append the vertices and indices to the current buffer
void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override
{
_IRR_DEBUG_BREAK_IF(true);
assert(false);
}
//! Describe what kind of primitive geometry is used by the meshbuffer

View file

@ -6,6 +6,7 @@
#include <algorithm>
#include <iterator>
#include <vector>
#include <cassert>
#include "irrTypes.h"
#include "irrMath.h"
@ -108,7 +109,7 @@ public:
\param index: Where position to insert the new element. */
void insert(const T &element, u32 index = 0)
{
_IRR_DEBUG_BREAK_IF(index > m_data.size()) // access violation
assert(index <= m_data.size());
auto pos = std::next(m_data.begin(), index);
m_data.insert(pos, element);
is_sorted = false;
@ -190,32 +191,28 @@ public:
//! Direct access operator
T &operator[](u32 index)
{
_IRR_DEBUG_BREAK_IF(index >= m_data.size()) // access violation
assert(index < m_data.size());
return m_data[index];
}
//! Direct const access operator
const T &operator[](u32 index) const
{
_IRR_DEBUG_BREAK_IF(index >= m_data.size()) // access violation
assert(index < m_data.size());
return m_data[index];
}
//! Gets last element.
T &getLast()
{
_IRR_DEBUG_BREAK_IF(m_data.empty()) // access violation
assert(!m_data.empty());
return m_data.back();
}
//! Gets last element
const T &getLast() const
{
_IRR_DEBUG_BREAK_IF(m_data.empty()) // access violation
assert(!m_data.empty());
return m_data.back();
}
@ -365,7 +362,7 @@ public:
\param index: Index of element to be erased. */
void erase(u32 index)
{
_IRR_DEBUG_BREAK_IF(index >= m_data.size()) // access violation
assert(index < m_data.size());
auto it = std::next(m_data.begin(), index);
m_data.erase(it);
}

View file

@ -11,6 +11,7 @@
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <cassert>
/* HACK: import these string methods from MT's util/string.h */
extern std::wstring utf8_to_wide(std::string_view input);
@ -174,9 +175,9 @@ public:
}
if constexpr (sizeof(T) != sizeof(B)) {
_IRR_DEBUG_BREAK_IF(
(uintptr_t)c >= (uintptr_t)(str.data()) &&
(uintptr_t)c < (uintptr_t)(str.data() + str.size()));
assert(
(uintptr_t)c < (uintptr_t)(str.data()) ||
(uintptr_t)c >= (uintptr_t)(str.data() + str.size()));
}
if ((void *)c == (void *)c_str())

View file

@ -5,6 +5,7 @@
#pragma once
#include <cstdint>
#include <cassert>
namespace irr
{
@ -65,22 +66,6 @@ typedef char fschar_t;
} // end namespace irr
//! define a break macro for debugging.
#if defined(_DEBUG)
#if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER)
#include <crtdbg.h>
#define _IRR_DEBUG_BREAK_IF(_CONDITION_) \
if (_CONDITION_) { \
_CrtDbgBreak(); \
}
#else
#include <assert.h>
#define _IRR_DEBUG_BREAK_IF(_CONDITION_) assert(!(_CONDITION_));
#endif
#else
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
#endif
//! deprecated macro for virtual function override
/** prefer to use the override keyword for new code */
#define _IRR_OVERRIDE_ override
@ -89,13 +74,13 @@ typedef char fschar_t;
// Note: an assert(false) is included first to catch this in debug builds
#if defined(__cpp_lib_unreachable)
#include <utility>
#define IRR_CODE_UNREACHABLE() do { _IRR_DEBUG_BREAK_IF(1) std::unreachable(); } while(0)
#define IRR_CODE_UNREACHABLE() do { assert(false); std::unreachable(); } while(0)
#elif defined(__has_builtin)
#if __has_builtin(__builtin_unreachable)
#define IRR_CODE_UNREACHABLE() do { _IRR_DEBUG_BREAK_IF(1) __builtin_unreachable(); } while(0)
#define IRR_CODE_UNREACHABLE() do { assert(false); __builtin_unreachable(); } while(0)
#endif
#elif defined(_MSC_VER)
#define IRR_CODE_UNREACHABLE() do { _IRR_DEBUG_BREAK_IF(1) __assume(false); } while(0)
#define IRR_CODE_UNREACHABLE() do { assert(false); __assume(false); } while(0)
#endif
#ifndef IRR_CODE_UNREACHABLE
#define IRR_CODE_UNREACHABLE() (void)0

View file

@ -12,6 +12,7 @@
#include "aabbox3d.h"
#include "rect.h"
#include "IrrCompileConfig.h" // for IRRLICHT_API
#include <cassert>
namespace irr
{
@ -1198,10 +1199,10 @@ inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixPerspectiveFovRH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
{
const f64 h = reciprocal(tan(fieldOfViewRadians * 0.5));
_IRR_DEBUG_BREAK_IF(aspectRatio == 0.f); // divide by zero
assert(aspectRatio != 0.f); // divide by zero
const T w = static_cast<T>(h / aspectRatio);
_IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero
assert(zNear != zFar); // divide by zero
M[0] = w;
M[1] = 0;
M[2] = 0;
@ -1240,10 +1241,10 @@ inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixPerspectiveFovLH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
{
const f64 h = reciprocal(tan(fieldOfViewRadians * 0.5));
_IRR_DEBUG_BREAK_IF(aspectRatio == 0.f); // divide by zero
assert(aspectRatio != 0.f); // divide by zero
const T w = static_cast<T>(h / aspectRatio);
_IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero
assert(zNear != zFar); // divide by zero
M[0] = w;
M[1] = 0;
M[2] = 0;
@ -1282,7 +1283,7 @@ inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixPerspectiveFovInfinityLH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 epsilon)
{
const f64 h = reciprocal(tan(fieldOfViewRadians * 0.5));
_IRR_DEBUG_BREAK_IF(aspectRatio == 0.f); // divide by zero
assert(aspectRatio != 0.f); // divide by zero
const T w = static_cast<T>(h / aspectRatio);
M[0] = w;
@ -1313,9 +1314,9 @@ template <class T>
inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixOrthoLH(
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero)
{
_IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero
assert(widthOfViewVolume != 0.f); // divide by zero
assert(heightOfViewVolume != 0.f); // divide by zero
assert(zNear != zFar); // divide by zero
M[0] = (T)(2 / widthOfViewVolume);
M[1] = 0;
M[2] = 0;
@ -1352,9 +1353,9 @@ template <class T>
inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixOrthoRH(
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero)
{
_IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero
assert(widthOfViewVolume != 0.f); // divide by zero
assert(heightOfViewVolume != 0.f); // divide by zero
assert(zNear != zFar); // divide by zero
M[0] = (T)(2 / widthOfViewVolume);
M[1] = 0;
M[2] = 0;
@ -1391,9 +1392,9 @@ template <class T>
inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixPerspectiveRH(
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero)
{
_IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero
assert(widthOfViewVolume != 0.f); // divide by zero
assert(heightOfViewVolume != 0.f); // divide by zero
assert(zNear != zFar); // divide by zero
M[0] = (T)(2 * zNear / widthOfViewVolume);
M[1] = 0;
M[2] = 0;
@ -1431,9 +1432,9 @@ template <class T>
inline CMatrix4<T> &CMatrix4<T>::buildProjectionMatrixPerspectiveLH(
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero)
{
_IRR_DEBUG_BREAK_IF(widthOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(heightOfViewVolume == 0.f); // divide by zero
_IRR_DEBUG_BREAK_IF(zNear == zFar); // divide by zero
assert(widthOfViewVolume != 0.f); // divide by zero
assert(heightOfViewVolume != 0.f); // divide by zero
assert(zNear != zFar); // divide by zero
M[0] = (T)(2 * zNear / widthOfViewVolume);
M[1] = 0;
M[2] = 0;

View file

@ -9,6 +9,7 @@
#include <functional>
#include <array>
#include <cassert>
namespace irr
{

View file

@ -8,6 +8,7 @@
#include <functional>
#include <array>
#include <cassert>
namespace irr
{