Fix heap corruption coming out of running scripts dialog

This commit is contained in:
Brad Davis 2017-06-22 19:15:58 -07:00
parent 4439de240a
commit d50c448151

View file

@ -40,9 +40,25 @@ ScrollingWindow {
property alias y: root.y property alias y: root.y
} }
Timer {
id: refreshTimer
interval: 100
repeat: false
running: false
onTriggered: updateRunningScripts();
}
Component {
id: listModelBuilder
ListModel { }
}
Connections { Connections {
target: ScriptDiscoveryService target: ScriptDiscoveryService
onScriptCountChanged: updateRunningScripts(); onScriptCountChanged: {
runningScriptsModel = listModelBuilder.createObject(root);
refreshTimer.restart();
}
} }
Component.onCompleted: { Component.onCompleted: {
@ -65,10 +81,16 @@ ScrollingWindow {
b = simplify(b.path); b = simplify(b.path);
return a < b ? -1 : a > b ? 1 : 0; return a < b ? -1 : a > b ? 1 : 0;
}); });
runningScriptsModel.clear() // Calling `runningScriptsModel.clear()` here instead of creating a new object
// triggers some kind of weird heap corruption deep inside Qt. So instead of
// modifying the model in place, possibly triggering behaviors in the table
// instead we create a new `ListModel`, populate it and update the
// existing model atomically.
var newRunningScriptsModel = listModelBuilder.createObject(root);
for (var i = 0; i < runningScripts.length; ++i) { for (var i = 0; i < runningScripts.length; ++i) {
runningScriptsModel.append(runningScripts[i]); newRunningScriptsModel.append(runningScripts[i]);
} }
runningScriptsModel = newRunningScriptsModel;
} }
function loadScript(script) { function loadScript(script) {