Null camera in advancedDynamicTexture doPicking method

Hi BJS community,
I’ve encountered a small issue with advancedDynamicTexture.
The doPicking method assumes that the camera is always there with a non-null assertion.
That’s not the case though and I get errors if the texture is created before the camera is added.

I’m not sure why the non-null assertion was added in the first place but I think we need to replace it with a check. If you are ok with that, I can make a PR for that.
And I’d probably fix some of the other arguable non-null assertions in this module btw.

Are you referring to this:

if (this._isFullscreen) {
            let camera = scene.cameraToUseForPointers || scene.activeCamera;
            let viewport = camera!.viewport;
            x = x * (textureSize.width / (engine.getRenderWidth() * viewport.width));
            y = y * (textureSize.height / (engine.getRenderHeight() * viewport.height));
        }

?
makes sense to me to check if the camera exists first, sure. The camera is technically needed for the viewport, but what would you expect the default behavior to be when no camera is available? return without running picking?

Are you referring to this:

Yeah. There is a link to this line in the first post.

return without running picking?

I think that’s fair. Picking is not possible if there is no viewport.
I’ll make a PR then.

2 Likes

Made a small PR
Removed all non-null assertions in this module.

2 Likes

Merged. thanks a lot!!