Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bullet wrapper issue #3509

Closed
eadle opened this issue Oct 24, 2015 · 3 comments
Closed

Bullet wrapper issue #3509

eadle opened this issue Oct 24, 2015 · 3 comments

Comments

@eadle
Copy link

@eadle eadle commented Oct 24, 2015

The Bullet wrapper currently doesn't allow a btPairCachingGhostObject to getAllContactManfolds. I've tracked this bug down to how a btBroadphasePair temporary instance is stored when trying to access an index in btBroadphasePairArray. It's an easy fix by storing the temporary btBroadphasePair instance in Java instead of C++. This doesn't change how the API is exposed and it looks like this is the desired behaviour anyway (see btBroadphasePair.java).

    /** Temporary instance, use by native methods that return a btBroadphasePair instance */
    protected final static btBroadphasePair temp = new btBroadphasePair(0, false);
    public static btBroadphasePair internalTemp(long cPtr, boolean own) {
        temp.reset(cPtr, own);
        return temp;
    }

I'll add to this tomorrow with an example to reproduce the results, but the following three file changes fixes the issue (this guy had a similar issue). I didn't make a pull request because I'm having no luck with swig. Any tips would be appreciated.

jni/swig-src/collision/collision_wrap.cpp:

SWIGEXPORT jlong JNICALL Java_com_badlogic_gdx_physics_bullet_collision_CollisionJNI_btBroadphasePairArray_1at(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
  jlong jresult = 0 ;
  btAlignedObjectArray< btBroadphasePair > *arg1 = (btAlignedObjectArray< btBroadphasePair > *) 0 ;
  btBroadphasePair *result = 0 ;
  int arg2 ;

  (void)jenv;
  (void)jcls;
  (void)jarg1_;
  arg1 = *(btAlignedObjectArray< btBroadphasePair > **)&jarg1;
  arg2 = (int)jarg2;
  result = (btBroadphasePair *) &((btAlignedObjectArray< btBroadphasePair > const *)arg1)->at(arg2);
  *(btBroadphasePair **)&jresult = result;
  return jresult;
}

jni/swig-src/collision/com/badlogic/gdx/physics/bullet/collision/btBroadphaseArray.java:

public btBroadphasePair at(int n) {
  return btBroadphasePair.internalTemp(CollisionJNI.btBroadphasePairArray_at(swigCPtr, this, n), false);
}

jni/swig-src/collision/CollisionJNI.java:

public final static native long btBroadphasePairArray_at(long jarg1, btBroadphasePairArray jarg1_, int jarg2);
@xoppa
Copy link
Member

@xoppa xoppa commented Oct 24, 2015

Thanks, would you mind to include a test to show the issue. Preferable something we can add to the tests.

@eadle
Copy link
Author

@eadle eadle commented Oct 26, 2015

Sorry for the delay. Finally figured out how to setup the libgdx tests in Android Studio. I think I've come up with a cool test that can only be solved with btPairCachingGhostObject, but it could take a little time before I make a pull request. If you just want a quick test just to reproduce the issue, let me know.

@badlogic
Copy link
Member

@badlogic badlogic commented Nov 16, 2015

Any update on this @eadle ?

@xoppa xoppa closed this in 22c0d9b Mar 17, 2016
xoppa added a commit that referenced this issue Mar 17, 2016
Fixes #3509 and adds a simple test program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.