lo-th / phy

Physics for three. Game engine
https://lo-th.github.io/phy/
MIT License
503 stars 42 forks source link

(Motor Bug) Joints cannot be removed if not on DEBUG mode #36

Open nebular opened 2 months ago

nebular commented 2 months ago

So if you add a joint with "debug" turned off

When removing this joint, phy.remove(joint.name) --- the routine in Motor will do nothing, as phy.byName() returns null - however the joint is kept alive in the worker.

This causes many nasty bugs - for example

After that crash, worker must be restarted.

My temp fix:

    // RLP: SEND ALWAYS TO MOTOR to remove non-exising joints
    static remove(name, direct = false, physicsType = "joint") {

        if (name.constructor === Array) return Motor.removes(name, direct);

        let b = Motor.byName(name);

        if (b) {

            // remove on three side

            if (b.extraRemove) b.extraRemove();
            ITEM_LIBRARY[b.type].clear(b);

        }

        const objectType = b ? b.type : physicsType;

        // remove on physics side
        if (objectType) root.post({ m: "remove", o: { name: name, type: objectType } }, null, direct);

    }

So when removing joints, I call remove(jointName, false, "joint") - or remove(jointName, false) as physicsType is set to joint. It's not the most elegant but it works well.

lo-th commented 1 month ago

mm yep i have to make research about that