Skip to content

Commit

Permalink
softbody : fixed error on softjoint finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
dokthar committed Apr 19, 2016
1 parent a3ee141 commit 4c0312e
Showing 1 changed file with 28 additions and 4 deletions.
Expand Up @@ -36,6 +36,8 @@
import com.jme3.export.*;
import com.jme3.math.Vector3f;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* <p>
Expand All @@ -53,6 +55,8 @@ public abstract class SoftPhysicsJoint extends PhysicsJoint {
protected float constraintForceMixing = 1;
protected float split = 1;

private boolean added = false;

protected SoftPhysicsJoint() {
}

Expand Down Expand Up @@ -97,6 +101,7 @@ public boolean isCollisionBetweenLinkedBodys() {

/**
* Get the error reduction parameter coefficient (aka ERP).
* <p>From bullet documentation :</p>
* <p>
* The ERP specifies what proportion of the joint error will be fixed during
* the next simulation step.
Expand All @@ -121,6 +126,7 @@ public float getErrorReductionParameter() {

/**
* Set the error reduction parameter coefficient (aka ERP).
* <p>From bullet documentation :</p>
* <p>
* The ERP specifies what proportion of the joint error will be fixed during
* the next simulation step.
Expand All @@ -145,6 +151,7 @@ public void setErrorReductionParameter(float erp) {

/**
* Get the constraint force mixing coefficient (aka CFM).
* <p>From bullet documentation :</p>
* <ul>
* <li>If CFM = 0 then the constraint will be hard.
* <li>If CFM is set to a positive value, it will be possible to violate the
Expand All @@ -168,6 +175,7 @@ public float getConstraintForceMixing() {

/**
* Set the constraint force mixing coefficient (aka CFM).
* <p> From bullet documentation :</p>
* <ul>
* <li>If CFM = 0 then the constraint will be hard.
* <li>If CFM is set to a positive value, it will be possible to violate the
Expand Down Expand Up @@ -279,22 +287,38 @@ public void read(JmeImporter im) throws IOException {
* SoftPhysicsSpace.
*/
public void addConstraint() {
addConstraint(objectId, softA.getObjectId());
if (!added) {
addConstraint(objectId, softA.getObjectId());
added = true;
}
}

private native void addConstraint(long jointId, long bodyId);

/**
* Remove the constraint to bodies. The constraint must be already added.
* Remove the constraint from bodies.
* This method shouldn't be called in the user code, already called by the
* SoftPhysicsSpace.
*/
public void removeConstraint() {
removeConstraint(objectId, softA.getObjectId());
if (added) {
removeConstraint(objectId, softA.getObjectId());
added = false;
}
}

private native void removeConstraint(long jointId, long bodyId);

@Override
protected native void finalizeNative(long objectId);
protected void finalizeNative(long objectId){
// override finalizeNative instead of finalize
// only want to verify condition on 'added' boolean before native finalize call
// this way it will still call Object.finalize()
if (added) {
Logger.getLogger(this.getClass().getName()).log(Level.FINE, "SoftJoint {0} is still attached, it will be destroyed by the softBody", Long.toHexString(objectId));
} else {
super.finalizeNative(objectId);
}
}

}

0 comments on commit 4c0312e

Please sign in to comment.