diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 25f02f298..f7f8b94a1 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -67,6 +67,9 @@ Other Changes: triggered by some widgets e.g. Checkbox(), Selectable() and many others, which cleared ActiveId at the same time as editing. (#9028) Note that IsItemDeactivatedAfterEdit() was not affected, only IsItemEdited). +- Demo: About Box: emit infos to convey when IM_ASSERT() macro is disabled, + - so users don't miss out on programming errors being reported. + - so it is included in config/build info submitted in new GitHub Issues. - Debug Tools: fixed DebugTextEncoding() potentially reading out of bounds if provided a trailing truncated UTF-8 sequence. - Backends: diff --git a/imconfig.h b/imconfig.h index 0e7cf6182..c6d9b8d5f 100644 --- a/imconfig.h +++ b/imconfig.h @@ -15,7 +15,8 @@ #pragma once //---- Define assertion handler. Defaults to calling assert(). -// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. +// - If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. +// - Compiling with NDEBUG will usually strip out assert() to nothing, which is NOT recommended because we use asserts to notify of programmer mistakes. //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts diff --git a/imgui.h b/imgui.h index c1e9a02eb..88c42ecb6 100644 --- a/imgui.h +++ b/imgui.h @@ -89,6 +89,7 @@ Index of this file: #endif // Helper Macros +// (note: compiling with NDEBUG will usually strip out assert() to nothing, which is NOT recommended because we use asserts to notify of programmer mistakes.) #ifndef IM_ASSERT #include #define IM_ASSERT(_EXPR) assert(_EXPR) // You can override the default assert handler by editing imconfig.h diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 3c3900b43..a43fd2487 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -8185,6 +8185,25 @@ void ImGui::ShowAboutWindow(bool* p_open) ImGui::Text("define: __EMSCRIPTEN__"); ImGui::Text("Emscripten: %d.%d.%d", __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__); #endif +#ifdef NDEBUG + ImGui::Text("define: NDEBUG"); +#endif + + // Heuristic to detect no-op IM_ASSERT() macros + // - This is designed so people opening bug reports would convey and notice that they have disabled asserts for Dear ImGui code. + // - 16 is > strlen("((void)(_EXPR))") which we suggested in our imconfig.h template as a possible way to disable. + int assert_runs_expression = 0; + IM_ASSERT(++assert_runs_expression); + int assert_expand_len = (int)strlen(IM_STRINGIFY(IM_ASSERT(true))); + bool assert_maybe_disabled = (!assert_runs_expression || assert_expand_len <= 16); + ImGui::Text("IM_ASSERT: runs expression: %s. expand size: %s%s", + assert_runs_expression ? "OK" : "KO", (assert_expand_len > 16) ? "OK" : "KO", assert_maybe_disabled ? " (MAYBE DISABLED?!)" : ""); + if (assert_maybe_disabled) + { + ImGui::SameLine(); + HelpMarker("IM_ASSERT() calls assert() by default. Compiling with NDEBUG will usually strip out assert() to nothing, which is NOT recommended because we use asserts to notify of programmer mistakes!"); + } + ImGui::Separator(); ImGui::Text("io.BackendPlatformName: %s", io.BackendPlatformName ? io.BackendPlatformName : "NULL"); ImGui::Text("io.BackendRendererName: %s", io.BackendRendererName ? io.BackendRendererName : "NULL");