Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 3 files). Show all
Unified · Split
| @@ -94,43 +94,33 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 93 unmodified lines | |||
| 94 | _isUserLoaded(false), | 94 | _isUserLoaded(false), |
| 95 | _arrayBufferClass(new ArrayBufferClass(this)) | 95 | _arrayBufferClass(new ArrayBufferClass(this)) |
| 96 | { | 96 | { |
| 97 | qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::ScriptEngine() " << getFilename() << "[" << this << "]"; | ||
| 98 | _allKnownScriptEngines.insert(this); | 97 | _allKnownScriptEngines.insert(this); |
| 99 | } | 98 | } |
| 100 | 99 | ||
| 101 | ScriptEngine::~ScriptEngine() { | 100 | ScriptEngine::~ScriptEngine() { |
| 102 | qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::~ScriptEngine() " << getFilename(); | ||
| 103 | _allKnownScriptEngines.remove(this); | 101 | _allKnownScriptEngines.remove(this); |
| 104 | } | 102 | } |
| 105 | 103 | ||
| 106 | QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines; | 104 | QSet<ScriptEngine*> ScriptEngine::_allKnownScriptEngines; |
| 107 | 105 | ||
| 108 | void ScriptEngine::gracefullyStopAllScripts(QObject* application) { | 106 | void ScriptEngine::stopAllScripts(QObject* application) { |
| 109 | qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::gracefullyStopAllScripts() ----------- START ------------------"; | ||
| 110 | |||
| 111 | |||
| 112 | QMutableSetIterator<ScriptEngine*> i(_allKnownScriptEngines); | 107 | QMutableSetIterator<ScriptEngine*> i(_allKnownScriptEngines); |
| 113 | while (i.hasNext()) { | 108 | while (i.hasNext()) { |
| 114 | ScriptEngine* scriptEngine = i.next(); | 109 | ScriptEngine* scriptEngine = i.next(); |
| 115 | qDebug() << (void*)scriptEngine; | ||
| 116 | |||
| 117 | if (scriptEngine->isRunning()) { | ||
| 118 | qDebug() << "scriptEngine still alive:" << scriptEngine->getFilename() << "[" << scriptEngine << "]"; | ||
| 119 | 110 | ||
| 111 | // NOTE: typically all script engines are running. But there's at least one known exception to this, the | ||
| 112 | // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using | ||
| 113 | // them. We don't need to stop scripts that aren't running. | ||
| 114 | if (scriptEngine->isRunning()) { | ||
| 120 | QEventLoop loop; | 115 | QEventLoop loop; |
| 121 | QObject::connect(scriptEngine, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit); | 116 | QObject::connect(scriptEngine, &ScriptEngine::doneRunning, &loop, &QEventLoop::quit); |
| 122 | 117 | ||
| 123 | scriptEngine->disconnect(application); | 118 | scriptEngine->disconnect(application); |
| 124 | scriptEngine->stop(); | 119 | scriptEngine->stop(); |
| 125 | 120 | ||
| 126 | qDebug() << "waiting on script to stop... "; | ||
| 127 | loop.exec(); | 121 | loop.exec(); |
| 128 | qDebug() << "done waiting... "; | ||
| 129 | } else { | ||
| 130 | qDebug() << "WARNING! scriptEngine [" << (void*)scriptEngine << "] still in _allKnownScriptEngines but not running??? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | ||
| 131 | } | 122 | } |
| 132 | } | 123 | } |
| 133 | qDebug() << "[" << QThread::currentThread() << "]" << "ScriptEngine::gracefullyStopAllScripts() ----------- DONE ------------------"; | ||
| 134 | } | 124 | } |
| 135 | 125 | ||
| 136 | QString ScriptEngine::getFilename() const { | 126 | QString ScriptEngine::getFilename() const { |
| @@ -411,14 +401,12 @@ void ScriptEngine::run() { · 274 unmodified lines | |||
| 411 | } | 401 | } |
| 412 | 402 | ||
| 413 | if (_isFinished) { | 403 | if (_isFinished) { |
| 414 | qDebug() << "ScriptEngine::run()... while() about to break " << getFilename(); | ||
| 415 | break; | 404 | break; |
| 416 | } | 405 | } |
| 417 | 406 | ||
| 418 | QCoreApplication::processEvents(); | 407 | QCoreApplication::processEvents(); |
| 419 | 408 | ||
| 420 | if (_isFinished) { | 409 | if (_isFinished) { |
| 421 | qDebug() << "ScriptEngine::run()... while() about to break " << getFilename(); | ||
| 422 | break; | 410 | break; |
| 423 | } | 411 | } |
| 424 | 412 | ||
| @@ -548,7 +536,6 @@ void ScriptEngine::run() { · 123 unmodified lines | |||
| 548 | } | 536 | } |
| 549 | lastUpdate = now; | 537 | lastUpdate = now; |
| 550 | } | 538 | } |
| 551 | qDebug() << "ScriptEngine::run()... about to emit scriptEnding() " << getFilename(); | ||
| 552 | emit scriptEnding(); | 539 | emit scriptEnding(); |
| 553 | 540 | ||
| 554 | // kill the avatar identity timer | 541 | // kill the avatar identity timer |
| @@ -566,25 +553,19 @@ void ScriptEngine::run() { · 11 unmodified lines | |||
| 566 | 553 | ||
| 567 | // If we were on a thread, then wait till it's done | 554 | // If we were on a thread, then wait till it's done |
| 568 | if (thread()) { | 555 | if (thread()) { |
| 569 | qDebug() << "ScriptEngine::run()... about to call thread()->quit() " << getFilename(); | ||
| 570 | thread()->quit(); | 556 | thread()->quit(); |
| 571 | } | 557 | } |
| 572 | 558 | ||
| 573 | qDebug() << "ScriptEngine::run()... about to emit finished() " << getFilename(); | ||
| 574 | emit finished(_fileNameString); | 559 | emit finished(_fileNameString); |
| 575 | 560 | ||
| 576 | _isRunning = false; | 561 | _isRunning = false; |
| 577 | 562 | ||
| 578 | qDebug() << "ScriptEngine::run()... about to emit runningStateChanged() " << getFilename(); | ||
| 579 | emit runningStateChanged(); | 563 | emit runningStateChanged(); |
| 580 | 564 | ||
| 581 | qDebug() << "ScriptEngine::run()... about to emit doneRunning() " << getFilename(); | ||
| 582 | emit doneRunning(); | 565 | emit doneRunning(); |
| 583 | qDebug() << "ScriptEngine::run()... DONE WITH run()... " << getFilename(); | ||
| 584 | } | 566 | } |
| 585 | 567 | ||
| 586 | void ScriptEngine::stop() { | 568 | void ScriptEngine::stop() { |
| 587 | qDebug() << "ScriptEngine::stop()... " << getFilename(); | ||
| 588 | _isFinished = true; | 569 | _isFinished = true; |
| 589 | emit runningStateChanged(); | 570 | emit runningStateChanged(); |
| 590 | } | 571 | } |
| @@ -666,12 +647,10 @@ void ScriptEngine::print(const QString& message) { · 75 unmodified lines | |||
| 666 | emit printedMessage(message); | 647 | emit printedMessage(message); |
| 667 | } | 648 | } |
| 668 | 649 | ||
| 669 | /** | 650 | // If a callback is specified, the included files will be loaded asynchronously and the callback will be called |
| 670 | * If a callback is specified, the included files will be loaded asynchronously and the callback will be called | 651 | // when all of the files have finished loading. |
| 671 | * when all of the files have finished loading. | 652 | // If no callback is specified, the included files will be loaded synchronously and will block execution until |
| 672 | * If no callback is specified, the included files will be loaded synchronously and will block execution until | 653 | // all of the files have finished loading. |
| 673 | * all of the files have finished loading. | ||
| 674 | */ | ||
| 675 | void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) { | 654 | void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) { |
| 676 | QList<QUrl> urls; | 655 | QList<QUrl> urls; |
| 677 | for (QString file : includeFiles) { | 656 | for (QString file : includeFiles) { |