Skip to content

Commit

Permalink
jmeCollisionSpace: split "m_pEnv" into 2 fields
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 11, 2023
1 parent 420d9f4 commit f83e7e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/native/glue/com_jme3_bullet_CollisionSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ JNIEXPORT jlong JNICALL Java_com_jme3_bullet_CollisionSpace_getJniEnvId
pSpace = reinterpret_cast<jmeCollisionSpace *> (spaceId);
NULL_CHK(pEnv, pSpace, "The collision space does not exist.", 0);

const JNIEnv * result = pSpace->getEnv();
const JNIEnv * result = pSpace->getCreateEnv();
return reinterpret_cast<jlong> (result);
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/native/glue/jmeCollisionSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ bool jmeFilterCallback::needBroadphaseCollision(btBroadphaseProxy *pProxy0,
}

jmeCollisionSpace::jmeCollisionSpace(JNIEnv *pEnv, jobject javaSpace) {
this->m_pEnv = pEnv;
this->m_pCreateEnv = pEnv;
attachThread();

m_javaSpace = pEnv->NewWeakGlobalRef(javaSpace);
EXCEPTION_CHK(pEnv,);
Expand All @@ -107,9 +108,9 @@ jmeCollisionSpace::jmeCollisionSpace(JNIEnv *pEnv, jobject javaSpace) {
void jmeCollisionSpace::attachThread() {
#ifdef ANDROID
// doesn't match the Invocation API spec
jint retCode = jmeClasses::vm->AttachCurrentThread(&m_pEnv, NULL);
jint retCode = jmeClasses::vm->AttachCurrentThread(&m_pAttachEnv, NULL);
#else
jint retCode = jmeClasses::vm->AttachCurrentThread((void **)&m_pEnv, NULL);
jint retCode = jmeClasses::vm->AttachCurrentThread((void **)&m_pAttachEnv, NULL);
#endif
btAssert(retCode == JNI_OK);
}
Expand All @@ -131,7 +132,7 @@ btBroadphaseInterface * jmeCollisionSpace::createBroadphase(
pBroadphase = new btDbvtBroadphase(); //dance009
break;
default:
m_pEnv->ThrowNew(jmeClasses::IllegalArgumentException,
m_pCreateEnv->ThrowNew(jmeClasses::IllegalArgumentException,
"The broadphase type is out of range.");
return 0;
}
Expand Down
19 changes: 14 additions & 5 deletions src/main/native/glue/jmeCollisionSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ class jmeCollisionSpace {
protected:
btCollisionWorld * m_pCollisionWorld;
/*
* an interface pointer for the Java thread that simulates this space:
* interface pointer most recently attached by this space:
*/
JNIEnv *m_pEnv;
JNIEnv *m_pAttachEnv;
/*
* interface pointer for the thread that created this space:
*/
JNIEnv *m_pCreateEnv;
jobject m_javaSpace;
/*
* exclusive access to the JavaVM and JNIEnv during parallel for loops:
Expand Down Expand Up @@ -84,14 +88,19 @@ class jmeCollisionSpace {
}

const JNIEnv *
getEnv() const {
return m_pEnv;
getAttachEnv() const {
return m_pAttachEnv;
}

const JNIEnv *
getCreateEnv() const {
return m_pCreateEnv;
}

JNIEnv *
getEnvAndAttach() {
attachThread();
return m_pEnv;
return m_pAttachEnv;
}

jobject
Expand Down

0 comments on commit f83e7e1

Please sign in to comment.