Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly dispose renderer to stop the animation loop #5112

Merged
merged 1 commit into from
Sep 10, 2022

Conversation

vincentfretin
Copy link
Contributor

Description:
In aframe 1.3.0 and master (three r141), when you are removing the a-scene from the DOM, it disposes the WebXRManager/WebVRManager (renderer.xr) on detachedCallback but not the renderer itself (WebGLRenderer), so it doesn't stop properly the animation loop and it continues executing some tick methods.
You can test with document.body.removeChild(AFRAME.scenes[0])
Before the PR:
Capture d’écran du 2022-09-10 17-42-52

After the PR:
Capture d’écran du 2022-09-10 18-33-41

This is known issue since a long time, see #3146 (comment) and https://stackoverflow.com/questions/54930875/aframejs-how-to-completely-destroy-a-scene and I also documented it in https://aframe.wiki/en/memory

Changes proposed:

Properly disposing the renderer in detachedCallback seems right because in attachedCallback that is calling this.setupRenderer() we're creating a new WebGLRenderer always.
But note that detaching or reattaching the scene is not a supported use case, it gives currently an error before and after this PR anyway on the /examples/boilerplate/3d-model/ example where I tested that and I'm no gonna investigate that.

scene=AFRAME.scenes[0]
document.body.removeChild(scene)
document.body.appendChild(scene)
core:a-entity:warn Tried to remove `Object3D` of type:  mesh which was not defined.
2
browser.js:111 core:a-node:error Failure loading node:   TypeError: Cannot read properties of undefined (reading 'constructor')
    at extendProperties (component.js:736:1)
    at NewComponent.callUpdateHandler (component.js:416:1)
    at NewComponent.updateProperties (component.js:300:1)
    at HTMLElement.value (a-entity.js:490:1)
    at HTMLElement.value (a-entity.js:456:1)
    at entityLoadCallback (a-entity.js:249:1)
    at emitLoaded (a-node.js:127:1)
browser.js:111 components:gltf-model:warn Unexpected token '<', "<!DOCTYPE "... is not valid JSON 

@dmarcos
Copy link
Member

dmarcos commented Sep 10, 2022

Thanks!

@dmarcos dmarcos merged commit fb67365 into aframevr:master Sep 10, 2022
@vincentfretin vincentfretin deleted the properly-dispose-renderer branch September 11, 2022 07:46
@vincentfretin vincentfretin mentioned this pull request Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants