Skip to content

Commit

Permalink
Merge pull request #521 from overte-org/fix/script_shutdown
Browse files Browse the repository at this point in the history
Fixed interface scripts failing to shutdown
  • Loading branch information
ksuprynowicz authored Jul 22, 2023
2 parents 17ceda8 + f3732aa commit 012098b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
18 changes: 12 additions & 6 deletions interface/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7550,12 +7550,18 @@ void Application::registerScriptEngineWithApplicationServices(ScriptManagerPoint
}
auto scriptingInterface = DependencyManager::get<controller::ScriptingInterface>();
scriptEngine->registerGlobalObject("Controller", scriptingInterface.data());
scriptManager->connect(scriptManager.get(), &ScriptManager::scriptEnding, [scriptManager]() {
// Request removal of controller routes with callbacks to a given script engine
auto userInputMapper = DependencyManager::get<UserInputMapper>();
userInputMapper->scheduleScriptEndpointCleanup(scriptManager->engine().get());
// V8TODO: Maybe we should wait until removal is finished if there are still crashes
});

{
auto connection = std::make_shared<QMetaObject::Connection>();
*connection = scriptManager->connect(scriptManager.get(), &ScriptManager::scriptEnding, [scriptManager, connection]() {
// Request removal of controller routes with callbacks to a given script engine
auto userInputMapper = DependencyManager::get<UserInputMapper>();
userInputMapper->scheduleScriptEndpointCleanup(scriptManager->engine().get());
// V8TODO: Maybe we should wait until endpoint cleanup is finished before deleting the script engine if there are still crashes
QObject::disconnect(*connection);
});
}

UserInputMapper::registerControllerTypes(scriptEngine.get());

auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
connect(_manager, &ScriptManager::errorLoadingScript, this, &ScriptManagerScriptingInterface::errorLoadingScript);
connect(_manager, &ScriptManager::update, this, &ScriptManagerScriptingInterface::update);
connect(_manager, &ScriptManager::scriptEnding, this, &ScriptManagerScriptingInterface::scriptEnding);
connect(_manager, &ScriptManager::finished, this, &ScriptManagerScriptingInterface::finished);
connect(_manager, &ScriptManager::printedMessage, this, &ScriptManagerScriptingInterface::printedMessage);
connect(_manager, &ScriptManager::errorMessage, this, &ScriptManagerScriptingInterface::errorMessage);
connect(_manager, &ScriptManager::warningMessage, this, &ScriptManagerScriptingInterface::warningMessage);
Expand Down
9 changes: 0 additions & 9 deletions libraries/script-engine/src/ScriptManagerScriptingInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,6 @@ class ScriptManagerScriptingInterface : public QObject {
*/
void scriptEnding();

/*@jsdoc
* @function Script.finished
* @param {string} filename - File name.
* @param {object} engine - Engine.
* @returns {Signal}
* @deprecated This signal is deprecated and will be removed.
*/
void finished(const QString& fileNameString, ScriptManagerPointer);

/*@jsdoc
* Triggered when the script prints a message to the program log via {@link print}, {@link Script.print},
* {@link console.log}, {@link console.debug}, {@link console.group}, {@link console.groupEnd}, {@link console.time}, or
Expand Down

0 comments on commit 012098b

Please sign in to comment.