LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.76k stars 636 forks source link

SOFTReopenDevice#alcReopenDeviceSOFT doesn't allow null deviceName #793

Closed Berstanio closed 2 years ago

Berstanio commented 2 years ago

Version

3.3.2 (nightly)

Platform

macOS arm64

JDK

graalvm 22.2 Java 11

Module

OpenAL

Bug description

The function SOFTReopenDevice#alcReopenDeviceSOFT should accept a null deviceName as parameter, as it is described in the OpenAL-soft docs https://openal-soft.org/openal-extensions/SOFT_reopen_device.txt. However the source looks like this:

    public static boolean alcReopenDeviceSOFT(@NativeType("ALCdevice *") long device, @NativeType("ALCchar const *") ByteBuffer deviceName, @Nullable @NativeType("ALCint const *") IntBuffer attribs) {
        if (CHECKS) {
            checkNT1(deviceName);
            checkNTSafe(attribs);
        }
        return nalcReopenDeviceSOFT(device, memAddress(deviceName), memAddressSafe(attribs));
    }

However it should be:

    public static boolean alcReopenDeviceSOFT(@NativeType("ALCdevice *") long device, @NativeType("ALCchar const *") ByteBuffer deviceName, @Nullable @NativeType("ALCint const *") IntBuffer attribs) {
        if (CHECKS) {
            checkNT1Safe(deviceName);
            checkNTSafe(attribs);
        }
        return nalcReopenDeviceSOFT(device, memAddressSafe(deviceName), memAddressSafe(attribs));
    }

Calling the nalc method directly with SOFTReopenDevice.nalcReopenDeviceSOFT(device, memAddressSafe((ByteBuffer)null), memAddressSafe((IntBuffer)null)) works as expected.

Stacktrace or crash log output

Caused by: java.lang.NullPointerException
    at org.lwjgl.system.Checks.checkNT1(Checks.java:226)
    at org.lwjgl.openal.SOFTReopenDevice.alcReopenDeviceSOFT(SOFTReopenDevice.java:57)
    ... 18 more

or when disabling checks:
Caused by: java.lang.NullPointerException
    at org.lwjgl.system.MemoryUtil.memAddress(MemoryUtil.java:737)
    at org.lwjgl.openal.SOFTReopenDevice.alcReopenDeviceSOFT(SOFTReopenDevice.java:60)
    ... 18 more
Spasi commented 2 years ago

Thank you @Berstanio!