mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:42:58 +02:00
Wait on old entity script engines in threadpool
This commit is contained in:
parent
e1c130d02f
commit
806d06b552
2 changed files with 22 additions and 13 deletions
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QScriptSyntaxCheckResult>
|
#include <QScriptSyntaxCheckResult>
|
||||||
|
#include <QThreadPool>
|
||||||
|
|
||||||
#include <ColorUtils.h>
|
#include <ColorUtils.h>
|
||||||
#include <AbstractScriptingServicesInterface.h>
|
#include <AbstractScriptingServicesInterface.h>
|
||||||
|
@ -83,14 +84,22 @@ void EntityTreeRenderer::resetEntitiesScriptEngine() {
|
||||||
|
|
||||||
auto newEngine = new ScriptEngine(NO_SCRIPT, QString("Entities %1").arg(++_entitiesScriptEngineCount));
|
auto newEngine = new ScriptEngine(NO_SCRIPT, QString("Entities %1").arg(++_entitiesScriptEngineCount));
|
||||||
_entitiesScriptEngine = QSharedPointer<ScriptEngine>(newEngine, [](ScriptEngine* engine){
|
_entitiesScriptEngine = QSharedPointer<ScriptEngine>(newEngine, [](ScriptEngine* engine){
|
||||||
// Gracefully exit
|
class WaitRunnable : public QRunnable {
|
||||||
|
public:
|
||||||
|
WaitRunnable(ScriptEngine* engine) : _engine(engine) {}
|
||||||
|
virtual void run() override {
|
||||||
|
_engine->wait();
|
||||||
|
_engine->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScriptEngine* _engine;
|
||||||
|
};
|
||||||
|
|
||||||
engine->unloadAllEntityScripts();
|
engine->unloadAllEntityScripts();
|
||||||
engine->stop();
|
engine->stop();
|
||||||
|
// Wait for the scripting thread from the thread pool to avoid hanging the main thread
|
||||||
// Disgracefully exit, if necessary
|
QThreadPool::globalInstance()->start(new WaitRunnable(engine));
|
||||||
QTimer::singleShot(ScriptEngine::MAX_SCRIPT_EVALUATION_TIME, engine, &ScriptEngine::abort);
|
|
||||||
|
|
||||||
engine->deleteLater();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine.data());
|
_scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine.data());
|
||||||
|
|
|
@ -83,6 +83,13 @@ public:
|
||||||
/// run the script in the callers thread, exit when stop() is called.
|
/// run the script in the callers thread, exit when stop() is called.
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// NOTE - this is intended to be a public interface for Agent scripts, and local scripts, but not for EntityScripts
|
||||||
|
Q_INVOKABLE void stop();
|
||||||
|
|
||||||
|
// Stop any evaluating scripts and wait for the scripting thread to finish.
|
||||||
|
void wait();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can
|
// NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can
|
||||||
// properly ensure they are only called on the correct thread
|
// properly ensure they are only called on the correct thread
|
||||||
|
@ -138,10 +145,6 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void requestGarbageCollection() { collectGarbage(); }
|
Q_INVOKABLE void requestGarbageCollection() { collectGarbage(); }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// NOTE - this is intended to be a public interface for Agent scripts, and local scripts, but not for EntityScripts
|
|
||||||
Q_INVOKABLE void stop();
|
|
||||||
|
|
||||||
bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget
|
bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget
|
||||||
bool isRunning() const { return _isRunning; } // used by ScriptWidget
|
bool isRunning() const { return _isRunning; } // used by ScriptWidget
|
||||||
|
|
||||||
|
@ -201,9 +204,6 @@ protected:
|
||||||
void init();
|
void init();
|
||||||
QString getFilename() const;
|
QString getFilename() const;
|
||||||
|
|
||||||
// Stop any evaluating scripts and wait for the scripting thread to finish.
|
|
||||||
void wait();
|
|
||||||
|
|
||||||
bool evaluatePending() const { return _evaluatesPending > 0; }
|
bool evaluatePending() const { return _evaluatesPending > 0; }
|
||||||
void timerFired();
|
void timerFired();
|
||||||
void stopAllTimers();
|
void stopAllTimers();
|
||||||
|
|
Loading…
Reference in a new issue