From d7ad8c66edf570c03662dd601807bf6dcbdf8dd5 Mon Sep 17 00:00:00 2001 From: Yves BOYAdjian Date: Sun, 3 Nov 2024 19:53:43 +0100 Subject: [PATCH] Freeze at startup correction --- application/src/application/MainGLFW.java | 79 ++++++++--------------- retroboss/src/Main.java | 10 +++ 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/application/src/application/MainGLFW.java b/application/src/application/MainGLFW.java index 058bda2..5ecc047 100644 --- a/application/src/application/MainGLFW.java +++ b/application/src/application/MainGLFW.java @@ -290,6 +290,7 @@ protected Object doInBackground() throws Exception { buildPhysics(); loadSavedGame(); SwingUtilities.invokeLater(() -> { + try { startOpenGL(); startViewer(); loadPlanks(); @@ -297,6 +298,15 @@ protected Object doInBackground() throws Exception { setEscapeCallback(); addIdleListeners(); runVisu(); + } catch (Exception e) { + JOptionPane.showMessageDialog(window, e.toString(), "Exception in Bigfoot Hunting", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + System.exit(-1); // Necessary, because of Linux + } catch (Error e) { + JOptionPane.showMessageDialog(window, e.toString(), "Error in Bigfoot Hunting", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + System.exit(-1); // Necessary, because of Linux + } }); } catch (Exception e) { JOptionPane.showMessageDialog(window, e.toString(), "Exception in Bigfoot Hunting", JOptionPane.ERROR_MESSAGE); @@ -1719,56 +1729,7 @@ public static void runVisu() { }); SwingUtilities.invokeLater(() -> { - try { - loop(); - } catch (Exception e) { - viewer.setVisible(false); - JOptionPane.showMessageDialog(window, e.toString(), "Exception in Mount Rainier Island", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); - System.exit(-1); // Necessary, because of Linux - } catch (Error e) { - viewer.setVisible(false); - JOptionPane.showMessageDialog(window, e.toString(), "Error in Mount Rainier Island", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); - System.exit(-1); // Necessary, because of Linux - } -//// Can call "alc" functions at any time -// long device = alcOpenDevice((ByteBuffer)null); -// ALCCapabilities deviceCaps = ALC.createCapabilities(device); -// -// long context = alcCreateContext(device, (IntBuffer)null); -// alcMakeContextCurrent(context); -// AL.createCapabilities(deviceCaps); -//// Can now call "al" functions -// -// IntBuffer buffer = BufferUtils.createIntBuffer(1); -// AL10.alGenBuffers(buffer); -// -// String args = "ressource/" + "AMBSea_Falaise 2 (ID 2572)_LS_16bit.wav"; -// File file = new File(args); -// if (!file.exists()) { -// file = new File("application/" + args); -// } -// URL url = null; -// try { -// url = file.toURL(); -// } catch (MalformedURLException e) { -// e.printStackTrace(); -// } -// -// long time = 0; -// try { -// time = createBufferData(buffer.get(0),url); -// } catch (UnsupportedAudioFileException e) { -// e.printStackTrace(); -// } catch (IOException e) { -// e.printStackTrace(); -// } - - //InputStream seaSound = loadMP3Sound("AMBSea_Falaise 2 (ID 2572)_LS_16bit.mp3"); - - //seaClip = playSound(seaSound,true, 0.0001f); AtomicInteger seaAtomicInteger = new AtomicInteger(); @@ -1789,7 +1750,7 @@ public static void runVisu() { seaRenderer.play(); - seaRenderer.setVolume(0.0f); + seaRenderer.setVolume(0.001f); seaAudioLatch.countDown(); @@ -1844,7 +1805,7 @@ public static void runVisu() { forestRenderer.play(); - forestRenderer.setVolume(0.0f); + forestRenderer.setVolume(0.001f); forestAudioLatch.countDown(); @@ -1908,6 +1869,22 @@ public static void runVisu() { } }); //aliveThread.start(); + SwingUtilities.invokeLater(() -> { + + try { + loop(); + } catch (Exception e) { + viewer.setVisible(false); + JOptionPane.showMessageDialog(window, e.toString(), "Exception in Mount Rainier Island", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + System.exit(-1); // Necessary, because of Linux + } catch (Error e) { + viewer.setVisible(false); + JOptionPane.showMessageDialog(window, e.toString(), "Error in Mount Rainier Island", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + System.exit(-1); // Necessary, because of Linux + } + }); }); } diff --git a/retroboss/src/Main.java b/retroboss/src/Main.java index 6a4d789..0d13e27 100644 --- a/retroboss/src/Main.java +++ b/retroboss/src/Main.java @@ -32,6 +32,7 @@ protected Object doInBackground() throws Exception { MainGLFW.buildPhysics(); MainGLFW.loadSavedGame(); SwingUtilities.invokeLater(() -> { + try { MainGLFW.startOpenGL(); MainGLFW.startViewer(); MainGLFW.loadPlanks(); @@ -39,6 +40,15 @@ protected Object doInBackground() throws Exception { MainGLFW.setEscapeCallback(); MainGLFW.addIdleListeners(); MainGLFW.runVisu(); + } catch (Exception e) { + JOptionPane.showMessageDialog(MainGLFW.window, e.toString(), "Exception in Retro Boss", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + System.exit(-1); // Necessary, because of Linux + } catch (Error e) { + JOptionPane.showMessageDialog(MainGLFW.window, e.toString(), "Error in Retro Boss", JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + System.exit(-1); // Necessary, because of Linux + } }); } catch (Exception e) { JOptionPane.showMessageDialog(MainGLFW.window, e.toString(), "Exception in Retro Boss", JOptionPane.ERROR_MESSAGE);