From 93755e65065a1eb791b69caff31a8c46fa438d9d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 22 Nov 2014 11:53:50 -0800 Subject: [PATCH] fix bugs in unloading scripts when changing domains --- examples/entityScripts/sitOnEntity.js | 15 +++------------ interface/src/entities/EntityTreeRenderer.cpp | 4 +++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/examples/entityScripts/sitOnEntity.js b/examples/entityScripts/sitOnEntity.js index 8769ab55fd..d5c4fa9c52 100644 --- a/examples/entityScripts/sitOnEntity.js +++ b/examples/entityScripts/sitOnEntity.js @@ -127,9 +127,7 @@ } var globalMouseClick = function(event) { - print("globalMouseClick"); var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - if (clickedOverlay == externalThis.standUpButton) { seat.model = null; externalThis.standUp(); @@ -166,6 +164,7 @@ } catch (e){} Script.update.connect(standingUpAnimation); Overlays.editOverlay(this.standUpButton, { visible: false }); + Controller.mousePressEvent.disconnect(globalMouseClick); } function SeatIndicator(modelProperties, seatIndex) { @@ -226,20 +225,11 @@ print("Was seated: " + sitting); storeStartPoseAndTransition(); updateJoints(1.0); - Overlays.editOverlay(this.standUpButton, { visible: true }); } } frame++; } - - var locationChanged = false; - if (location.hostname != oldHost || !location.isConnected) { - this.removeIndicators(); - oldHost = location.hostname; - locationChanged = true; - } } - var oldHost = location.hostname; this.addIndicators = function() { if (!this.indicatorsAdded) { @@ -351,12 +341,13 @@ this.unload = function(entityID) { this.cleanup(); + Script.update.disconnect(update); }; this.preload = function(entityID) { this.updateProperties(entityID); // All callbacks start by updating the properties this.createStandupButton(); - Script.update.connect(update); // do we want to do this??? how expensive will this be? + Script.update.connect(update); }; diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index 2544ecc792..4587fcf92e 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -64,6 +64,9 @@ EntityTreeRenderer::~EntityTreeRenderer() { } void EntityTreeRenderer::clear() { + foreach (const EntityItemID& entityID, _entityScripts.keys()) { + checkAndCallUnload(entityID); + } OctreeRenderer::clear(); _entityScripts.clear(); } @@ -858,7 +861,6 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI } void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) { - checkAndCallUnload(entityID); _entityScripts.remove(entityID); }