Skip to content

Fix Android freeze when discarding changes on close#2

Merged
iwahage merged 1 commit intomasterfrom
fix/android-close-file-freeze
Apr 7, 2026
Merged

Fix Android freeze when discarding changes on close#2
iwahage merged 1 commit intomasterfrom
fix/android-close-file-freeze

Conversation

@iwahage
Copy link
Copy Markdown
Owner

@iwahage iwahage commented Apr 7, 2026

Summary

  • Fix freeze/crash when tapping "Discard changes" on Android close-file dialog
  • In mobile mode, setCentralWidget(nullptr) is a no-op (QStackedWidget ignores null), leaving the old container widget with a dangling pointer to the deleted map_widget. Resize events from leaving fullscreen then access freed memory.
  • Replace setCentralWidget(nullptr) + delete map_widget with setCentralWidget(new QWidget()) + map_widget = nullptr so the old container is properly evicted and scheduled for deletion
  • Change cleanup loop in MainWindow::setCentralWidget() from if to while for robustness

Test plan

  • Open a map on Android, tap back/close, select "Discard changes" — app should return to home screen without freezing
  • Open a map from home screen — should work without crash
  • Edit a map, close with "Save" — should save and return to home screen normally

🤖 Generated with Claude Code

In mobile mode, map_widget lives inside a container_widget (QVBoxLayout
with bottom_action_bar).  MapEditorController::detach() was calling
setCentralWidget(nullptr), which does nothing because QStackedWidget
ignores null, and then deleting map_widget individually, leaving a
dangling pointer in the container's layout.  When the app later left
fullscreen mode, resize events reached the stale container and accessed
freed memory, causing a freeze.

Fix: pass a new empty QWidget to setCentralWidget() so the old container
is properly removed from the QStackedWidget and scheduled for deletion.
Also change the cleanup loop in MainWindow::setCentralWidget() from
`if` to `while` to handle edge cases with multiple stacked widgets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iwahage iwahage merged commit 4728bff into master Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant