Failed engine/client assertion

- Separated 'FailedAssertion' into 'FailedEngineAssertion' and
      'FailedClientAssertion'
- Minor adjustment to the change log
This commit is contained in:
Light 2021-07-21 13:52:30 +04:30
parent ac8c515b06
commit 2967cf5675
4 changed files with 51 additions and 23 deletions

View file

@ -9,19 +9,16 @@
#include <memory> #include <memory>
#define LT_WIN(x) // windows
#define LT_LIN(x) // linux
#define LT_MAC(x) // mac
#define LT_VERSION "0.7.0" // version
#define LT_VERSION "0.7.2"
///*** [ CHANGE_LOG ] ***/// ///*** [ CHANGE_LOG ] ***///
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Note: change log starts from 2021-07-21, the starting version is // Note: change log starts from 2021-07-21, the starting version is 0.7.0,
// 0.7.0, I came up with that version because of the engine's major // I came up with that version because of:
// features: // projects: 'Engine', 'Sandbox', 'Mirror' [+0.3]
// projects: 'Engine', 'Sandbox', 'Mirror' + 0.3 // graphics apis: 'OpenGL', 'DirectX11' [+0.2]
// graphics apis: 'OpenGL', 'DirectX11' + 0.2 // platforms: 'Windows', 'Linux' [+0.2]
// platforms: 'Windows', 'Linux' + 0.2
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// //
// 0.7.0: started the change log // 0.7.0: started the change log
@ -29,8 +26,17 @@
// 0.7.1: [ LT_BREAK ] // 0.7.1: [ LT_BREAK ]
// - Added the 'LT_BERAK' macro, a portable debug-trap // - Added the 'LT_BERAK' macro, a portable debug-trap
// //
// 0.7.2: [ Failed engine/client assertion ]
// - Separated 'FailedAssertion' into 'FailedEngineAssertion' and 'FailedClientAssertion'
// - Minor adjustment to the change log
//
///*** [ CHANGE_LOG ] ***/// ///*** [ CHANGE_LOG ] ***///
// platform
#define LT_WIN(x) // windows
#define LT_LIN(x) // linux
#define LT_MAC(x) // mac
#if defined(LIGHT_PLATFORM_WINDOWS) #if defined(LIGHT_PLATFORM_WINDOWS)
#define LT_BUILD_PLATFORM "Windows" #define LT_BUILD_PLATFORM "Windows"
#define LT_WIN(x) x #define LT_WIN(x) x
@ -48,11 +54,13 @@
#endif #endif
// operations
#define BIT(x) 1 << x #define BIT(x) 1 << x
// assertions
// #todo: log to file in distribution builds // #todo: log to file in distribution builds
#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedAssertion(__FILE__, __LINE__); } } #define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedEngineAssertion(__FILE__, __LINE__); } }
#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_BREAK(); } } #define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } } }
///*** [ PORTABLES ] ***/// ///*** [ PORTABLES ] ***///

View file

@ -11,9 +11,14 @@
namespace Light { namespace Light {
FailedAssertion::FailedAssertion(const char* file, int line) FailedEngineAssertion::FailedEngineAssertion(const char* file, int line)
{ {
LT_ENGINE_CRITICAL("FailedAssertion::FailedAssertion: assertion failed in: {} (line {})", file, line); LT_ENGINE_CRITICAL("FailedAssertion::FailedAssertion: engine assertion failed in: {} (line {})", file, line);
}
FailedClientAssertion::FailedClientAssertion(const char* file, int line)
{
LT_ENGINE_CRITICAL("FailedClientAssertion::FailedClientAssertion: client assertion failed in: {} (line {})", file, line);
} }
glException::glException(unsigned int source, unsigned int type, unsigned int id, const char* msg) glException::glException(unsigned int source, unsigned int type, unsigned int id, const char* msg)

View file

@ -4,9 +4,14 @@
namespace Light { namespace Light {
struct FailedAssertion : std::exception struct FailedEngineAssertion : std::exception
{ {
FailedAssertion(const char* file, int line); FailedEngineAssertion(const char* file, int line);
};
struct FailedClientAssertion : std::exception
{
FailedClientAssertion(const char* file, int line);
}; };
// OpenGL // OpenGL

View file

@ -20,20 +20,25 @@ int main(int argc, char** argv)
application->GameLoop(); application->GameLoop();
} }
catch (Light::FailedAssertion) catch (Light::FailedEngineAssertion)
{ {
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedAssertion'"); LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedEngineAssertion'");
exitCode = -1; exitCode = -1;
} }
catch (Light::FailedClientAssertion)
{
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedClientAssertion'");
exitCode = -2;
}
catch(Light::glException) catch(Light::glException)
{ {
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'"); LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'");
exitCode = -2; exitCode = -3;
} }
catch (Light::dxException) catch (Light::dxException)
{ {
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'dxException'"); LT_ENGINE_CRITICAL("main: exitting due to unhandled 'dxException'");
exitCode = -3; exitCode = -4;
} }
delete application; delete application;
@ -60,15 +65,20 @@ int main(int argc, char* argv[])
application->GameLoop(); application->GameLoop();
} }
catch (Light::FailedAssertion) catch (Light::FailedEngineAssertion)
{ {
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedAssertion'"); LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedEngineAssertion'");
exitCode = -1; exitCode = -1;
} }
catch (Light::FailedClientAssertion)
{
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedClientAssertion'");
exitCode = -2;
}
catch(Light::glException) catch(Light::glException)
{ {
LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'"); LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'");
exitCode = -2; exitCode = -3;
} }
delete application; delete application;