From 146e5d4ff1912a1aab1620e4c8a3d63d83b8a9cc Mon Sep 17 00:00:00 2001 From: shweet Date: Sat, 3 Oct 2026 18:58:30 -0400 Subject: [PATCH] Fix close-popup ImGui stack imbalance, stale region hover, shared resize chord state, window properties leak Co-Authored-By: Claude Opus 5.5 --- src/imgui/documents.cpp | 22 +++++++--------------- src/imgui/window/spritesheet_editor.cpp | 2 +- src/imgui/window/timeline/timeline.cpp | 5 ++--- src/imgui/window/timeline/timeline.hpp | 2 ++ src/loader.cpp | 1 + 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/imgui/documents.cpp b/src/imgui/documents.cpp index 0b9c19d..3856c9b 100644 --- a/src/imgui/documents.cpp +++ b/src/imgui/documents.cpp @@ -300,18 +300,11 @@ namespace anm2ed::imgui shortcut(manager.chords[SHORTCUT_CONFIRM]); if (ImGui::Button(localize.get(BASIC_YES), widgetSize)) { - bool isSaved = true; - if (isDocumentDirty) isSaved = taskbar.save_manual(manager, settings, closeDocumentIndex); - - if (!isSaved) + // A failed save keeps the document (and its popup) open. + auto isSaved = !isDocumentDirty || taskbar.save_manual(manager, settings, closeDocumentIndex); + if (isSaved) { - ImGui::EndPopup(); - return; - } - - if (isSpritesheetDirty) - { - { + if (isSpritesheetDirty) for (auto& spritesheet : closeDocument.model.content.spritesheets) { auto id = spritesheet.id; @@ -332,11 +325,10 @@ namespace anm2ed::imgui } } } - } + auto index = closeDocumentIndex; + manager.command_push({.runManager = [index](Manager& manager) { manager.close(index); }}); + close(); } - auto index = closeDocumentIndex; - manager.command_push({.runManager = [index](Manager& manager) { manager.close(index); }}); - close(); } ImGui::SameLine(); diff --git a/src/imgui/window/spritesheet_editor.cpp b/src/imgui/window/spritesheet_editor.cpp index e7973a7..52f39f2 100644 --- a/src/imgui/window/spritesheet_editor.cpp +++ b/src/imgui/window/spritesheet_editor.cpp @@ -244,6 +244,7 @@ namespace anm2ed::imgui drawList->AddRectFilled(min, max, ImGui::GetColorU32(to_imvec4(vec4(backgroundColor, 1.0f)))); image_premultiplied_draw(this->texture, to_imvec2(size)); + hoveredRegionId = -1; if (ImGui::IsItemHovered()) { auto input = canvas_input_get(manager, isFocused); @@ -301,7 +302,6 @@ namespace anm2ed::imgui if (tool == tool::DRAW && input.isRightDown) useTool = tool::ERASE; if (tool == tool::ERASE && input.isRightDown) useTool = tool::DRAW; - hoveredRegionId = -1; if (useTool == tool::PAN && spritesheet && texture && texture->is_valid() && isMouseOverCanvas) for (auto& region : spritesheet->regions) { diff --git a/src/imgui/window/timeline/timeline.cpp b/src/imgui/window/timeline/timeline.cpp index 58a3396..7ebe977 100644 --- a/src/imgui/window/timeline/timeline.cpp +++ b/src/imgui/window/timeline/timeline.cpp @@ -201,7 +201,6 @@ namespace anm2ed::imgui }; constexpr FrameResize FRAME_RESIZES[] = {{SHORTCUT_SHORTEN_FRAME, EDIT_SHORTEN_FRAME, -1}, {SHORTCUT_EXTEND_FRAME, EDIT_EXTEND_FRAME, 1}}; - static bool isResizeChordHeld[std::size(FRAME_RESIZES)]{}; for (int i = 0; i < (int)std::size(FRAME_RESIZES); ++i) { auto resize = FRAME_RESIZES[i]; @@ -211,7 +210,7 @@ namespace anm2ed::imgui std::erase_if(selectedFrames, is_trigger_reference); if (!selectedFrames.empty()) { - if (!isResizeChordHeld[i]) edit_begin_push(resize.edit); + if (resizeChordTabIds[i] != document.tabId) edit_begin_push(resize.edit); command_push( [=, this](Manager&, Document& document) { @@ -222,7 +221,7 @@ namespace anm2ed::imgui document.change(); }); } - isResizeChordHeld[i] = isPressed; + resizeChordTabIds[i] = isPressed ? document.tabId : 0; } auto isPreviousFrame = shortcut(manager.chords[SHORTCUT_PREVIOUS_FRAME], shortcut::GLOBAL); diff --git a/src/imgui/window/timeline/timeline.hpp b/src/imgui/window/timeline/timeline.hpp index 09dab0a..bd4f877 100644 --- a/src/imgui/window/timeline/timeline.hpp +++ b/src/imgui/window/timeline/timeline.hpp @@ -146,6 +146,8 @@ namespace anm2ed::imgui float draggedFrameWidth{}; bool isDraggedFrameSnapshot{}; FrameMoveDrag frameMoveDrag{}; + // The tab a held shorten/extend chord is editing (0 when released), so a held chord starts one undo entry per document. + std::uint64_t resizeChordTabIds[2]{}; std::optional frameSelectionAnchor{}; int animationLengthEditIndex{-1}; std::vector rowDragReferences{}; diff --git a/src/loader.cpp b/src/loader.cpp index 2e6f60c..0860567 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -189,6 +189,7 @@ namespace anm2ed SDL_SetBooleanProperty(windowProperties, SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN, true); window = SDL_CreateWindowWithProperties(windowProperties); + SDL_DestroyProperties(windowProperties); if (!window) {