From b4b733ceb2401a8ed15df324f3309fe4f52ac4b9 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 11 Jan 2024 22:18:54 +0000 Subject: [PATCH] Fix handling of null device/context in ALC bindings (#108) Closes #100 --- .../java/org/lwjglx/openal/ALC10.java | 36 +++++++++++++------ .../java/org/lwjglx/openal/ALC11.java | 15 +++++--- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/generated/java/org/lwjglx/openal/ALC10.java b/src/generated/java/org/lwjglx/openal/ALC10.java index 7c6ee7f1..4e328e73 100644 --- a/src/generated/java/org/lwjglx/openal/ALC10.java +++ b/src/generated/java/org/lwjglx/openal/ALC10.java @@ -24,7 +24,7 @@ public class ALC10 { public static boolean alcCloseDevice(org.lwjglx.openal.ALCdevice device) { - boolean returnValue = org.lwjgl.openal.ALC10.alcCloseDevice(device.device); + boolean returnValue = org.lwjgl.openal.ALC10.alcCloseDevice(getDevice(device)); return returnValue; } @@ -46,56 +46,56 @@ public static org.lwjglx.openal.ALCcontext alcGetCurrentContext() { } public static void alcDestroyContext(org.lwjglx.openal.ALCcontext ctx) { - org.lwjgl.openal.ALC10.alcDestroyContext(ctx.context); + org.lwjgl.openal.ALC10.alcDestroyContext(getContext(ctx)); } public static org.lwjglx.openal.ALCdevice alcGetContextsDevice(org.lwjglx.openal.ALCcontext ctx) { - final long devId = org.lwjgl.openal.ALC10.alcGetContextsDevice(ctx.context); + final long devId = org.lwjgl.openal.ALC10.alcGetContextsDevice(getContext(ctx)); return new ALCdevice(devId); } public static int alcMakeContextCurrent(org.lwjglx.openal.ALCcontext ctx) { - return org.lwjgl.openal.ALC10.alcMakeContextCurrent(ctx.context) ? ALC_TRUE : ALC_FALSE; + return org.lwjgl.openal.ALC10.alcMakeContextCurrent(getContext(ctx)) ? ALC_TRUE : ALC_FALSE; } public static void alcProcessContext(org.lwjglx.openal.ALCcontext ctx) { - org.lwjgl.openal.ALC10.alcProcessContext(ctx.context); + org.lwjgl.openal.ALC10.alcProcessContext(getContext(ctx)); } public static void alcSuspendContext(org.lwjglx.openal.ALCcontext ctx) { - org.lwjgl.openal.ALC10.alcSuspendContext(ctx.context); + org.lwjgl.openal.ALC10.alcSuspendContext(getContext(ctx)); } public static int alcGetEnumValue(org.lwjglx.openal.ALCdevice device, java.lang.String enumName) { - int returnValue = org.lwjgl.openal.ALC10.alcGetEnumValue(device.device, enumName); + int returnValue = org.lwjgl.openal.ALC10.alcGetEnumValue(getDevice(device), enumName); return returnValue; } public static int alcGetError(org.lwjglx.openal.ALCdevice device) { - int returnValue = org.lwjgl.openal.ALC10.alcGetError(device.device); + int returnValue = org.lwjgl.openal.ALC10.alcGetError(getDevice(device)); return returnValue; } public static void alcGetInteger(org.lwjglx.openal.ALCdevice device, int pname, java.nio.IntBuffer integerdata) { - org.lwjgl.openal.ALC10.alcGetIntegerv(device.device, pname, integerdata); + org.lwjgl.openal.ALC10.alcGetIntegerv(getDevice(device), pname, integerdata); } public static java.lang.String alcGetString(org.lwjglx.openal.ALCdevice device, int pname) { - java.lang.String returnValue = org.lwjgl.openal.ALC10.alcGetString(device.device, pname); + java.lang.String returnValue = org.lwjgl.openal.ALC10.alcGetString(getDevice(device), pname); return returnValue; } public static boolean alcIsExtensionPresent(org.lwjglx.openal.ALCdevice device, java.lang.String extName) { - boolean returnValue = org.lwjgl.openal.ALC10.alcIsExtensionPresent(device.device, extName); + boolean returnValue = org.lwjgl.openal.ALC10.alcIsExtensionPresent(getDevice(device), extName); return returnValue; } @@ -108,4 +108,18 @@ public static org.lwjglx.openal.ALCdevice alcOpenDevice(java.lang.String arg0) { return returnValue; } + private static long getDevice(org.lwjglx.openal.ALCdevice dev) { + if (dev == null) { + return 0; + } + return dev.device; + } + + private static long getContext(org.lwjglx.openal.ALCcontext context) { + if (context == null) { + return 0; + } + return context.context; + } + } diff --git a/src/generated/java/org/lwjglx/openal/ALC11.java b/src/generated/java/org/lwjglx/openal/ALC11.java index e16c7607..8bf70a8e 100644 --- a/src/generated/java/org/lwjglx/openal/ALC11.java +++ b/src/generated/java/org/lwjglx/openal/ALC11.java @@ -12,7 +12,7 @@ public class ALC11 { public static boolean alcCaptureCloseDevice(org.lwjglx.openal.ALCdevice device) { - boolean returnValue = org.lwjgl.openal.ALC11.alcCaptureCloseDevice(device.device); + boolean returnValue = org.lwjgl.openal.ALC11.alcCaptureCloseDevice(getDevice(device)); return returnValue; } @@ -28,20 +28,27 @@ public static org.lwjglx.openal.ALCdevice alcCaptureOpenDevice(java.lang.String public static void alcCaptureSamples(org.lwjglx.openal.ALCdevice device, java.nio.ByteBuffer buffer, int samples) { - org.lwjgl.openal.ALC11.alcCaptureSamples(device.device, buffer, samples); + org.lwjgl.openal.ALC11.alcCaptureSamples(getDevice(device), buffer, samples); } public static void alcCaptureStart(org.lwjglx.openal.ALCdevice device) { - org.lwjgl.openal.ALC11.alcCaptureStart(device.device); + org.lwjgl.openal.ALC11.alcCaptureStart(getDevice(device)); } public static void alcCaptureStop(org.lwjglx.openal.ALCdevice device) { - org.lwjgl.openal.ALC11.alcCaptureStop(device.device); + org.lwjgl.openal.ALC11.alcCaptureStop(getDevice(device)); } + private static long getDevice(org.lwjglx.openal.ALCdevice dev) { + if (dev == null) { + return 0; + } + return dev.device; + } + }