Skip to content

Conversation

@vincentfretin
Copy link
Contributor

Description:

We get a Uncaught TypeError: this.removeChild is not a function error when removing the scene if we had the reflection component on it and we didn't enter vr mode.

Changes proposed:

  • Be sure this.probeLight exists before trying to remove it, also use this.el.removeChild instead of non existing this.removeChild
  • Add a test that doesn't fail on this error
this.cubeCamera = new THREE.CubeCamera(0.1, 1000, this.cubeRenderTarget);
this.lightingEstimationTexture = (new THREE.WebGLCubeRenderTarget(16)).texture;
this.needsVREnvironmentUpdate = true;
this.probeLight = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to declare the variable in init like this. Also I check for it in the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to declare it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need to declare it. There is also other variables used on this that are not declared either.

this.cubeCamera.position.set(0, 1.6, 0);
this.cubeCamera.update(renderer, scene);
this.el.object3D.environment = this.cubeRenderTarget.texture;
scene.environment = this.cubeRenderTarget.texture;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use scene.environment = null three line above, we should use the scene variable here for symmetry :)

this.removeChild(this.probeLight);
if (this.probeLight) {
this.el.removeChild(this.probeLight);
this.probeLight = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.probeLight = null; is not mandatory, but I find it good code hygiene to remove any reference to a DOM element explicitly. This can help the GC too.

Copy link
Member

@dmarcos dmarcos Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be undefined. null represents a missing object. In this case we're resetting the variable. Also for style consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the line. This doesn't add much. The component is removed anyway, so the DOM element is removed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About null vs undefined, please note that in the aframe code base we are currently setting some variable to null in remove like I suggested. In the text component for example:

remove: function () {
this.geometry.dispose();
this.geometry = null;
this.el.removeObject3D(this.attrName);
this.material.dispose();
this.material = null;
this.texture.dispose();
this.texture = null;
if (this.shaderObject) { delete this.shaderObject; }
},

@dmarcos
Copy link
Member

dmarcos commented Sep 27, 2022

Thank you!

@dmarcos dmarcos merged commit 6b7452d into aframevr:master Sep 27, 2022
@vincentfretin vincentfretin deleted the fix-reflection-removal branch September 30, 2022 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants