Skip to content

Commit

Permalink
bugfix: IllegalStateException in MotorcycleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 11, 2024
1 parent 047b332 commit a939107
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public VehicleCollisionTester getVehicleCollisionTester() {
public Wheel getWheel(int wheelIndex) {
long constraintVa = va();
long wheelVa = getWheel(constraintVa, wheelIndex);
Wheel result = new Wheel(wheelVa);
int ordinal = Constraint.getControllerType(constraintVa);
Wheel result = Wheel.newWheel(wheelVa, ordinal);

return result;
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Wheel.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,35 @@ public ConstWheelSettings getSettings() {
WheelSettings result = (WheelSettings) settings.getPtr();
return result;
}

/**
* Instantiate a {@code Wheel} from its virtual address.
*
* @param wheelVa the virtual address of the native object, or zero
* @param ordinal the type of {@code VehicleController}
* @return a new JVM object, or {@code null} if {@code wheelVa} was
* zero
*/
public static Wheel newWheel(long wheelVa, int ordinal) {
if (wheelVa == 0L) {
return null;
}

Wheel result;
switch (ordinal) {
case VehicleController.motorcycleType:
case VehicleController.wheeledVehicleType:
result = new WheelWv(wheelVa);
break;
case VehicleController.trackedVehicleType:
result = new WheelTv(wheelVa);
break;
default:
throw new IllegalArgumentException("ordinal = " + ordinal);
}

return result;
}
// *************************************************************************
// native private methods

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/github/stephengold/joltjni/WheelTv.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public class WheelTv extends Wheel {
// constructors

/**
* Instantiate with no native object assigned.
* <p>
* This no-arg constructor was made explicit to avoid javadoc warnings from
* JDK 18+.
* Instantiate with the specified native object assigned but not owned.
*
* @param wheelVa the virtual address of the native object to assign (not
* zero)
*/
WheelTv() {
WheelTv(long wheelVa) {
super(wheelVa);
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/github/stephengold/joltjni/WheelWv.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public class WheelWv extends Wheel {
// constructors

/**
* Instantiate with no native object assigned.
* <p>
* This no-arg constructor was made explicit to avoid javadoc warnings from
* JDK 18+.
* Instantiate with the specified native object assigned but not owned.
*
* @param wheelVa the virtual address of the native object to assign (not
* zero)
*/
WheelWv() {
WheelWv(long wheelVa) {
super(wheelVa);
}
}

0 comments on commit a939107

Please sign in to comment.