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

Fixed issue where light fails to set already loaded target #2715

Merged
merged 1 commit into from
Jun 1, 2017

Conversation

RSpace
Copy link
Contributor

@RSpace RSpace commented Jun 1, 2017

Description:

By switching out models and lights dynamically in a scene, I have exposed an issue in the light component where a null reference exception occurs when creating a new spot or directional light where the target is already loaded.

setLight calls getLight which calls onSetTarget. onSetTarget expects this.light to be present, which works as long as the target is not loaded, since an event listener is set up in getLight, giving this.light time to get set in setLight. When the target is not loaded, however, onSetTarget is called immediately and this.light is undefined.

Changes proposed:

  • Added tests to expose the issue
  • Call onSetTarget with the new light to set the target on, instead of relying on this.light
  • Continue to also set target on this.light if present (this was necessary to get all tests passing, not sure why)

onSetTarget: function (targetEl) {
this.light.target = targetEl.object3D;
onSetTarget: function (targetEl, light) {
if (this.light) { this.light.target = targetEl.object3D; }
Copy link
Member

Choose a reason for hiding this comment

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

Can we just rely on the light parameter? Do we need to check both this.light and light?

light.target = targrtEl.object3D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmarcos Right, I made a simplification and all tests still pass.

… already loaded.

Added fix for the issue, so the newly created light gets the target set.
@RSpace RSpace force-pushed the loaded-light-target branch from 4e97a64 to bb675f1 Compare June 1, 2017 10:34
@dmarcos
Copy link
Member

dmarcos commented Jun 1, 2017

Thanks!

@dmarcos dmarcos merged commit e6b5935 into aframevr:master Jun 1, 2017
@RSpace RSpace deleted the loaded-light-target branch June 1, 2017 11:05
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.

2 participants