Hello all
I am new to this, so it might be a problem with me. I’m implementing a drag and drop by using this PG: https://www.babylonjs-playground.com/#1HTCCO#21 as my base code, but there is problem with it, when I do drag and drop the box for some minutes then it crashes and the theres nothing in the scene with an exception error “Uncaught RangeError: Maximum call stack size exceeded”. I googled it and found out its because of using setAbsolutePosition here:
var onPointerMove = function (evt) {
if (!dragPoint) {
return;
}
var pickParentInfo = pickParent(currentMesh);
if (!pickParentInfo.hit) {
return;
}
var current = pickParentInfo.pickedPoint;
var normal = pickParentInfo.getNormal(true);
var parentMesh = pickParentInfo.pickedMesh;
if (parentMesh == currentMesh.parent &&
normal.x == planeNormal.x &&
normal.y == planeNormal.y &&
normal.z == planeNormal.z) {
var dragVector = current.subtract(dragPoint);
currentMesh.position.addInPlace(dragVector);
}
else {
var displacement = new BABYLON.Vector3(-0.5, -0.5, -0.5); //TODO: calcular esse vetor de acordo com o ponto zero do mesh
var vector = normal.multiply(displacement);
var boundingInfo = currentMesh.getBoundingInfo();
var dimensions = boundingInfo.maximum.subtract(boundingInfo.minimum);
var diff = dimensions.multiply(vector);
var absolutePosition = current.subtract(diff);
currentMesh.parent = parentMesh;
currentMesh.setAbsolutePosition(absolutePosition);
planeNormal = normal;
}
dragPoint = current;
}
Is there any other alternative or solution for that?
One i can understand, but three thrown at the same time?..
Might be line 120 and 121 in the playground (setting the parents and setting its absolute position), but this is an uneducated guess.
The isssue is the playground itself. this happens when you are dragging one of the objects (let’s say blue) and move very fast with the mouse that you eventually on top of red. Then the parenting system goes crazy.
Thank you for your solution. I checked it but still giving error although it needs more time working on it to give the error, so its an improvement. even using “currentMesh.position = absolutePosition.clone();” instead of “currentMesh.setAbsolutePosition(absolutePosition);” does not remove the error but it changes the behavior.
my question is that is this the right way to have this kind of behavior between two meshes or is there another way without using setAbsoluteposition?
I did the second one with setAbsolute and was not able to recreate the error no matter how fast I clicked dragged and did interactions, how are you triggering the error? Is it when like the mouse is being released not with focus on the canvas or something?
Drag the objects tword the camera to the bottom of the screen (under the camera basically) and this only works for when you move an object with a child on it. hmmmm, its gotta be in the _syncParentEnabledState for some reason is recursing over itself to many times?
Its kinda hard to make it happen reliably.
Give me a second I might be able to figure this out.
I am actually gonna second this as a bug. Its kinda weird behavior and is seeming to be linked to how the children/parents are being synced.
I tried enabling .alwaysSelectAsActiveMesh = true; on both meshes to disable culling to see if it was the camera frustrum toggling the enable at the wrong time, but that did not seem to do anything.
just grab the blue cube that has a the child red sphere parented to it to the bottom of the screen and start wiggling back and forth is the easiest way to get it to trigger that I have found.
Looking at it I’m starting to think that these two methods are just passing themselves back and forth?
isSynchronized has a part that calls isSynchronizedWithParent() which might return isSynchronized agian and on and on and on perhaps?
I do not think it is the setAbsolutePosition that is the problem and I have checked all the variables I can think of that he is using and none are ever coming back and null or undefined prior to the error drop.