`GetMouseWheelMove` results in null pointer exception
Closed this issue · 4 comments
ejenk0 commented
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.
ejenk0 commented
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
ejenk0 commented
ejenk0 commented
CreedVI commented
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.