From c4a4623ba87a5f8ffaeaff385f8a607acd6ad851 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 11 Jul 2017 15:11:48 -0700 Subject: [PATCH 1/5] Workaround the bug where Avatar Entities can't get deleted after switching domains --- scripts/system/spectatorCamera.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index 7786514edc..a9069a66a6 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -110,17 +110,28 @@ // // Description: // -Call this function to shut down the spectator camera and - // destroy the camera entity. - function spectatorCameraOff() { + // destroy the camera entity. "isChangingDomains" is true when this function is called + // from the "Window.domainChanged()" signal. + function spectatorCameraOff(isChangingDomains) { spectatorCameraConfig.attachedEntityId = false; spectatorCameraConfig.enableSecondaryCameraRenderConfigs(false); if (camera) { - Entities.deleteEntity(camera); + // Workaround for Avatar Entities not immediately having properties after + // the "Window.domainChanged()" signal is emitted. + // Should be removed after FB6155 is fixed. + if (isChangingDomains) { + Script.setTimeout(function () { + Entities.deleteEntity(camera); + camera = false; + }, 1 * 1000); + } else { + Entities.deleteEntity(camera); + camera = false; + } } if (viewFinderOverlay) { Overlays.deleteOverlay(viewFinderOverlay); } - camera = false; viewFinderOverlay = false; setDisplay(monitorShowsCameraView); // Change button to active when window is first openend OR if the camera is on, false otherwise. @@ -179,7 +190,9 @@ tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); addOrRemoveButton(false, HMD.active); tablet.screenChanged.connect(onTabletScreenChanged); - Window.domainChanged.connect(spectatorCameraOff); + Window.domainChanged.connect(function () { + spectatorCameraOff(true); + }); Window.geometryChanged.connect(resizeViewFinderOverlay); Controller.keyPressEvent.connect(keyPressEvent); HMD.displayModeChanged.connect(onHMDChanged); @@ -470,7 +483,9 @@ // -shutdown() will be called when the script ends (i.e. is stopped). function shutdown() { spectatorCameraOff(); - Window.domainChanged.disconnect(spectatorCameraOff); + Window.domainChanged.disconnect(function () { + spectatorCameraOff(true); + }); Window.geometryChanged.disconnect(resizeViewFinderOverlay); addOrRemoveButton(true, HMD.active); if (tablet) { From b0639be8bdf59eac377b0d939c5ed9c08a92fd1d Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 11 Jul 2017 15:23:50 -0700 Subject: [PATCH 2/5] Use function pointers correctly --- scripts/system/spectatorCamera.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index a9069a66a6..94e3dbde02 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -190,9 +190,7 @@ tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); addOrRemoveButton(false, HMD.active); tablet.screenChanged.connect(onTabletScreenChanged); - Window.domainChanged.connect(function () { - spectatorCameraOff(true); - }); + Window.domainChanged.connect(onDomainChanged); Window.geometryChanged.connect(resizeViewFinderOverlay); Controller.keyPressEvent.connect(keyPressEvent); HMD.displayModeChanged.connect(onHMDChanged); @@ -483,9 +481,7 @@ // -shutdown() will be called when the script ends (i.e. is stopped). function shutdown() { spectatorCameraOff(); - Window.domainChanged.disconnect(function () { - spectatorCameraOff(true); - }); + Window.domainChanged.disconnect(onDomainChanged); Window.geometryChanged.disconnect(resizeViewFinderOverlay); addOrRemoveButton(true, HMD.active); if (tablet) { @@ -501,6 +497,14 @@ } } + // Function Name: onDomainChanged() + // + // Description: + // -A small utility function used when the Window.domainChanged() signal is fired. + function onDomainChanged() { + spectatorCameraOff(true); + } + // These functions will be called when the script is loaded. startup(); Script.scriptEnding.connect(shutdown); From 1001097f9293197273a45aad423170a5bf29cf1e Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 11 Jul 2017 15:29:00 -0700 Subject: [PATCH 3/5] Fix button state --- scripts/system/spectatorCamera.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index 94e3dbde02..8945d006ab 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -113,6 +113,14 @@ // destroy the camera entity. "isChangingDomains" is true when this function is called // from the "Window.domainChanged()" signal. function spectatorCameraOff(isChangingDomains) { + + function deleteCamera() { + Entities.deleteEntity(camera); + camera = false; + // Change button to active when window is first openend OR if the camera is on, false otherwise. + button.editProperties({ isActive: onSpectatorCameraScreen || camera }); + } + spectatorCameraConfig.attachedEntityId = false; spectatorCameraConfig.enableSecondaryCameraRenderConfigs(false); if (camera) { @@ -121,12 +129,10 @@ // Should be removed after FB6155 is fixed. if (isChangingDomains) { Script.setTimeout(function () { - Entities.deleteEntity(camera); - camera = false; + deleteCamera(); }, 1 * 1000); } else { - Entities.deleteEntity(camera); - camera = false; + deleteCamera(); } } if (viewFinderOverlay) { @@ -134,10 +140,6 @@ } viewFinderOverlay = false; setDisplay(monitorShowsCameraView); - // Change button to active when window is first openend OR if the camera is on, false otherwise. - if (button) { - button.editProperties({ isActive: onSpectatorCameraScreen || camera }); - } } // Function Name: addOrRemoveButton() From 51c22eb7dbe318b5f8021c8fa549a8febcd0ee4a Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 11 Jul 2017 15:38:10 -0700 Subject: [PATCH 4/5] Also re-enable spectator camera after switching domains --- scripts/system/spectatorCamera.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index 8945d006ab..9d976a5608 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -130,6 +130,7 @@ if (isChangingDomains) { Script.setTimeout(function () { deleteCamera(); + spectatorCameraOn(); }, 1 * 1000); } else { deleteCamera(); From a27644ae4d71559053da55f62892522f449fb32c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 11 Jul 2017 15:52:12 -0700 Subject: [PATCH 5/5] Magic numbers --- scripts/system/spectatorCamera.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index 9d976a5608..661e40cdeb 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -112,6 +112,7 @@ // -Call this function to shut down the spectator camera and // destroy the camera entity. "isChangingDomains" is true when this function is called // from the "Window.domainChanged()" signal. + var WAIT_AFTER_DOMAIN_SWITCH_BEFORE_CAMERA_DELETE_MS = 1 * 1000; function spectatorCameraOff(isChangingDomains) { function deleteCamera() { @@ -131,7 +132,7 @@ Script.setTimeout(function () { deleteCamera(); spectatorCameraOn(); - }, 1 * 1000); + }, WAIT_AFTER_DOMAIN_SWITCH_BEFORE_CAMERA_DELETE_MS); } else { deleteCamera(); }