diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 9f1185cfb9..01f87da334 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -39,6 +39,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf OctreeRenderer(), _wantScripts(wantScripts), _entitiesScriptEngine(NULL), + _sandboxScriptEngine(NULL), _lastMouseEventValid(false), _viewState(viewState), _scriptingServices(scriptingServices), @@ -58,7 +59,10 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf } EntityTreeRenderer::~EntityTreeRenderer() { - // do we need to delete the _entitiesScriptEngine?? or is it deleted by default + // NOTE: we don't need to delete _entitiesScriptEngine because it's owned by the application and gets cleaned up + // automatically but we do need to delete our sandbox script engine. + delete _sandboxScriptEngine; + _sandboxScriptEngine = NULL; } void EntityTreeRenderer::clear() { @@ -79,6 +83,8 @@ void EntityTreeRenderer::init() { _entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities", _scriptingServices->getControllerScriptingInterface()); _scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine); + + _sandboxScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities Sandbox", NULL); } // make sure our "last avatar position" is something other than our current position, so that on our @@ -190,13 +196,15 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) { if (isURL) { _entitiesScriptEngine->setParentURL(entity->getScript()); } - QScriptValue entityScriptConstructor = _entitiesScriptEngine->evaluate(scriptContents); + QScriptValue entityScriptConstructor = _sandboxScriptEngine->evaluate(scriptContents); if (!entityScriptConstructor.isFunction()) { qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID; qDebug() << " NOT CONSTRUCTOR"; qDebug() << " SCRIPT:" << entityScript; return QScriptValue(); // invalid script + } else { + entityScriptConstructor = _entitiesScriptEngine->evaluate(scriptContents); } QScriptValue entityScriptObject = entityScriptConstructor.construct(); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 92cc2c4dcc..73406bcc15 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -135,6 +135,7 @@ private: bool _wantScripts; ScriptEngine* _entitiesScriptEngine; + ScriptEngine* _sandboxScriptEngine; QScriptValue loadEntityScript(EntityItem* entity); QScriptValue loadEntityScript(const EntityItemID& entityItemID);