Repository navigation
keep default theme objects alive for the process lifetime - #37
Merged
Merged
Conversation
The default color/size/page objects live in a Q_GLOBAL_STATIC and are handed out to QML by MProp. When static destruction runs while a QQmlEngine is still alive, they are destroyed first and every binding on MD.MProp.color / MD.Token.color re-evaluates against a destroyed QObject, printing "TypeError: Cannot read property '...' of null". Create the defaults once and keep them for the whole process lifetime. Nothing changes while the engine is up, and an explicitly assigned MdColorMgr is still owned by the Theme it is set on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default
MdColorMgr/ThemeSize/PageContextthatMProphands out live in aQ_GLOBAL_STATICinsrc/style/theme.cpp. When a process reaches static destruction while aQQmlEngineis still alive, those objects go away first, and every binding readingMD.MProp.colororMD.Token.colorre-evaluates against a destroyed QObject and printsTypeError: Cannot read property '...' of null.Token.qml:36(isDarkTheme) is in that listtoo, so the singleton trips over it as well.
It is not an exotic ordering: any engine that outlives
main()hits it — a heap engine that isnever deleted,
exit()from a watchdog or crash path, or an engine whose lifetime belongs to ascripting host. In an app embedding the library, one killed run printed 191 of these lines.
Reproducer (v0.3.0, Qt 6.11.2, Xvfb + software GL): an
MD.Pageholding 20 rows ofMD.Divider+MD.Badge+MD.ScrollBar+MD.Textin a plainQQuickView, hosted byBefore the patch: 101
TypeErrorlines. After: 0. Same scene, otherwise the same binary.The change creates the defaults once and keeps them for the process lifetime. Nothing moves while
the engine is up: colors read through an attached provider and through the default are identical
before and after (16 roles plus
mode,isDarkTheme,themeMode, inheritedelevation/textColor, andresetfallback); the only difference in the dump is the printed address, nowheap instead of static storage.
ctestis 42/42 both ways, andexamplestarts clean.I left
Token.qmland the raw pointers inAttachPropuntouched on purpose — guarding the QMLwould only hide the symptom, and turning the attached property into a
QPointeris a largerdecision than this defect calls for. Glad to go that way instead if you prefer it.