Statically allocating the EntityScriptingInterface means we can't make sure it is initialized AFTER NodeList has been initialized
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -44,7 +44,7 @@ · 43 unmodified lines | |||
| 44 | #include "MIDIEvent.h" | 44 | #include "MIDIEvent.h" |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | EntityScriptingInterface ScriptEngine::_entityScriptingInterface; | 47 | EntityScriptingInterface* ScriptEngine::_entityScriptingInterface; |
| 48 | 48 | ||
| 49 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ | 49 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ |
| 50 | qDebug() << "script:print()<<" << context->argument(0).toString(); | 50 | qDebug() << "script:print()<<" << context->argument(0).toString(); |
| @@ -73,6 +73,13 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon · 22 unmodified lines | |||
| 73 | out = qobject_cast<AbstractInputController*>(object.toQObject()); | 73 | out = qobject_cast<AbstractInputController*>(object.toQObject()); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | EntityScriptingInterface* ScriptEngine::getEntityScriptingInterface() { | ||
| 77 | if (ScriptEngine::_entityScriptingInterface == nullptr) { | ||
| 78 | ScriptEngine::_entityScriptingInterface = new EntityScriptingInterface(); | ||
| 79 | } | ||
| 80 | return ScriptEngine::_entityScriptingInterface; | ||
| 81 | } | ||
| 82 | |||
| 76 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, | 83 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, |
| 77 | AbstractControllerScriptingInterface* controllerScriptingInterface) : | 84 | AbstractControllerScriptingInterface* controllerScriptingInterface) : |
| 78 | 85 | ||
| @@ -97,6 +104,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 18 unmodified lines | |||
| 97 | _isUserLoaded(false), | 104 | _isUserLoaded(false), |
| 98 | _arrayBufferClass(new ArrayBufferClass(this)) | 105 | _arrayBufferClass(new ArrayBufferClass(this)) |
| 99 | { | 106 | { |
| 107 | getEntityScriptingInterface(); | ||
| 100 | _allScriptsMutex.lock(); | 108 | _allScriptsMutex.lock(); |
| 101 | _allKnownScriptEngines.insert(this); | 109 | _allKnownScriptEngines.insert(this); |
| 102 | _allScriptsMutex.unlock(); | 110 | _allScriptsMutex.unlock(); |
| @@ -314,7 +322,7 @@ void ScriptEngine::init() { · 211 unmodified lines | |||
| 314 | 322 | ||
| 315 | auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>(); | 323 | auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>(); |
| 316 | 324 | ||
| 317 | _entityScriptingInterface.init(); | 325 | _entityScriptingInterface->init(); |
| 318 | 326 | ||
| 319 | // register various meta-types | 327 | // register various meta-types |
| 320 | registerMetaTypes(this); | 328 | registerMetaTypes(this); |
| @@ -352,7 +360,7 @@ void ScriptEngine::init() { · 31 unmodified lines | |||
| 352 | registerGlobalObject("Script", this); | 360 | registerGlobalObject("Script", this); |
| 353 | registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); | 361 | registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); |
| 354 | registerGlobalObject("Controller", _controllerScriptingInterface); | 362 | registerGlobalObject("Controller", _controllerScriptingInterface); |
| 355 | registerGlobalObject("Entities", &_entityScriptingInterface); | 363 | registerGlobalObject("Entities", _entityScriptingInterface); |
| 356 | registerGlobalObject("Quat", &_quatLibrary); | 364 | registerGlobalObject("Quat", &_quatLibrary); |
| 357 | registerGlobalObject("Vec3", &_vec3Library); | 365 | registerGlobalObject("Vec3", &_vec3Library); |
| 358 | registerGlobalObject("Uuid", &_uuidLibrary); | 366 | registerGlobalObject("Uuid", &_uuidLibrary); |
| @@ -489,13 +497,13 @@ void ScriptEngine::run() { · 130 unmodified lines | |||
| 489 | break; | 497 | break; |
| 490 | } | 498 | } |
| 491 | 499 | ||
| 492 | if (!_isFinished && _entityScriptingInterface.getEntityPacketSender()->serversExist()) { | 500 | if (!_isFinished && _entityScriptingInterface->getEntityPacketSender()->serversExist()) { |
| 493 | // release the queue of edit entity messages. | 501 | // release the queue of edit entity messages. |
| 494 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); | 502 | _entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); |
| 495 | 503 | ||
| 496 | // since we're in non-threaded mode, call process so that the packets are sent | 504 | // since we're in non-threaded mode, call process so that the packets are sent |
| 497 | if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) { | 505 | if (!_entityScriptingInterface->getEntityPacketSender()->isThreaded()) { |
| 498 | _entityScriptingInterface.getEntityPacketSender()->process(); | 506 | _entityScriptingInterface->getEntityPacketSender()->process(); |
| 499 | } | 507 | } |
| 500 | } | 508 | } |
| 501 | 509 | ||
| @@ -622,13 +630,13 @@ void ScriptEngine::run() { · 120 unmodified lines | |||
| 622 | // kill the avatar identity timer | 630 | // kill the avatar identity timer |
| 623 | delete _avatarIdentityTimer; | 631 | delete _avatarIdentityTimer; |
| 624 | 632 | ||
| 625 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { | 633 | if (_entityScriptingInterface->getEntityPacketSender()->serversExist()) { |
| 626 | // release the queue of edit entity messages. | 634 | // release the queue of edit entity messages. |
| 627 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); | 635 | _entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); |
| 628 | 636 | ||
| 629 | // since we're in non-threaded mode, call process so that the packets are sent | 637 | // since we're in non-threaded mode, call process so that the packets are sent |
| 630 | if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) { | 638 | if (!_entityScriptingInterface->getEntityPacketSender()->isThreaded()) { |
| 631 | _entityScriptingInterface.getEntityPacketSender()->process(); | 639 | _entityScriptingInterface->getEntityPacketSender()->process(); |
| 632 | } | 640 | } |
| 633 | } | 641 | } |
| 634 | 642 | ||