Skip to content

Commit def250d

Browse files
committed
Replaced ASSERT_THROW using false as conditional with ASSERT_FAIL.
1 parent 5586b68 commit def250d

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

source/Component/ParticleEmitter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace Component
9494
return ColourSource::ConstantColour;
9595
}
9696
else // Invalid state
97-
ASSERT_THROW(false, "Invalid colour source state. ParticleEmitter needs either a colour or a texture.")
97+
ASSERT_FAIL("Invalid colour source state. ParticleEmitter needs either a colour or a texture.");
9898
}
9999
enum class SizeSource : uint8_t
100100
{

source/OpenGL/GLState.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ namespace OpenGL
590590
case BufferDataType::UnsignedInt: return GL_UNSIGNED_INT;
591591
case BufferDataType::Float: return GL_FLOAT;
592592
case BufferDataType::Double: return GL_DOUBLE;
593-
default: ASSERT_THROW(false, "[OPENGL] Unknown BufferDataType requested");
593+
default: ASSERT_FAIL("[OPENGL] Unknown BufferDataType requested");
594594
}
595595
}
596596
GLenum convert(BufferStorageFlag p_flag)
@@ -603,7 +603,7 @@ namespace OpenGL
603603
case BufferStorageFlag::MapPersistentBit: return GL_MAP_PERSISTENT_BIT;
604604
case BufferStorageFlag::MapCoherentBit: return GL_MAP_COHERENT_BIT;
605605
case BufferStorageFlag::ClientStorageBit: return GL_CLIENT_STORAGE_BIT;
606-
default: ASSERT_THROW(false, "[OPENGL] Unknown BufferStorageFlag requested"); return 0;
606+
default: ASSERT_FAIL("[OPENGL] Unknown BufferStorageFlag requested");
607607
}
608608
}
609609
GLenum convert(MemoryBarrierFlag p_barrier_bitfield)
@@ -623,7 +623,7 @@ namespace OpenGL
623623
case MemoryBarrierFlag::TransformFeedbackBarrierBit: return GL_TRANSFORM_FEEDBACK_BARRIER_BIT;
624624
case MemoryBarrierFlag::AtomicCounterBarrierBit: return GL_ATOMIC_COUNTER_BARRIER_BIT;
625625
case MemoryBarrierFlag::ShaderStorageBarrierBit: return GL_SHADER_STORAGE_BARRIER_BIT;
626-
default: ASSERT_THROW(false, "[OPENGL] Unknown MemoryBarrierFlag requested"); return 0;
626+
default: ASSERT_FAIL("[OPENGL] Unknown MemoryBarrierFlag requested");
627627
}
628628

629629
}

source/OpenGL/ParticleRenderer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace OpenGL
161161
dc.m_destination_factor = BlendFactorType::One;
162162
}
163163
else
164-
ASSERT_THROW(false, "Unknown blending style.");
164+
ASSERT_FAIL("Unknown blending style.");
165165

166166
dc.set_UBO("ViewProperties", p_view_properties);
167167

@@ -205,7 +205,7 @@ namespace OpenGL
205205
dc.set_texture("end_diffuse", p_emitter.end_texture->m_GL_texture);
206206
break;
207207
default:
208-
ASSERT_THROW(false, "Unknown colour source")
208+
ASSERT_FAIL("Unknown colour source")
209209
}
210210
switch (size_source)
211211
{
@@ -217,7 +217,7 @@ namespace OpenGL
217217
dc.set_uniform("end_size", p_emitter.end_size.value());
218218
break;
219219
default:
220-
ASSERT_THROW(false, "Unknown size source")
220+
ASSERT_FAIL("Unknown size source")
221221
}
222222

223223
constexpr GLuint vertex_buffer_binding_point = 0;
@@ -246,7 +246,7 @@ namespace OpenGL
246246
case Component::ParticleEmitter::SizeSource::Varying:
247247
return m_particle_draw_constant_colour_varying_size;
248248
default:
249-
ASSERT_THROW(false, "Unknown size source")
249+
ASSERT_FAIL("Unknown size source")
250250
}
251251
case Component::ParticleEmitter::ColourSource::ConstantTexture:
252252
switch (p_size_source)
@@ -256,7 +256,7 @@ namespace OpenGL
256256
case Component::ParticleEmitter::SizeSource::Varying:
257257
return m_particle_draw_constant_texture_varying_size;
258258
default:
259-
ASSERT_THROW(false, "Unknown size source")
259+
ASSERT_FAIL("Unknown size source")
260260
}
261261
case Component::ParticleEmitter::ColourSource::ConstantColourAndTexture:
262262
switch (p_size_source)
@@ -266,7 +266,7 @@ namespace OpenGL
266266
case Component::ParticleEmitter::SizeSource::Varying:
267267
return m_particle_draw_constant_colour_and_texture_varying_size;
268268
default:
269-
ASSERT_THROW(false, "Unknown size source")
269+
ASSERT_FAIL("Unknown size source")
270270
}
271271
case Component::ParticleEmitter::ColourSource::VaryingColour:
272272
switch (p_size_source)
@@ -276,7 +276,7 @@ namespace OpenGL
276276
case Component::ParticleEmitter::SizeSource::Varying:
277277
return m_particle_draw_varying_colour_varying_size;
278278
default:
279-
ASSERT_THROW(false, "Unknown size source")
279+
ASSERT_FAIL("Unknown size source")
280280
}
281281
case Component::ParticleEmitter::ColourSource::VaryingTexture:
282282
switch (p_size_source)
@@ -286,7 +286,7 @@ namespace OpenGL
286286
case Component::ParticleEmitter::SizeSource::Varying:
287287
return m_particle_draw_varying_texture_varying_size;
288288
default:
289-
ASSERT_THROW(false, "Unknown size source")
289+
ASSERT_FAIL("Unknown size source")
290290
}
291291
case Component::ParticleEmitter::ColourSource::VaryingColourConstantTexture:
292292
switch (p_size_source)
@@ -296,7 +296,7 @@ namespace OpenGL
296296
case Component::ParticleEmitter::SizeSource::Varying:
297297
return m_particle_draw_varying_colour_constant_texture_varying_size;
298298
default:
299-
ASSERT_THROW(false, "Unknown size source")
299+
ASSERT_FAIL("Unknown size source")
300300
}
301301
case Component::ParticleEmitter::ColourSource::ConstantColourVaryingTexture:
302302
switch (p_size_source)
@@ -306,7 +306,7 @@ namespace OpenGL
306306
case Component::ParticleEmitter::SizeSource::Varying:
307307
return m_particle_draw_constant_colour_varying_texture_varying_size;
308308
default:
309-
ASSERT_THROW(false, "Unknown size source")
309+
ASSERT_FAIL("Unknown size source")
310310
}
311311
case Component::ParticleEmitter::ColourSource::VaryingColourAndTexture:
312312
switch (p_size_source)
@@ -316,10 +316,10 @@ namespace OpenGL
316316
case Component::ParticleEmitter::SizeSource::Varying:
317317
return m_particle_draw_varying_colour_and_texture_varying_size;
318318
default:
319-
ASSERT_THROW(false, "Unknown size source")
319+
ASSERT_FAIL("Unknown size source")
320320
}
321321
default:
322-
ASSERT_THROW(false, "Unknown colour source")
322+
ASSERT_FAIL("Unknown colour source")
323323
}
324324
};
325325

source/Platform/Core.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ namespace Platform
8484

8585
if (severity == GL_DEBUG_SEVERITY_HIGH)
8686
{
87-
ASSERT_THROW(false, "[OpenGL][{}][{}][{}]: {}", src, sv, tp, message);
87+
ASSERT_FAIL("[OpenGL][{}][{}][{}]: {}", src, sv, tp, message);
8888
}
8989
else if (severity == GL_DEBUG_SEVERITY_MEDIUM)
9090
{
91-
ASSERT_THROW(false, "[OpenGL][{}][{}][{}]: {}", src, sv, tp, message);
91+
ASSERT_FAIL("[OpenGL][{}][{}][{}]: {}", src, sv, tp, message);
9292
}
9393
else if (severity == GL_DEBUG_SEVERITY_LOW)
9494
{
@@ -212,7 +212,7 @@ namespace Platform
212212
{
213213
case FileDialogFilter::All: ofn.lpstrFilter = "All Files\0*.*\0"; break;
214214
case FileDialogFilter::Scene: ofn.lpstrFilter = scene_filter.c_str(); break;
215-
default: ASSERT_THROW(false, "Invalid FileDialogFilter");
215+
default: ASSERT_FAIL("Invalid FileDialogFilter");
216216
}
217217

218218
std::filesystem::path selected_path;
@@ -229,7 +229,7 @@ namespace Platform
229229
if (GetOpenFileNameA(&ofn) == TRUE) selected_path = std::filesystem::path(ofn.lpstrFile);
230230
break;
231231
}
232-
default: ASSERT_THROW(false, "Invalid FileDialogType");
232+
default: ASSERT_FAIL("Invalid FileDialogType");
233233
}
234234

235235
// Append the .ss extension if not present
@@ -239,7 +239,7 @@ namespace Platform
239239
return selected_path;
240240
#else
241241
(void)p_type; (void)p_filter; (void)p_title; (void)p_start_path;
242-
ASSERT_THROW(false, "file_dialog not implemented for this platform");
242+
ASSERT_FAIL("file_dialog not implemented for this platform");
243243
#endif
244244
}
245245
} // namespace Platform

source/Utility/File.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ namespace Utility
2929
}
3030
catch (std::ifstream::failure& e)
3131
{
32-
ASSERT_THROW(false, "File not successfully read, exception thrown: {}", e.what());
32+
ASSERT_FAIL("File not successfully read, exception thrown: {}", e.what());
3333
}
34-
35-
return "";
3634
}
3735

3836
void File::foreach_file(const std::filesystem::path& p_directory, const std::function<void(const std::filesystem::directory_entry& p_entry)>& p_function)

source/Utility/Logger.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void Logger::log_warning(const std::string& p_message, const std::source_locatio
3939
}
4040
void Logger::log_error(const std::string& p_message, const std::source_location& p_location)
4141
{
42-
const auto error_str = std::format("[ERROR] {} -{}", p_message, to_string(p_location));
42+
const auto error_str = std::format("[ERROR] {}\n-{}", p_message, to_string(p_location));
4343

4444
if constexpr (s_log_to_editor)
4545
{
@@ -48,17 +48,23 @@ void Logger::log_error(const std::string& p_message, const std::source_location&
4848
}
4949

5050
if constexpr (s_log_to_console)
51-
std::cout << error_str << std::endl;
51+
std::cerr << error_str << std::endl;
5252

5353
//if constexpr (s_log_to_file)
5454
// TODO
5555
}
56-
void Logger::assert_fail(const std::string& p_conditional, const std::string& p_message, const std::source_location& p_location)
56+
[[noreturn]] void Logger::assert_fail(const std::string& p_conditional, const std::string& p_message, const std::source_location& p_location)
5757
{
5858
const auto assert_fail_str = std::format("ASSERT FAILED: '{}' - {}", p_conditional, p_message);
5959
log_error(assert_fail_str, p_location);
6060
throw std::logic_error(assert_fail_str);
6161
}
62+
[[noreturn]] void Logger::assert_fail(const std::string& p_message, const std::source_location& p_location)
63+
{
64+
const auto assert_fail_str = std::format("ASSERT FAILED: '{}'", p_message);
65+
log_error(assert_fail_str, p_location);
66+
throw std::logic_error(assert_fail_str);
67+
}
6268

6369
std::string Logger::to_string(const std::source_location& p_location)
6470
{

source/Utility/Logger.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class Logger
1414
static void log_info(const std::string& p_message);
1515
static void log_warning(const std::string& p_message, const std::source_location& p_location = std::source_location::current());
1616
static void log_error(const std::string& p_message, const std::source_location& p_location = std::source_location::current());
17-
static void assert_fail(const std::string& p_conditional, const std::string& p_message, const std::source_location& p_location = std::source_location::current());
17+
[[noreturn]] static void assert_fail(const std::string& p_conditional, const std::string& p_message, const std::source_location& p_location = std::source_location::current());
18+
[[noreturn]] static void assert_fail(const std::string& p_message, const std::source_location& p_location = std::source_location::current());
1819
static inline UI::Editor* s_editor_sink = nullptr; // If pointing to an Editor && s_log_to_editor is true, the editor will output the Log message to its console.
1920

2021
private:
@@ -40,7 +41,8 @@ class Logger
4041
#define ASSERT(x, ...) (void)0;
4142
#endif
4243

43-
#define ASSERT_THROW(x, ...) if (!(x)) { Logger::assert_fail(#x, std::format(__VA_ARGS__), std::source_location::current()); throw std::runtime_error(std::format(__VA_ARGS__)); }
44+
#define ASSERT_THROW(x, ...) if (!(x)) { Logger::assert_fail(#x, std::format(__VA_ARGS__), std::source_location::current()); }
45+
#define ASSERT_FAIL(...) { Logger::assert_fail(std::format(__VA_ARGS__), std::source_location::current()); }
4446

4547

4648
#if defined(_MSC_VER)

0 commit comments

Comments
 (0)