diff --git a/src/app/core/window.cc b/src/app/core/window.cc index aaa139fb..b8fc941b 100644 --- a/src/app/core/window.cc +++ b/src/app/core/window.cc @@ -1,15 +1,53 @@ #include "app/core/window.h" +#include + #include "absl/status/status.h" #include "absl/strings/str_format.h" #include "app/core/platform/font_loader.h" #include "util/sdl_deleter.h" +#include "util/log.h" #include "app/gfx/arena.h" #include "app/gui/style.h" #include "imgui/backends/imgui_impl_sdl2.h" #include "imgui/backends/imgui_impl_sdlrenderer2.h" #include "imgui/imgui.h" +namespace { +// Custom ImGui assertion handler to prevent crashes +void ImGuiAssertionHandler(const char* expr, const char* file, int line, + const char* msg) { + // Log the assertion instead of crashing + LOG_ERROR("ImGui", "Assertion failed: %s\nFile: %s:%d\nMessage: %s", + expr, file, line, msg ? msg : ""); + + // Try to recover by resetting ImGui state + static int error_count = 0; + error_count++; + + if (error_count > 5) { + LOG_ERROR("ImGui", "Too many assertions, resetting workspace settings..."); + + // Backup and reset imgui.ini + try { + if (std::filesystem::exists("imgui.ini")) { + std::filesystem::copy("imgui.ini", "imgui.ini.backup", + std::filesystem::copy_options::overwrite_existing); + std::filesystem::remove("imgui.ini"); + LOG_INFO("ImGui", "Workspace settings reset. Backup saved to imgui.ini.backup"); + } + } catch (const std::exception& e) { + LOG_ERROR("ImGui", "Failed to reset workspace: %s", e.what()); + } + + error_count = 0; // Reset counter + } + + // Don't abort - let the program continue + // The assertion is logged and workspace can be reset if needed +} +} // namespace + namespace yaze { namespace core { @@ -41,6 +79,14 @@ absl::Status CreateWindow(Window& window, int flags) { ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + + // Set custom assertion handler to prevent crashes +#ifdef IMGUI_DISABLE_DEFAULT_ASSERT_HANDLER + ImGui::SetAssertHandler(ImGuiAssertionHandler); +#else + // For release builds, assertions are already disabled + LOG_INFO("Window", "ImGui assertions are disabled in this build"); +#endif // Initialize ImGuiTestEngine after ImGui context is created #if defined(YAZE_ENABLE_IMGUI_TEST_ENGINE) && YAZE_ENABLE_IMGUI_TEST_ENGINE diff --git a/src/app/editor/editor_library.cmake b/src/app/editor/editor_library.cmake index 95c3884f..3e084148 100644 --- a/src/app/editor/editor_library.cmake +++ b/src/app/editor/editor_library.cmake @@ -17,6 +17,7 @@ set( app/editor/dungeon/dungeon_renderer.cc app/editor/dungeon/dungeon_room_loader.cc app/editor/dungeon/dungeon_usage_tracker.cc + app/editor/dungeon/object_editor_card.cc app/editor/overworld/overworld_editor.cc app/editor/overworld/scratch_space.cc app/editor/sprite/sprite_editor.cc diff --git a/src/app/editor/ui/welcome_screen.cc b/src/app/editor/ui/welcome_screen.cc index c8fba878..a973d810 100644 --- a/src/app/editor/ui/welcome_screen.cc +++ b/src/app/editor/ui/welcome_screen.cc @@ -634,11 +634,15 @@ void WelcomeScreen::DrawProjectCard(const RecentProject& project, int index) { ImGui::Text(ICON_MD_VIDEOGAME_ASSET); ImGui::PopStyleColor(); - // Project name (compact) + // Project name (compact, shorten if too long) ImGui::SetCursorScreenPos(ImVec2(content_pos.x + 32, content_pos.y + 8)); ImGui::PushTextWrapPos(cursor_pos.x + card_size.x - 8); ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]); // Default font - ImGui::TextColored(kTriforceGold, "%s", project.name.c_str()); + std::string short_name = project.name; + if (short_name.length() > 22) { + short_name = short_name.substr(0, 19) + "..."; + } + ImGui::TextColored(kTriforceGold, "%s", short_name.c_str()); ImGui::PopFont(); ImGui::PopTextWrapPos();