Review Request 122105: Fix KgDifficulty saving on app close
David Faure
faure at kde.org
Fri Jan 23 22:39:17 UTC 2015
On Monday 19 January 2015 21:43:41 Albert Astals Cid wrote:
> See
> http://quickgit.kde.org/?p=libkdegames.git&a=blob&h=b94cce00ef338cdfd3224e35
> 42074b699ead0b29&hb=63855d630c928e46554885f6d022d0091dbe252b&f=kgdifficulty.
> cpp
>
> It has a
>
> K_GLOBAL_STATIC(KgDifficulty, g_difficulty)
>
> and a
>
> KConfigGroup cg(KGlobal::config(), "KgDifficulty");
> cg.writeEntry("Level", currentLevel()->key());
>
> in KgDifficulty destructor.
>
> And it did work :D
OK. So I investigated it further and .... well, it worked through luck, mostly
:)
As you probably heard before, the order of destruction of global statics is
not something one should rely upon. But that's exactly what happened here.
If the global static is created before KGlobal then it's destroyed afterwards,
and asserts. If it's created after KGlobal then no problem.
Since KGlobal was created in many automatic ways in kdelibs4, all apps ended
up in the second case, which is why it worked.
=> working kdelibs4 testcase
http://www.davidfaure.fr/2015/ksharedconfig_in_global_object.cpp
In KF5 it gives the QCoreApplication::arguments issue, but works otherwise.
Therefore one possible fix is ... calling KSharedConfig::openConfig() in
main(), or at least before calling the code that ends up creating your
singleton. Tricky (not really intuitive).
Here's the fix for the QCoreApplication::arguments issue:
https://git.reviewboard.kde.org/r/122232/
--
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5
More information about the Kde-frameworks-devel
mailing list