Skip to content

Commit e9487a1

Browse files
committed
Simplify R_ASSERT_CURE macros
Always assume that cure can be used Also, corrected ignoreAlways usage so that it won't interfere with the cure
1 parent 4f54b6d commit e9487a1

File tree

10 files changed

+52
-84
lines changed

10 files changed

+52
-84
lines changed

src/Layers/xrRender/Texture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ IC u32 it_height_rev_base(u32 d, u32 s)
253253
ID3DBaseTexture* CRender::texture_load(LPCSTR fRName, u32& ret_msize)
254254
{
255255
ret_msize = 0;
256-
R_ASSERT1_CURE(fRName && fRName[0], true, { return nullptr; });
256+
R_ASSERT1_CURE(fRName && fRName[0], { return nullptr; });
257257

258258
HRESULT result;
259259
ID3DTexture2D* pTexture2D = nullptr;

src/Layers/xrRenderDX11/dx11Texture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ IC u32 it_height_rev_base(u32 d, u32 s) { return color_rgba (
275275
ID3DBaseTexture* CRender::texture_load(LPCSTR fRName, u32& ret_msize)
276276
{
277277
ret_msize = 0;
278-
R_ASSERT1_CURE(fRName && fRName[0], true, { return nullptr; });
278+
R_ASSERT1_CURE(fRName && fRName[0], { return nullptr; });
279279

280280
DirectX::TexMetadata IMG;
281281
DirectX::ScratchImage texture;
@@ -316,7 +316,7 @@ ID3DBaseTexture* CRender::texture_load(LPCSTR fRName, u32& ret_msize)
316316
{
317317
// Load and get header
318318
S = FS.r_open(fn);
319-
R_ASSERT2_CURE(S, fn, true, { return nullptr; });
319+
R_ASSERT2_CURE(S, fn, { return nullptr; });
320320

321321
img_size = S->length();
322322
#ifdef DEBUG

src/Layers/xrRenderGL/glTexture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ u32 calc_texture_size(int lod, u32 mip_cnt, size_t orig_size)
6161
GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
6262
{
6363
ret_msize = 0;
64-
R_ASSERT1_CURE(fRName && fRName[0], true, { return 0; });
64+
R_ASSERT1_CURE(fRName && fRName[0], { return 0; });
6565

6666
GLuint pTexture = 0;
6767
string_path fn;
@@ -101,7 +101,7 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
101101
{
102102
// Load and get header
103103
S = FS.r_open(fn);
104-
R_ASSERT2_CURE(S, fn, true, { return 0; });
104+
R_ASSERT2_CURE(S, fn, { return 0; });
105105
img_size = S->length();
106106
#ifdef DEBUG
107107
Msg("* Loaded: %s[%d]b", fn, img_size);

src/xrCore/Crypto/xr_sha.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ static_assert(xr_sha1::DigestSize == SHA_DIGEST_LENGTH);
1515
xr_sha1::hash_t xr_sha1::calculate_with_yielder(const u8* data, u32 data_size, const yielder_t& yielder)
1616
{
1717
#ifdef USE_OPENSSL
18-
R_ASSERT1_CURE(data && data_size, true,
18+
R_ASSERT1_CURE(data && data_size,
1919
{
2020
return {};
2121
});
2222

2323
EVP_MD_CTX* sha_ctx = EVP_MD_CTX_new();
24-
R_ASSERT1_CURE(sha_ctx, true,
24+
R_ASSERT1_CURE(sha_ctx,
2525
{
2626
return {};
2727
});
28-
R_ASSERT1_CURE(EVP_DigestInit_ex(sha_ctx, EVP_sha1(), nullptr) != 0, true,
28+
R_ASSERT1_CURE(EVP_DigestInit_ex(sha_ctx, EVP_sha1(), nullptr) != 0,
2929
{
3030
EVP_MD_CTX_free(sha_ctx);
3131
return {};

src/xrCore/xrDebug_macros.h

Lines changed: 36 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -65,59 +65,51 @@
6565
#ifdef DEBUG
6666
#define NODEFAULT FATAL("nodefault reached")
6767

68-
#define R_ASSERT1_CURE(expr, can_be_cured, cure)\
68+
#define R_ASSERT1_CURE(expr, cure)\
6969
do\
7070
{\
71-
static bool ignoreAlways = false;\
72-
if (!ignoreAlways && !(expr))\
71+
if (!(expr))\
7372
{\
74-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr);\
75-
if (can_be_cured)\
76-
{\
77-
cure;\
78-
}\
73+
static bool ignoreAlways = false;\
74+
if (!ignoreAlways)\
75+
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr);\
76+
cure;\
7977
}\
8078
} while (false)
8179

82-
#define R_ASSERT2_CURE(expr, desc, can_be_cured, cure)\
80+
#define R_ASSERT2_CURE(expr, desc, cure)\
8381
do\
8482
{\
85-
static bool ignoreAlways = false;\
86-
if (!ignoreAlways && !(expr))\
83+
if (!(expr))\
8784
{\
88-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc);\
89-
if (can_be_cured)\
90-
{\
91-
cure;\
92-
}\
85+
static bool ignoreAlways = false;\
86+
if (!ignoreAlways)\
87+
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc);\
88+
cure;\
9389
}\
9490
} while (false)
9591

96-
#define R_ASSERT3_CURE(expr, desc, arg1, can_be_cured, cure)\
92+
#define R_ASSERT3_CURE(expr, desc, arg1, cure)\
9793
do\
9894
{\
99-
static bool ignoreAlways = false;\
100-
if (!ignoreAlways && !(expr))\
95+
if (!(expr))\
10196
{\
102-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc, arg1);\
103-
if (can_be_cured)\
104-
{\
105-
cure;\
106-
}\
97+
static bool ignoreAlways = false;\
98+
if (!ignoreAlways)\
99+
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc, arg1);\
100+
cure;\
107101
}\
108102
} while (false)
109103

110-
#define R_ASSERT4_CURE(expr, cure, desc, arg1, arg2, can_be_cured)\
104+
#define R_ASSERT4_CURE(expr, cure, desc, arg1, arg2)\
111105
do\
112106
{\
113-
static bool ignoreAlways = false;\
114-
if (!ignoreAlways && !(expr))\
107+
if (!(expr))\
115108
{\
116-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc, arg1, arg2);\
117-
if (can_be_cured)\
118-
{\
119-
cure;\
120-
}\
109+
static bool ignoreAlways = false;\
110+
if (!ignoreAlways)\
111+
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc, arg1, arg2);\
112+
cure;\
121113
}\
122114
} while (false)
123115

@@ -167,63 +159,39 @@
167159
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, (long)err);\
168160
} while (false)
169161
#else // DEBUG
170-
#define R_ASSERT1_CURE(expr, can_be_cured, cure)\
162+
#define R_ASSERT1_CURE(expr, cure)\
171163
do\
172164
{\
173-
static bool ignoreAlways = false;\
174-
if (!ignoreAlways && !(expr))\
165+
if (!(expr))\
175166
{\
176-
if (!can_be_cured)\
177-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr);\
178-
else\
179-
{\
180-
cure;\
181-
}\
167+
cure;\
182168
}\
183169
} while (false)
184170

185-
#define R_ASSERT2_CURE(expr, desc, can_be_cured, cure)\
171+
#define R_ASSERT2_CURE(expr, desc, cure)\
186172
do\
187173
{\
188-
static bool ignoreAlways = false;\
189-
if (!ignoreAlways && !(expr))\
174+
if (!(expr))\
190175
{\
191-
if (!can_be_cured)\
192-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc);\
193-
else\
194-
{\
195-
cure;\
196-
}\
176+
cure;\
197177
}\
198178
} while (false)
199179

200-
#define R_ASSERT3_CURE(expr, desc, arg1, can_be_cured, cure)\
180+
#define R_ASSERT3_CURE(expr, desc, arg1, cure)\
201181
do\
202182
{\
203-
static bool ignoreAlways = false;\
204-
if (!ignoreAlways && !(expr))\
183+
if (!(expr))\
205184
{\
206-
if (!can_be_cured)\
207-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc, arg1);\
208-
else\
209-
{\
210-
cure;\
211-
}\
185+
cure;\
212186
}\
213187
} while (false)
214188

215-
#define R_ASSERT4_CURE(expr, cure, desc, arg1, arg2, can_be_cured)\
189+
#define R_ASSERT4_CURE(expr, cure, desc, arg1, arg2)\
216190
do\
217191
{\
218-
static bool ignoreAlways = false;\
219-
if (!ignoreAlways && !(expr))\
192+
if (!(expr))\
220193
{\
221-
if (!can_be_cured)\
222-
xrDebug::Fail(ignoreAlways, DEBUG_INFO, #expr, desc, arg1, arg2);\
223-
else\
224-
{\
225-
cure;\
226-
}\
194+
cure;\
227195
}\
228196
} while (false)
229197

src/xrSound/SoundRender_Core_StartStop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
void CSoundRender_Core::i_start(CSoundRender_Emitter* E) const
99
{
10-
R_ASSERT1_CURE(E, true, { return; });
10+
R_ASSERT1_CURE(E, { return; });
1111

1212
// Search lowest-priority target
1313
float Ptarget = flt_max;

src/xrSound/SoundRender_Emitter_StartStop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void CSoundRender_Emitter::cancel()
110110
void CSoundRender_Emitter::stop_target()
111111
{
112112
wait_prefill();
113-
R_ASSERT1_CURE(target, true, { return; });
113+
R_ASSERT1_CURE(target, { return; });
114114
target->stop();
115115
target = nullptr;
116116
}

src/xrSound/SoundRender_Source.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool CSoundRender_Source::LoadWave(pcstr pName)
169169
const vorbis_info* ovi = ov_info(&ovf, -1);
170170

171171
// verify
172-
R_ASSERT3_CURE(ovi, "Invalid source info:", pName, true,
172+
R_ASSERT3_CURE(ovi, "Invalid source info:", pName,
173173
{
174174
ov_clear(&ovf);
175175
return false;
@@ -244,7 +244,7 @@ bool CSoundRender_Source::LoadWave(pcstr pName)
244244
#endif
245245
}
246246

247-
R_ASSERT3_CURE(m_info.maxAIDist >= 0.1f && m_info.maxDist >= 0.1f, "Invalid max distance.", pName, true,
247+
R_ASSERT3_CURE(m_info.maxAIDist >= 0.1f && m_info.maxDist >= 0.1f, "Invalid max distance.", pName,
248248
{
249249
ov_clear(&ovf);
250250
return false;

src/xrSound/SoundRender_Target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
void CSoundRender_Target::start(CSoundRender_Emitter* E)
88
{
9-
R_ASSERT1_CURE(E, true, { return; });
9+
R_ASSERT1_CURE(E, { return; });
1010

1111
// *** Initial buffer startup ***
1212
// 1. Fill parameters
@@ -37,7 +37,7 @@ void CSoundRender_Target::rewind()
3737

3838
void CSoundRender_Target::update()
3939
{
40-
R_ASSERT1_CURE(m_pEmitter, true, { return; });
40+
R_ASSERT1_CURE(m_pEmitter, { return; });
4141
}
4242

4343
void CSoundRender_Target::fill_parameters()

src/xrSound/SoundRender_TargetA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void CSoundRender_TargetA::update()
142142

143143
void CSoundRender_TargetA::fill_parameters()
144144
{
145-
R_ASSERT1_CURE(m_pEmitter, true, { return; });
145+
R_ASSERT1_CURE(m_pEmitter, { return; });
146146
inherited::fill_parameters();
147147

148148
// 3D params
@@ -177,7 +177,7 @@ void CSoundRender_TargetA::fill_parameters()
177177

178178
void CSoundRender_TargetA::submit_buffer(ALuint BufferID) const
179179
{
180-
R_ASSERT1_CURE(m_pEmitter, true, { return; });
180+
R_ASSERT1_CURE(m_pEmitter, { return; });
181181
const auto [data, dataSize] = m_pEmitter->obtain_block();
182182
A_CHK(alBufferData(BufferID, dataFormat, data, static_cast<ALsizei>(dataSize), sampleRate));
183183
}

0 commit comments

Comments
 (0)