History

first cut at properly shutting down timers while shutting down scripts

ZappoMan committed 11 years ago

Commit 7e2d3551 parent 1efa7b22 files · +15 −0Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+14−0
@@ -535,6 +535,9 @@ void ScriptEngine::run() { · 534 unmodified lines
535535 }
536536 lastUpdate = now;
537537 }
538+
539+ stopAllTimers(); // make sure all our timers are stopped if the script is ending
540+
538541 emit scriptEnding();
539542
540543 // kill the avatar identity timer
@@ -564,6 +567,17 @@ void ScriptEngine::run() { · 23 unmodified lines
564567 emit doneRunning();
565568 }
566569
570+// NOTE: This is private because it must be called on the same thread that created the timers, which is why
571+// we want to only call it in our own run "shutdown" processing.
572+void ScriptEngine::stopAllTimers() {
573+ QMutableHashIterator<QTimer*, QScriptValue> i(_timerFunctionMap);
574+ while (i.hasNext()) {
575+ i.next();
576+ QTimer* timer = i.key();
577+ stopTimer(timer);
578+ }
579+}
580+
567581 void ScriptEngine::stop() {
568582 _isFinished = true;
569583 emit runningStateChanged();