Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.8.0
-
None
-
windows 7 x64, ubuntu 16.04 x64, GCC 5.3
Description
I was optimizing binding expressions by exposing some often duplicated values as reusable properties, when I noticed those entirely cosmetic changes have wrecked my entire project.
I had a hard time reproducing it, but finally succeeded. Here is the initial code, producing the expected result as seen in the first image:
// S_Settings.qml pragma Singleton import QtQuick 2.7 Item { property real bsize: 50 } // in main() qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/S_Settings.qml")), "Set", 1, 0, "SS"); // main.qml import QtQuick 2.7 import QtQuick.Window 2.2 import Set 1.0 Window { id: main visible: true width: 300 height: 200 Rectangle { anchors.centerIn: parent width: SS.bsize * 4 height: SS.bsize * 2 radius: SS.bsize * .5 color: "red" border.color: "black" border.width: SS.bsize * .1 }
Now, let's make some changes, and introduce two more derived properties in the singleton and use them in main.cpp
// S_Settings.qml pragma Singleton import QtQuick 2.7 Item { property real bsize: 50 property real tenth: bsize * .1 property real half: bsize * .5 } // main.qml import QtQuick 2.7 import QtQuick.Window 2.2 import Set 1.0 Window { id: main visible: true width: 300 height: 200 Rectangle { anchors.centerIn: parent width: SS.bsize * 4 height: SS.bsize * 2 radius: SS.half color: "red" border.color: "black" border.width: SS.tenth } }
At a first glance, everything is OK, in this particular and trivial example the changes still produce the same output as the original code.
But now let's simply change the order of the properties:
// S_Settings.qml pragma Singleton import QtQuick 2.7 Item { property real bsize: 50 property real half: bsize * .5 property real tenth: bsize * .1 }
The output is already corrupted, as evident from the second image. The rectangle is incorrectly rounded and the border is abnormally thick.
Let's push that property another line up:
// S_Settings.qml pragma Singleton import QtQuick 2.7 Item { property real half: bsize * .5 property real bsize: 50 property real tenth: bsize * .1 }
Another cosmetic change that outta have no effect whatsoever and now the output is even bugger. Now all that we have is a small black rectangle.
Note that in this small example it only messes up property values. In my actual production code the effect was devastating. Aside from messed up property values, property types went crazy as well, the engine saw colors as ints, strings as bools, ints as nulls and so on. The effect ranged from entirely messed up UI with objects all in the wrong places, wrong sizes and wrong colors, through absolutely nothing showing up, and all the way to crashes, depending on simple changes of the order of properties in the singleton. Also, unlike in this example, in my production code I immediately got some visual artifacts, but simple reordering of properties made it even worse.
UPDATE:
It seems to be qml cache related, as purging the cache for that application solves the issue. Unfortunately, it is not as simple to do that on a user system. I can totally see this messing up user applications on updates, unless every QML file has changed in order to force recompilation, the end user application will succumb to this bug.