Hi,
I’m not able to reproduce this issue in PG yet, so here’s at least the details I can provide at this moment if that would give anyone a clue what the problem might be:
- it happens since v8.10.1
- the problem disappears when I comment out one of these lines in my code:
camera.lockedTarget = movingGLTF;
// camera
is instance of TargetCamera
new HtmlMeshRenderer(scene)
// instance from babylonjs-addons
a few tracebacks (the same issue, just caught at different place):
22:13:54.580 Uncaught InternalError: too much recursion
InvertMatrixToArray thinMath.matrix.functions.ts:225 //const m = source.asArray();
invertToRef math.vector.ts:6510 //if (InvertMatrixToArray(this, other.asArray())) {
invert math.vector.ts:6362 //this.invertToRef(this);
setTarget targetCamera.ts:273 //TmpMatrix.invert();
_getViewMatrix targetCamera.ts:443 //this.setTarget(this._getLockedTargetPosition()!);
getViewMatrix camera.ts:874 //this._computedViewMatrix = this._getViewMatrix();
_onCameraMatrixChanged htmlMeshRenderer.ts:653
matrixObs htmlMeshRenderer.ts:211
notifyObservers observable.ts:439
getViewMatrix camera.ts:890
getWorldMatrix camera.ts:851
22:31:51.680 Uncaught InternalError: too much recursion
computeWorldMatrix transformNode.ts:1073 //this.computeWorldMatrix();
getAbsolutePosition transformNode.ts:503 //return this.getAbsolutePosition();
get transformNode.ts:361 //return this.getAbsolutePosition();
_getLockedTargetPosition targetCamera.ts:145 //if (this.lockedTarget.absolutePosition) {
_getViewMatrix targetCamera.ts:443 //this.setTarget(this._getLockedTargetPosition()!);
getViewMatrix camera.ts:874 //this._computedViewMatrix = this._getViewMatrix();
edit: still in process of finding a minimal reproducible example, but yet another piece of code which makes the error go away is removing this line I have in onBeforeRenderObservable
:
camera.position.addInPlace(new Vector3(x,y,z))
@yedpodtrzitko
The timing of this is suspicious as v8.10.1 has a breaking change in the target camera, but I don’t see how the changes could have caused a recursion problem. Are you aware of the breaking change? Maybe the breaking change is causing the code to go in a recursion loop? Are you using a right-handed scene?
Hi, thanks for your response.
I am indeed using right-handed scene. I have noticed some decision logic related to this in the traceback, so I tried to change that to see if that will make a difference, but it behaves the same even with a left-handed scene.
Ok, let me know how it goes. If you can provide a repro of some kind, I can see if I can track it down.
2 Likes
Sure, I’ll post here when I’ll get to some conclusion.
1 Like
Hi,
I managed somehow reproduce the error in PG. Uncommenting the line 11 fixes the problem there, but is still produces the error locally even with properly initiated values.
camera.rotationOffset = 1;
Hey @yedpodtrzitko In your PG you are using:
camera.rotationOffset
This is not a property in TargetCamera or Camera classes, so it returns undefined. Because it is undefined, your theta angle is undefined, which ends with x and z as NaN.
Then, you assign the vector (NaN, 1, NaN) to be the position of the camera:
And because of how NaN works, this test fails inside of babylon code:
Because of this, the observable keeps thinking it has to recalculate the word and view matrix, and enters in an infinite loop.
That is why when you uncomment your line camera.rotationOffset = 1 things work fine.
cc @bghgary
2 Likes
Hi,
thanks for your response. The PG code isn’t 1:1 copy of my local code as the comment on line 10 suggests (ie. “however locally it’s still causing error even that way”), and I am still trying to remove unrelated code in my project to get to the actual cause. This is the closest I got so far to reproduce the issue in PG. Having the value valid in fixes that in PG (not locally, I have a valid value there). However - should an invalid value for position
cause a recursion error?
1 Like
I would say if the invalid value on the position includes a NaN anywhere, this behaviour is expected because NaN compared to NaN will always return false.
The camera.onViewMatrixChangedObservable also has this warning about this:
Some methods like Camera.getViewMatrix and Camera.getWorldMatrix can trigger the onViewMatrixChangedObservable observable, so using them inside an observer will require additional logic to avoid a stack overflow error.
(from the docs here: Camera | Babylon.js Documentation)
If you can repro this with a position that is valid please share and we can investigate further.
3 Likes
I’m gonna assume that was really the case, so I’ll mark this as solved. Thanks for your insight and the effort you put looking into it.
1 Like