Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
assert.hpp File Reference
#include <helios/core/core.hpp>
#include <cstdio>
#include <cstdlib>
#include <format>
#include <source_location>
#include <string>
#include <string_view>

Go to the source code of this file.

Namespaces

namespace  helios
 
namespace  helios::details
 

Macros

#define HELIOS_ASSERT(condition, ...)
 Assertion macro that aborts execution in debug builds.
 
#define HELIOS_INVARIANT(condition, ...)
 Invariant check that asserts in debug builds and logs error in release.
 
#define HELIOS_VERIFY(condition, ...)
 Verify macro that always checks the condition.
 
#define HELIOS_VERIFY_LOGGER(logger_name, condition, ...)
 Verify macro with logger name that always checks the condition.
 

Functions

void helios::details::LogAssertionFailureViaLogger (std::string_view condition, const std::source_location &loc, std::string_view message) noexcept
 Bridge to logger-provided assertion logging.
 
void helios::details::LogAssertionFailure (std::string_view condition, const std::source_location &loc, std::string_view message) noexcept
 Unified assertion logging function used by macros below.
 
void helios::details::AssertionFailed (std::string_view condition, const std::source_location &loc, std::string_view message) noexcept
 Assertion handler that logs via the logger system.
 
void helios::AbortWithStacktrace (std::string_view message) noexcept
 Prints a message with stack trace and aborts the program execution.
 

Variables

constexpr bool helios::details::kEnableAssert = false
 

Macro Definition Documentation

◆ HELIOS_ASSERT

#define HELIOS_ASSERT (   condition,
  ... 
)

Assertion macro that aborts execution in debug builds.

Does nothing in release builds. Attempts to use logger if available, falls back to printing via std::println if not. Supports format strings and arguments.

Parameters
conditionThe condition to check
...Optional message (can be format string with arguments)
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/app.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/sub_app.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/system_context.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/details/entities_manager.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/entity_command_buffer.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/query.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/world_command_buffer.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/arena_allocator.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/frame_allocator.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/free_list_allocator.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/growable_allocator.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/pool_allocator.hpp, and /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/stack_allocator.hpp.

Definition at line 140 of file assert.hpp.

◆ HELIOS_INVARIANT

#define HELIOS_INVARIANT (   condition,
  ... 
)

Invariant check that asserts in debug builds and logs error in release.

Provides runtime safety checks that are enforced even in release builds. In debug builds, triggers assertion. In release builds, logs error and continues.

Parameters
conditionThe condition to check
...Optional message (can be format string with arguments)

Definition at line 170 of file assert.hpp.

171 { \
172 if (HELIOS_EXPECT_FALSE(!(condition))) [[unlikely]] { \
173 constexpr auto loc = std::source_location::current(); \
174 if constexpr (sizeof(#__VA_ARGS__) > 1) { \
175 try { \
176 const std::string msg = std::format("" __VA_ARGS__); \
177 ::helios::details::LogAssertionFailure(#condition, loc, msg); \
178 } catch (...) { \
179 ::helios::details::LogAssertionFailure(#condition, loc, ""); \
180 } \
181 } else { \
182 ::helios::details::LogAssertionFailure(#condition, loc, ""); \
183 } \
184 } \
185 } while (false)
#define HELIOS_EXPECT_FALSE(x)
Definition core.hpp:140

◆ HELIOS_VERIFY

#define HELIOS_VERIFY (   condition,
  ... 
)

Verify macro that always checks the condition.

Similar to assert but runs in both debug and release builds. Useful for validating external input or critical invariants.

Parameters
conditionThe condition to check
...Optional message (can be format string with arguments)
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/frame_allocator.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/free_list_allocator.hpp, /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/pool_allocator.hpp, and /home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/memory/stack_allocator.hpp.

Definition at line 196 of file assert.hpp.

197 { \
198 if (HELIOS_EXPECT_FALSE(!(condition))) [[unlikely]] { \
199 constexpr auto loc = std::source_location::current(); \
200 if constexpr (sizeof(#__VA_ARGS__) > 1) { \
201 try { \
202 const std::string msg = std::format("" __VA_ARGS__); \
203 ::helios::details::AssertionFailed(#condition, loc, msg); \
204 } catch (...) { \
205 ::helios::details::AssertionFailed(#condition, loc, "Formatting error in verify"); \
206 } \
207 } else { \
208 ::helios::details::AssertionFailed(#condition, loc, ""); \
209 } \
210 HELIOS_DEBUG_BREAK(); \
211 } \
212 } while (false)

◆ HELIOS_VERIFY_LOGGER

#define HELIOS_VERIFY_LOGGER (   logger_name,
  condition,
  ... 
)

Verify macro with logger name that always checks the condition.

Similar to HELIOS_VERIFY but allows specifying a custom logger.

Note
The custom-logger variant delegates to the same assertion handling; the logger selection is performed by the logger integration function.
Parameters
logger_nameThe name of the logger to use
conditionThe condition to check
...Optional message (can be format string with arguments)

Definition at line 224 of file assert.hpp.

225 { \
226 if (HELIOS_EXPECT_FALSE(!(condition))) [[unlikely]] { \
227 constexpr auto loc = std::source_location::current(); \
228 if constexpr (sizeof(#__VA_ARGS__) > 1) { \
229 try { \
230 const std::string msg = std::format("" __VA_ARGS__); \
231 ::helios::details::AssertionFailed(#condition, loc, msg); \
232 } catch (...) { \
233 ::helios::details::AssertionFailed(#condition, loc, "Formatting error in verify"); \
234 } \
235 } else { \
236 ::helios::details::AssertionFailed(#condition, loc, ""); \
237 } \
238 HELIOS_DEBUG_BREAK(); \
239 } \
240 } while (false)