From 5276af6df152b3dec4ebc9c992aa0517efb45076 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:04:49 +0800 Subject: [PATCH 1/7] port https://github.com/GTNewHorizons/lwjgl3ify/pull/173/files --- src/main/java/org/lwjgl/openal/AL.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index 7bb899320..8b4429a30 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -24,12 +24,12 @@ public static void create() throws LWJGLException { } public static void create(String deviceArguments, int contextFrequency, int contextRefresh, - boolean contextSynchronized) { + boolean contextSynchronized) throws LWJGLException { create(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, true); } public static void create(String deviceArguments, int contextFrequency, int contextRefresh, - boolean contextSynchronized, boolean openDevice) { + boolean contextSynchronized, boolean openDevice) throws LWJGLException { IntBuffer attribs = BufferUtils.createIntBuffer(16); attribs.put(org.lwjgl3.openal.ALC10.ALC_FREQUENCY); @@ -51,6 +51,10 @@ public static void create(String deviceArguments, int contextFrequency, int cont long deviceHandle = org.lwjgl3.openal.ALC10.alcOpenDevice(defaultDevice); + if (deviceHandle == 0) { + throw new LWJGLException("Could not open ALC device"); + } + alcDevice = new ALCdevice(deviceHandle); final ALCCapabilities deviceCaps = org.lwjgl3.openal.ALC.createCapabilities(deviceHandle); From c8ad164035f6eea692d70d901eb9db8686b62b44 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:36:12 +0800 Subject: [PATCH 2/7] Revert "port https://github.com/GTNewHorizons/lwjgl3ify/pull/173/files" This reverts commit 5276af6df152b3dec4ebc9c992aa0517efb45076. --- src/main/java/org/lwjgl/openal/AL.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index 8b4429a30..7bb899320 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -24,12 +24,12 @@ public static void create() throws LWJGLException { } public static void create(String deviceArguments, int contextFrequency, int contextRefresh, - boolean contextSynchronized) throws LWJGLException { + boolean contextSynchronized) { create(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, true); } public static void create(String deviceArguments, int contextFrequency, int contextRefresh, - boolean contextSynchronized, boolean openDevice) throws LWJGLException { + boolean contextSynchronized, boolean openDevice) { IntBuffer attribs = BufferUtils.createIntBuffer(16); attribs.put(org.lwjgl3.openal.ALC10.ALC_FREQUENCY); @@ -51,10 +51,6 @@ public static void create(String deviceArguments, int contextFrequency, int cont long deviceHandle = org.lwjgl3.openal.ALC10.alcOpenDevice(defaultDevice); - if (deviceHandle == 0) { - throw new LWJGLException("Could not open ALC device"); - } - alcDevice = new ALCdevice(deviceHandle); final ALCCapabilities deviceCaps = org.lwjgl3.openal.ALC.createCapabilities(deviceHandle); From a528b4c48d4a5aecb251b0caa2bc784dfcffdb15 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:13:49 +0800 Subject: [PATCH 3/7] destroy the divice --- src/main/java/org/lwjgl/openal/AL.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index 358a53297..eadd9bc3d 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -51,8 +51,6 @@ public static void create(String deviceArguments, int contextFrequency, int cont long deviceHandle = org.lwjgl3.openal.ALC10.alcOpenDevice(defaultDevice); - if (deviceHandle == 0) throw new LWJGLException("Could not open ALC device"); - alcDevice = new ALCdevice(deviceHandle); final ALCCapabilities deviceCaps = org.lwjgl3.openal.ALC.createCapabilities(deviceHandle); @@ -63,6 +61,11 @@ public static void create(String deviceArguments, int contextFrequency, int cont org.lwjgl3.openal.AL.createCapabilities(deviceCaps); created = true; + + if (deviceHandle == 0) { + destroy(); + throw new LWJGLException("Could not open ALC device"); + } } public static boolean isCreated() { From 57667ec5b9d5207fcd17c51b23c66ad63cc76806 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:36:25 +0800 Subject: [PATCH 4/7] Update AL.java --- src/main/java/org/lwjgl/openal/AL.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index eadd9bc3d..ebc73773d 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -51,6 +51,11 @@ public static void create(String deviceArguments, int contextFrequency, int cont long deviceHandle = org.lwjgl3.openal.ALC10.alcOpenDevice(defaultDevice); + if (deviceHandle == 0) { + org.lwjgl3.openal.ALC10.alcCloseDevice(deviceHandle); + throw new LWJGLException("Could not open ALC device"); + } + alcDevice = new ALCdevice(deviceHandle); final ALCCapabilities deviceCaps = org.lwjgl3.openal.ALC.createCapabilities(deviceHandle); @@ -61,11 +66,6 @@ public static void create(String deviceArguments, int contextFrequency, int cont org.lwjgl3.openal.AL.createCapabilities(deviceCaps); created = true; - - if (deviceHandle == 0) { - destroy(); - throw new LWJGLException("Could not open ALC device"); - } } public static boolean isCreated() { From 91468b4d8e241260f75d29c32caad50d21bb652a Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:44:13 +0800 Subject: [PATCH 5/7] destroy only when created --- src/main/java/org/lwjgl/openal/AL.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index ebc73773d..7a5612050 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -73,11 +73,13 @@ public static boolean isCreated() { } public static void destroy() { - org.lwjgl3.openal.ALC10.alcDestroyContext(alcContext.context); - org.lwjgl3.openal.ALC10.alcCloseDevice(alcDevice.device); - alcContext = null; - alcDevice = null; - created = false; + if (created){ + org.lwjgl3.openal.ALC10.alcDestroyContext(alcContext.context); + org.lwjgl3.openal.ALC10.alcCloseDevice(alcDevice.device); + alcContext = null; + alcDevice = null; + created = false; + } } public static org.lwjgl.openal.ALCcontext getContext() { From 62639f9d8b33ba10c63cd9fda5fe059adb664c11 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:46:19 +0800 Subject: [PATCH 6/7] is it needed to alcDestroyContext for 0L? --- src/main/java/org/lwjgl/openal/AL.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index 7a5612050..1acc8fac6 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -51,10 +51,7 @@ public static void create(String deviceArguments, int contextFrequency, int cont long deviceHandle = org.lwjgl3.openal.ALC10.alcOpenDevice(defaultDevice); - if (deviceHandle == 0) { - org.lwjgl3.openal.ALC10.alcCloseDevice(deviceHandle); - throw new LWJGLException("Could not open ALC device"); - } + if (deviceHandle == 0) throw new LWJGLException("Could not open ALC device"); alcDevice = new ALCdevice(deviceHandle); From 616da1b5e5f86dbfa2ed109861513bb1a7cd26a2 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:11:07 +0800 Subject: [PATCH 7/7] check null before close them --- src/main/java/org/lwjgl/openal/AL.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/lwjgl/openal/AL.java b/src/main/java/org/lwjgl/openal/AL.java index 1acc8fac6..6152b7c2b 100644 --- a/src/main/java/org/lwjgl/openal/AL.java +++ b/src/main/java/org/lwjgl/openal/AL.java @@ -70,13 +70,15 @@ public static boolean isCreated() { } public static void destroy() { - if (created){ + if (alcContext != null) { org.lwjgl3.openal.ALC10.alcDestroyContext(alcContext.context); - org.lwjgl3.openal.ALC10.alcCloseDevice(alcDevice.device); alcContext = null; + } + if (alcDevice != null) { + org.lwjgl3.openal.ALC10.alcCloseDevice(alcDevice.device); alcDevice = null; - created = false; } + created = false; } public static org.lwjgl.openal.ALCcontext getContext() {