Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 3 files). Show all
Unified · Split
| @@ -427,7 +427,10 @@ void ScriptManager::runInThread() { · 426 unmodified lines | ||
| 427 | 427 | |
| 428 | 428 | void ScriptManager::executeOnScriptThread(std::function<void()> function, const Qt::ConnectionType& type ) { |
| 429 | 429 | if (QThread::currentThread() != thread()) { |
| 430 | − QMetaObject::invokeMethod(this, "executeOnScriptThread", type, Q_ARG(std::function<void()>, function)); | |
| 430 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 431 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 432 | + manager->executeOnScriptThread(function, type); | |
| 433 | + }); | |
| 431 | 434 | return; |
| 432 | 435 | } |
| 433 | 436 | |
| @@ -859,10 +862,10 @@ void ScriptManager::removeEventHandler(const EntityItemID& entityID, const QStri · 425 unmodified lines | ||
| 859 | 862 | qCDebug(scriptengine) << "*** WARNING *** ScriptManager::removeEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 860 | 863 | "entityID:" << entityID << " eventName:" << eventName; |
| 861 | 864 | #endif |
| 862 | − QMetaObject::invokeMethod(this, "removeEventHandler", | |
| 863 | − Q_ARG(const EntityItemID&, entityID), | |
| 864 | − Q_ARG(const QString&, eventName), | |
| 865 | − Q_ARG(const ScriptValue&, handler)); | |
| 865 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 866 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 867 | + manager->removeEventHandler(entityID, eventName, handler); | |
| 868 | + }); | |
| 866 | 869 | return; |
| 867 | 870 | } |
| 868 | 871 | #ifdef THREAD_DEBUGGING |
| @@ -906,10 +909,10 @@ void ScriptManager::addEventHandler(const EntityItemID& entityID, const QString& · 37 unmodified lines | ||
| 906 | 909 | "entityID:" << entityID << " eventName:" << eventName; |
| 907 | 910 | #endif |
| 908 | 911 | |
| 909 | − QMetaObject::invokeMethod(this, "addEventHandler", | |
| 910 | − Q_ARG(const EntityItemID&, entityID), | |
| 911 | − Q_ARG(const QString&, eventName), | |
| 912 | − Q_ARG(const ScriptValue&, handler)); | |
| 912 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 913 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 914 | + manager->addEventHandler(entityID, eventName, handler); | |
| 915 | + }); | |
| 913 | 916 | return; |
| 914 | 917 | } |
| 915 | 918 | #ifdef THREAD_DEBUGGING |
| @@ -1168,7 +1171,10 @@ void ScriptManager::stop(bool marshal) { · 252 unmodified lines | ||
| 1168 | 1171 | _isStopping = true; // this can be done on any thread |
| 1169 | 1172 | |
| 1170 | 1173 | if (marshal) { |
| 1171 | − QMetaObject::invokeMethod(this, "stop"); | |
| 1174 | + // Lambda is necessary there to keep shared_ptr counter above zero if this gets called from different thread | |
| 1175 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 1176 | + manager->stop(false); | |
| 1177 | + }); | |
| 1172 | 1178 | return; |
| 1173 | 1179 | } |
| 1174 | 1180 | |
| @@ -2012,11 +2018,10 @@ bool ScriptManager::hasEntityScriptDetails(const EntityItemID& entityID) const { · 837 unmodified lines | ||
| 2012 | 2018 | |
| 2013 | 2019 | void ScriptManager::loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) { |
| 2014 | 2020 | if (QThread::currentThread() != thread()) { |
| 2015 | − QMetaObject::invokeMethod(this, "loadEntityScript", | |
| 2016 | − Q_ARG(const EntityItemID&, entityID), | |
| 2017 | − Q_ARG(const QString&, entityScript), | |
| 2018 | − Q_ARG(bool, forceRedownload) | |
| 2019 | − ); | |
| 2021 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2022 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2023 | + manager->loadEntityScript(entityID, entityScript, forceRedownload); | |
| 2024 | + }); | |
| 2020 | 2025 | return; |
| 2021 | 2026 | } |
| 2022 | 2027 | PROFILE_RANGE(script, __FUNCTION__); |
| @@ -2093,13 +2098,10 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 70 unmodified lines | ||
| 2093 | 2098 | << contents << "isURL:" << isURL << "success:" << success; |
| 2094 | 2099 | #endif |
| 2095 | 2100 | |
| 2096 | − QMetaObject::invokeMethod(this, "entityScriptContentAvailable", | |
| 2097 | − Q_ARG(const EntityItemID&, entityID), | |
| 2098 | − Q_ARG(const QString&, scriptOrURL), | |
| 2099 | − Q_ARG(const QString&, contents), | |
| 2100 | − Q_ARG(bool, isURL), | |
| 2101 | − Q_ARG(bool, success), | |
| 2102 | − Q_ARG(const QString&, status)); | |
| 2101 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2102 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2103 | + manager->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status); | |
| 2104 | + }); | |
| 2103 | 2105 | return; |
| 2104 | 2106 | } |
| 2105 | 2107 | |
| @@ -2443,9 +2445,10 @@ void ScriptManager::unloadEntityScript(const EntityItemID& entityID, bool should · 337 unmodified lines | ||
| 2443 | 2445 | "entityID:" << entityID; |
| 2444 | 2446 | #endif |
| 2445 | 2447 | |
| 2446 | − QMetaObject::invokeMethod(this, "unloadEntityScript", | |
| 2447 | − Q_ARG(const EntityItemID&, entityID), | |
| 2448 | − Q_ARG(bool, shouldRemoveFromMap)); | |
| 2448 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2449 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2450 | + manager->unloadEntityScript(entityID, shouldRemoveFromMap); | |
| 2451 | + }); | |
| 2449 | 2452 | return; |
| 2450 | 2453 | } |
| 2451 | 2454 | #ifdef THREAD_DEBUGGING |
| @@ -2496,8 +2499,10 @@ void ScriptManager::unloadAllEntityScripts(bool blockingCall) { · 44 unmodified lines | ||
| 2496 | 2499 | qCDebug(scriptengine) << "*** WARNING *** ScriptManager::unloadAllEntityScripts() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]"; |
| 2497 | 2500 | #endif |
| 2498 | 2501 | |
| 2499 | − QMetaObject::invokeMethod(this, "unloadAllEntityScripts", | |
| 2500 | − blockingCall ? Qt::BlockingQueuedConnection : Qt::QueuedConnection); | |
| 2502 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2503 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2504 | + manager->unloadAllEntityScripts(blockingCall ? Qt::BlockingQueuedConnection : Qt::QueuedConnection); | |
| 2505 | + }); | |
| 2501 | 2506 | return; |
| 2502 | 2507 | } |
| 2503 | 2508 | #ifdef THREAD_DEBUGGING |
| @@ -2590,12 +2595,10 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q · 86 unmodified lines | ||
| 2590 | 2595 | qCDebug(scriptengine) << "*** WARNING *** ScriptManager::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 2591 | 2596 | "entityID:" << entityID << "methodName:" << methodName; |
| 2592 | 2597 | #endif |
| 2593 | − | |
| 2594 | − QMetaObject::invokeMethod(this, "callEntityScriptMethod", | |
| 2595 | − Q_ARG(const EntityItemID&, entityID), | |
| 2596 | − Q_ARG(const QString&, methodName), | |
| 2597 | − Q_ARG(const QStringList&, params), | |
| 2598 | − Q_ARG(const QUuid&, remoteCallerID)); | |
| 2598 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2599 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2600 | + manager->callEntityScriptMethod(entityID, methodName, params, remoteCallerID); | |
| 2601 | + }); | |
| 2599 | 2602 | return; |
| 2600 | 2603 | } |
| 2601 | 2604 | #ifdef THREAD_DEBUGGING |
| @@ -2660,10 +2663,10 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q · 58 unmodified lines | ||
| 2660 | 2663 | "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; |
| 2661 | 2664 | #endif |
| 2662 | 2665 | |
| 2663 | − QMetaObject::invokeMethod(this, "callEntityScriptMethod", | |
| 2664 | − Q_ARG(const EntityItemID&, entityID), | |
| 2665 | − Q_ARG(const QString&, methodName), | |
| 2666 | − Q_ARG(const PointerEvent&, event)); | |
| 2666 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2667 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2668 | + manager->callEntityScriptMethod(entityID, methodName, event); | |
| 2669 | + }); | |
| 2667 | 2670 | return; |
| 2668 | 2671 | } |
| 2669 | 2672 | #ifdef THREAD_DEBUGGING |
| @@ -2699,11 +2702,10 @@ void ScriptManager::callEntityScriptMethod(const EntityItemID& entityID, const Q · 29 unmodified lines | ||
| 2699 | 2702 | "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; |
| 2700 | 2703 | #endif |
| 2701 | 2704 | |
| 2702 | − QMetaObject::invokeMethod(this, "callEntityScriptMethod", | |
| 2703 | − Q_ARG(const EntityItemID&, entityID), | |
| 2704 | − Q_ARG(const QString&, methodName), | |
| 2705 | − Q_ARG(const EntityItemID&, otherID), | |
| 2706 | − Q_ARG(const Collision&, collision)); | |
| 2705 | + // Lambda is necessary there to keep shared_ptr counter above zero | |
| 2706 | + QMetaObject::invokeMethod(this, [=, manager = shared_from_this()]{ | |
| 2707 | + manager->callEntityScriptMethod(entityID, methodName, otherID, collision); | |
| 2708 | + }); | |
| 2707 | 2709 | return; |
| 2708 | 2710 | } |
| 2709 | 2711 | #ifdef THREAD_DEBUGGING |