Fix race conditions in timer execution for qtscript code. Patch reviewed by Safety0ff. Problem found by Vexed.
parent
be2c105b7a
commit
5941fa5dd9
|
@ -197,21 +197,21 @@ bool updateScripts()
|
|||
}
|
||||
// Check for timers, and run them if applicable.
|
||||
// TODO - load balancing
|
||||
QMutableListIterator<timerNode> iter(timers);
|
||||
QList<timerNode> runlist; // make a new list here, since we might trample all over the timer list during execution
|
||||
for (int i = 0; i < timers.size(); i++)
|
||||
{
|
||||
if (timers.at(i).frameTime <= gameTime)
|
||||
{
|
||||
timers[i].frameTime = timers.at(i).ms + gameTime; // update for next invokation
|
||||
runlist.append(timers.at(i));
|
||||
}
|
||||
}
|
||||
QListIterator<timerNode> iter(runlist);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
timerNode node = iter.next();
|
||||
if (node.frameTime <= gameTime)
|
||||
{
|
||||
node.frameTime = node.ms + gameTime; // update for next invokation
|
||||
const timerNode node = iter.next();
|
||||
callFunction(node.engine, node.function, QScriptValueList());
|
||||
}
|
||||
// Node could have been brutally removed from underneath us at this point
|
||||
if (timers.contains(node))
|
||||
{
|
||||
iter.setValue(node);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue