`GetMouseWheelMove` results in null pointer exception
Describe the bug Calling Raylib.core.GetMouseWheelMove results in a:
Exception in thread "main" java.lang.NullPointerException: Cannot read field "x" because "this.input.mouse.currentWheelMove" is null
at com.raylib.java.core.rCore.GetMouseWheelMove(rCore.java:2316)
Code
private void zoomCamera(float delta) {
camera.zoom = Math.clamp(camera.zoom + delta, ZOOM_MIN, ZOOM_MAX);
}
public void update(Raylib r) {
// Mouse drag camera controls
if (r.core.IsMouseButtonDown(MOUSE_BUTTON_MIDDLE.ordinal())) {
Vector2 delta = r.core.GetMouseDelta();
delta = Vector2Scale(delta, -CAMERA_PAN_ZOOM_FACTOR / camera.zoom);
shiftCamera(delta);
}
// Mouse zoom camera controls
float mouseWheelMovement = r.core.GetMouseWheelMove();
if (mouseWheelMovement != 0) {
zoomCamera(mouseWheelMovement * ZOOM_SPEED);
}
}
Desktop (please complete the following information):
- OS: MacOS Sonoma
Additional context Raylib-J Version: Release 0.5.2
Known workaround
This only seems to be a problem on the first frame/invocation for me, so just checking that the result of GetMouseWheelMoveV is not null is sufficient.
Similarly with GetMouseWheelMoveV:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.raylib.java.raymath.Vector2.getY()" because the return value of "com.raylib.java.core.rCore.GetMouseWheelMoveV()" is null
It appears to only be null on the first invocation. Here I am printing it out every frame
This is weird. In the decompiled Mouse class it has an empty initialiser, despite the fact that I just compiled it from source and I can see that it should have one...
The empty constructor is due to code optimization during compilation. You can see the lines that were previously in the default constructor have been moved to be inline with the variables.
However you can see I forgot to add the currentWheelMove and previousWheelMove initialization. Easy fix, so I'll be able to get this fixed rather quick.