Fixed crash with asset scripting crash

This commit is contained in:
ksuprynowicz 2023-03-23 00:16:38 +01:00
parent ca577f2802
commit 6c1fd88fb1
3 changed files with 11 additions and 7 deletions

View file

@ -43,7 +43,7 @@ STATIC_SCRIPT_TYPES_INITIALIZER((+[](ScriptManager* manager){
})); }));
AssetScriptingInterface::AssetScriptingInterface(QObject* parent) : BaseAssetScriptingInterface(parent) { AssetScriptingInterface::AssetScriptingInterface(ScriptManager* parent) : BaseAssetScriptingInterface(parent), _scriptManager(parent) {
qCDebug(scriptengine) << "AssetScriptingInterface::AssetScriptingInterface" << parent; qCDebug(scriptengine) << "AssetScriptingInterface::AssetScriptingInterface" << parent;
} }
@ -246,7 +246,7 @@ void AssetScriptingInterface::jsCallback(const ScriptValue& handler,
Q_ASSERT(thread() == QThread::currentThread()); Q_ASSERT(thread() == QThread::currentThread());
Q_ASSERT(engine); Q_ASSERT(engine);
//V8TODO: which kind of script context guard needs to be used here? //V8TODO: which kind of script context guard needs to be used here?
ScriptContextGuard scriptContextGuard(engine()->currentContext()); ScriptContextGuard scriptContextGuard(_scriptManager->engine()->currentContext());
auto errorValue = !error.toBool() ? engine()->nullValue() : error; auto errorValue = !error.toBool() ? engine()->nullValue() : error;
JS_VERIFY(handler.isObject() && handler.property("callback").isFunction(), JS_VERIFY(handler.isObject() && handler.property("callback").isFunction(),
QString("jsCallback -- .callback is not a function (%1)") QString("jsCallback -- .callback is not a function (%1)")

View file

@ -46,12 +46,15 @@
* @hifi-server-entity * @hifi-server-entity
* @hifi-assignment-client * @hifi-assignment-client
*/ */
class ScriptManager;
/// Provides the <code><a href="https://apidocs.overte.org/Assets.html">Assets</a></code> scripting API /// Provides the <code><a href="https://apidocs.overte.org/Assets.html">Assets</a></code> scripting API
class AssetScriptingInterface : public BaseAssetScriptingInterface, Scriptable { class AssetScriptingInterface : public BaseAssetScriptingInterface, Scriptable {
Q_OBJECT Q_OBJECT
public: public:
using Parent = BaseAssetScriptingInterface; using Parent = BaseAssetScriptingInterface;
AssetScriptingInterface(QObject* parent = nullptr); AssetScriptingInterface(ScriptManager* parent);
/*@jsdoc /*@jsdoc
* Called when an {@link Assets.uploadData} call is complete. * Called when an {@link Assets.uploadData} call is complete.
@ -547,6 +550,7 @@ protected:
void jsCallback(const ScriptValue& handler, const ScriptValue& error, const QVariantMap& result); void jsCallback(const ScriptValue& handler, const ScriptValue& error, const QVariantMap& result);
void jsCallback(const ScriptValue& handler, const ScriptValue& error, const ScriptValue& result); void jsCallback(const ScriptValue& handler, const ScriptValue& error, const ScriptValue& result);
bool jsVerify(bool condition, const QString& error); bool jsVerify(bool condition, const QString& error);
ScriptManager *_scriptManager;
}; };
#endif // hifi_AssetScriptingInterface_h #endif // hifi_AssetScriptingInterface_h

View file

@ -394,6 +394,7 @@ void ScriptManager::runInThread() {
workerThread->setObjectName(name); workerThread->setObjectName(name);
_engine->setThread(workerThread); _engine->setThread(workerThread);
moveToThread(workerThread); moveToThread(workerThread);
_assetScriptingInterface->moveToThread(workerThread);
// NOTE: If you connect any essential signals for proper shutdown or cleanup of // NOTE: If you connect any essential signals for proper shutdown or cleanup of
// the script engine, make sure to add code to "reconnect" them to the // the script engine, make sure to add code to "reconnect" them to the
@ -884,10 +885,9 @@ void ScriptManager::run() {
hifi::scripting::setLocalAccessSafeThread(true); hifi::scripting::setLocalAccessSafeThread(true);
} }
if (QThread::currentThread() != _assetScriptingInterface->thread()) {
//_engine->enterIsolateOnThisThread(); _assetScriptingInterface->moveToThread(QThread::currentThread());
}
_engine->compileTest();
auto filenameParts = _fileNameString.split("/"); auto filenameParts = _fileNameString.split("/");
auto name = filenameParts.size() > 0 ? filenameParts[filenameParts.size() - 1] : "unknown"; auto name = filenameParts.size() > 0 ? filenameParts[filenameParts.size() - 1] : "unknown";