From 32738dfd66e198815f5a06fabbe58e0f8426a577 Mon Sep 17 00:00:00 2001 From: stephengold Date: Sat, 21 Sep 2024 11:43:52 -0700 Subject: [PATCH] Body: changed the semantics of the getId() method --- src/main/java/com/github/stephengold/joltjni/Body.java | 10 ++++------ src/main/native/glue/b/Body.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/stephengold/joltjni/Body.java b/src/main/java/com/github/stephengold/joltjni/Body.java index 86582043..8ee02658 100644 --- a/src/main/java/com/github/stephengold/joltjni/Body.java +++ b/src/main/java/com/github/stephengold/joltjni/Body.java @@ -24,7 +24,6 @@ of this software and associated documentation files (the "Software"), to deal import com.github.stephengold.joltjni.enumerate.EMotionType; import com.github.stephengold.joltjni.readonly.ConstAaBox; import com.github.stephengold.joltjni.readonly.ConstBody; -import com.github.stephengold.joltjni.readonly.ConstBodyId; import com.github.stephengold.joltjni.readonly.ConstShape; import com.github.stephengold.joltjni.readonly.QuatArg; import com.github.stephengold.joltjni.readonly.RVec3Arg; @@ -460,17 +459,16 @@ public float getFriction() { } /** - * Access the body's ID for use with {@code BodyInterface}. The body is + * Copy the body's ID for use with {@code BodyInterface}. The body is * unaffected. * - * @return a new immutable JVM object with the pre-existing native object - * assigned + * @return a new object */ @Override - public ConstBodyId getId() { + public BodyId getId() { long bodyVa = va(); long bodyIdVa = getId(bodyVa); - ConstBodyId result = new BodyId(bodyIdVa, false); + BodyId result = new BodyId(bodyIdVa, true); return result; } diff --git a/src/main/native/glue/b/Body.cpp b/src/main/native/glue/b/Body.cpp index 885abc7e..8d8b170a 100644 --- a/src/main/native/glue/b/Body.cpp +++ b/src/main/native/glue/b/Body.cpp @@ -344,8 +344,10 @@ JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_Body_getFriction JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_Body_getId (JNIEnv *, jclass, jlong bodyVa) { const Body * const pBody = reinterpret_cast (bodyVa); - const BodyID &result = pBody->GetID(); - return reinterpret_cast (&result); + const BodyID &id = pBody->GetID(); + BodyId * pResult = new BodyID(id); + TRACE_NEW("BodyID", pResult) + return reinterpret_cast (pResult); } inline static const Vec3 getLinearVelocity(jlong bodyVa) {