n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.

Home Page:https://n5ro.github.io/aframe-physics-system/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read property '_wakeUpAfterNarrowphase' of undefined

arthurmougin opened this issue · comments

Hello, i am using aframe physics system with pool for a bubble game.

Problem, randomly after acollide (i return the pooled bubble on collide), this error message appear:

aframe-physics-system.js:14639 Uncaught TypeError: Cannot read property 
'_wakeUpAfterNarrowphase' of undefined
    at World.internalStep (aframe-physics-system.js:14639)
    at World.step (aframe-physics-system.js:14337)
    at LocalDriver.step (aframe-physics-system.js:18353)
    at o.tick (aframe-physics-system.js:19022)
    at HTMLElement.tick (a-scene.js:725)
    at HTMLElement.render (a-scene.js:769)
    at bind.js:12
    at f (three.js:25931)
    at t (three.js:14337)

When colliding, i call this function :

pop: function (e) {
        var minimumAge = 100;//value tested over time
        
        //if e is a collide event
        if(e.detail) { 
            e.preventDefault();
            console.log("pop collision", e);
                // sometimes e design the plane and we want to ignore it
            if(e.detail.body.el.components.bubble == undefined) return; 
                //fixing the context on the fly
            this.el = e.srcElement;
            
               //calcul age of bubble (first fix trial)
            let deathdate = +new Date();
            let lifetime = deathdate - this.el.birthdate;
            console.log(lifetime);
                //popping bubbles to early can cause crash
            if(lifetime < minimumAge) {
                console.warn("too young to die");
                return;
            }
        }else {// if e is el, called from a setTimeout
            //fixing the context on the fly
            this.el = e;
            //prevent false trigger
            if(!this.el.isplaying) return;
        }
        this.el.parentEl.components.pool__bubble.returnEntity(this.el);
        this.el.removeEventListener('collide', this.pop);
        this.el.isplaying = false;/**/
    },

when spawning an entity from the pool I use this function :

 var newbub = this.el.sceneEl.components.pool__bubble.requestEntity();
        if(newbub){
                //set spawn position at child coordonate
            el.object3D.updateMatrixWorld();
            var newpos =  new THREE.Vector3().setFromMatrixPosition(el.firstElementChild.object3D.matrixWorld);
            newbub.setAttribute('position', newpos);
            newbub.play();
                //set impulse direction
            var target = new CANNON.Vec3().copy(newpos);
            var direction = target.vsub(el.object3D.position);
               //varying direction
            direction.x += (Math.random()*2*data.directionVariation)-data.directionVariation;
            direction.y += (Math.random()*2*data.directionVariation)-data.directionVariation;
            direction.z += (Math.random()*2*data.directionVariation)-data.directionVariation;
            direction.normalize();
            var force = data.spawnForce;
                //varying force
            force += (Math.random()*2*data.spawnForceInterval)-data.spawnForceInterval;
            var impulse = direction.mult(force);
            newbub.body.applyImpulse(
            /* impulse */        impulse,
            /* world position */ new CANNON.Vec3().copy(newpos)
            );
        }

Did you see #36 ?

thank you for the advice, i tested the fix provided and managed to find a solution: using an async function as the event callback.

image

Well... sadly it is still happening but less frequently :)

I fixed it by externalizing the deletion of the element from the callback and putting on the tick handler.
image
image