mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-12-02 18:45:41 +00:00
8c7a192128
Should've did this in the beginning.
52 lines
3.4 KiB
C
52 lines
3.4 KiB
C
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
#pragma once
|
|
|
|
void Y_OnAssertFailed(const char* szMessage, const char* szFunction, const char* szFile, unsigned uLine);
|
|
void Y_OnPanicReached(const char* szMessage, const char* szFunction, const char* szFile, unsigned uLine);
|
|
|
|
#define Assert(expr) \
|
|
if (!(expr)) \
|
|
{ \
|
|
Y_OnAssertFailed("Assertion failed: '" #expr "'", __FUNCTION__, __FILE__, __LINE__); \
|
|
}
|
|
#define AssertMsg(expr, msg) \
|
|
if (!(expr)) \
|
|
{ \
|
|
Y_OnAssertFailed("Assertion failed: '" msg "'", __FUNCTION__, __FILE__, __LINE__); \
|
|
}
|
|
|
|
#ifdef _DEBUG
|
|
#define DebugAssert(expr) \
|
|
if (!(expr)) \
|
|
{ \
|
|
Y_OnAssertFailed("Debug assertion failed: '" #expr "'", __FUNCTION__, __FILE__, __LINE__); \
|
|
}
|
|
#define DebugAssertMsg(expr, msg) \
|
|
if (!(expr)) \
|
|
{ \
|
|
Y_OnAssertFailed("Debug assertion failed: '" msg "'", __FUNCTION__, __FILE__, __LINE__); \
|
|
}
|
|
#define DebugUnreachableCode() Y_OnPanicReached("Unreachable code reached", __FUNCTION__, __FILE__, __LINE__)
|
|
#else
|
|
#define DebugAssert(expr)
|
|
#define DebugAssertMsg(expr, msg)
|
|
#define DebugUnreachableCode()
|
|
#endif
|
|
|
|
// Panics the application, displaying an error message.
|
|
#define Panic(Message) Y_OnPanicReached("Panic triggered: '" Message "'", __FUNCTION__, __FILE__, __LINE__)
|
|
|
|
// Kills the application, indicating a pure function call that should not have happened.
|
|
#define PureCall() Y_OnPanicReached("PureCall encountered", __FUNCTION__, __FILE__, __LINE__)
|
|
|
|
// Kills the application, indicating that code that was never supposed to be reached has been executed.
|
|
#define UnreachableCode() Y_OnPanicReached("Unreachable code reached", __FUNCTION__, __FILE__, __LINE__)
|
|
|
|
// Helper for switch cases.
|
|
#define DefaultCaseIsUnreachable() \
|
|
default: \
|
|
UnreachableCode(); \
|
|
break;
|