Windows: Use a different window title for debug asserts

Fix bug in FastVec.h
This commit is contained in:
Henrik Rydgård
2026-02-05 12:04:06 +01:00
parent 991d7bdfab
commit d8c40eefe8
3 changed files with 10 additions and 11 deletions
-1
View File
@@ -158,7 +158,6 @@ private:
T *oldData = data_;
data_ = (T *)malloc(sizeof(T) * newCapacity);
_assert_msg_(data_ != nullptr, "%d", (int)newCapacity);
_dbg_assert_(oldData != nullptr);
if (capacity_ != 0 && oldData != nullptr) {
memcpy(data_, oldData, sizeof(T) * size_);
free(oldData);
+2 -2
View File
@@ -92,7 +92,7 @@ void BreakIntoPSPDebugger(const char *reason) {
}
}
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...) {
bool HandleAssert(bool isDebugAssert, const char *function, const char *file, int line, const char *expression, const char* format, ...) {
// Read message and write it to the log
char text[LOG_BUF_SIZE];
va_list args;
@@ -135,7 +135,7 @@ bool HandleAssert(const char *function, const char *file, int line, const char *
const char *threadName = GetCurrentThreadName();
OutputDebugStringA(formatted);
printf("%s\n", formatted);
static const std::string caption = "Critical";
static const std::string caption = isDebugAssert ? "Debug Assert" : "Critical Assert";
std::wstring wcaption = ConvertUTF8ToWString(caption + " " + (threadName ? threadName : "(unknown thread)"));
switch (MessageBox(g_dialogParent, ConvertUTF8ToWString(text).c_str(), wcaption.c_str(), msgBoxStyle)) {
case IDYES:
+8 -8
View File
@@ -133,9 +133,9 @@ void GenericLog(Log type, LogLevel level, const char *file, int line, const char
#define VERBOSE_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LVERBOSE, __VA_ARGS__) } while (false)
// Currently only actually shows a dialog box on Windows.
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...)
bool HandleAssert(bool isDebugAssert, const char *function, const char *file, int line, const char *expression, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 5, 6)))
__attribute__((format(printf, 6, 7)))
#endif
;
@@ -172,22 +172,22 @@ void SetAssertDialogParent(void *handle); // HWND on windows. Ignored on other
#define _dbg_assert_(_a_) \
if (!(_a_)) {\
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
if (!HandleAssert(true, __FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
}
#define _dbg_assert_or_log_(_a_) \
if (!(_a_)) {\
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
if (!HandleAssert(true, __FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
}
#define _dbg_assert_msg_(_a_, ...) \
if (!(_a_)) { \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
if (!HandleAssert(true, __FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
}
#define _dbg_assert_msg_or_log_(_a_, log, ...) \
if (!(_a_)) { \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
if (!HandleAssert(true, __FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
}
#else // not debug
@@ -210,12 +210,12 @@ void SetAssertDialogParent(void *handle); // HWND on windows. Ignored on other
#define _assert_(_a_) \
if (!(_a_)) {\
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
if (!HandleAssert(false, __FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \
}
#define _assert_msg_(_a_, ...) \
if (!(_a_)) { \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
if (!HandleAssert(false, __FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
}
// Just INFO_LOGs on nonWindows. On Windows it outputs to the VS output console.