Possible crash in `AbstractWorldTool::undoStack` when switching maps
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 12.9k
- Forks
- 2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 8
Description
The following crash was reported through Sentry:
Thread 28281 Crashed:
0 libtilededitor.so 0x7f1b4e333c47 Tiled::AbstractWorldTool::undoStack (abstractworldtool.cpp:397)
1 libtilededitor.so 0x7f1b4e4a5691 Tiled::MapEditor::updateActiveUndoStack (mapeditor.cpp:684)
2 libtilededitor.so 0x7f1b4e4acc34 Tiled::MapEditor::setCurrentDocument (mapeditor.cpp:379)
3 libtilededitor.so 0x7f1b4e3ed36c Tiled::DocumentManager::currentIndexChanged (documentmanager.cpp:982)
4 libQt6Core.so.6 0x7f1b4c797771 [inlined] QtPrivate::QSlotObjectBase::call (qobjectdefs_impl.h:363)
5 libQt6Core.so.6 0x7f1b4c797771 doActivate<T> (qobject.cpp:3979)
6 libQt6Widgets.so.6 0x7f1b4dd6c5cd QTabBar::currentChanged (moc_qtabbar.cpp:425)
7 libQt6Widgets.so.6 0x7f1b4dd73ad3 QTabBar::removeTab (qtabbar.cpp:1063)
8 libtilededitor.so 0x7f1b4e3f4228 Tiled::DocumentManager::closeDocumentAt (documentmanager.cpp:865)
9 libQt6Core.so.6 0x7f1b4c797771 [inlined] QtPrivate::QSlotObjectBase::call (qobjectdefs_impl.h:363)
10 libQt6Core.so.6 0x7f1b4c797771 doActivate<T> (qobject.cpp:3979)
11 libtilededitor.so 0x7f1b4e3ecaa4 Tiled::DocumentManager::documentCloseRequested (moc_documentmanager.cpp:635)
12 libQt6Core.so.6 0x7f1b4c797771 [inlined] QtPrivate::QSlotObjectBase::call (qobjectdefs_impl.h:363)
13 libQt6Core.so.6 0x7f1b4c797771 doActivate<T> (qobject.cpp:3979)
14 libQt6Widgets.so.6 0x7f1b4dd6c610 QTabBar::tabCloseRequested (moc_qtabbar.cpp:432)
The crash occurs on the last line of this function:
It is clear that even though WorldManager::worldForMap returned a World*, the DocumentManager::ensureWorldDocument did not have a matching WorldDocument instance. Matching instances are supposed to always be available based on these connections:
I'm not sure yet what could cause this issue, but I think this approach is a little too fragile in any case.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing AbstractWorldTool::undoStack in src/tiled/abstractworldtool.cpp around lines 392-398, then follow MapEditor::updateActiveUndoStack, setCurrentDocument, and DocumentManager::closeDocumentAt from the stack trace. Compare this flow with the WorldDocument connections in src/tiled/documentmanager.cpp around lines 278-282. Done means reproducing the map-switch or document-close sequence and preventing the crash while preserving the expected undo-stack behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100