Author Topic: Sound System problems with cleanup and backgroundMusic  (Read 3708 times)

Offline FabianLC

  • bit
  • Posts: 1
    • View Profile
Sound System problems with cleanup and backgroundMusic
« on: November 23, 2017, 08:58:44 AM »
I've been trying to prevent the Sound System from "crashing", but I haven't succeeded yet, I'm using the LWJGL library and the code does fails in two situations, when I play background music and during a cleanup. Here's what the console prints.

Exception in thread "Thread-11" java.lang.NullPointerException
   at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:259)
   at paulscode.sound.libraries.SourceLWJGLOpenAL.play(SourceLWJGLOpenAL.java:616)
   at paulscode.sound.Library.play(Library.java:706)
   at paulscode.sound.libraries.LibraryLWJGLOpenAL.quickPlay(LibraryLWJGLOpenAL.java:795)
   at paulscode.sound.SoundSystem.CommandQuickPlay(SoundSystem.java:1866)
   at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2438)
   at paulscode.sound.CommandThread.run(CommandThread.java:121)

and this happens during cleanup and makes my game freeze for a while

SoundSystem shutting down...
java.lang.NullPointerException
   at com.jcraft.jorbis.DspState.init(DspState.java:178)
   at com.jcraft.jorbis.DspState.synthesis_init(DspState.java:216)
   at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:315)
   at paulscode.sound.libraries.SourceLWJGLOpenAL.preLoad(SourceLWJGLOpenAL.java:687)
   at paulscode.sound.Source.stream(Source.java:928)
   at paulscode.sound.StreamThread.run(StreamThread.java:129)
Error in class 'LibraryLWJGLOpenAL'
    Stream thread did not die!
Ignoring errors... continuing clean-up.
    Author: Paul Lamb,

I've also been wondering if it's normal to have that many threads, I've gotten errors up to thread 22.

Exception in thread "Thread-22" java.lang.NullPointerException
   at com.jcraft.jogg.StreamState.packetout(StreamState.java:186)
   at paulscode.sound.codecs.CodecJOrbis.readBytes(CodecJOrbis.java:575)
   at paulscode.sound.codecs.CodecJOrbis.read(CodecJOrbis.java:354)
   at paulscode.sound.libraries.SourceLWJGLOpenAL.preLoad(SourceLWJGLOpenAL.java:691)
   at paulscode.sound.Source.stream(Source.java:928)
   at paulscode.sound.StreamThread.run(StreamThread.java:129)

My code:
if(!musicLoaded) {
   soundSystem.backgroundMusic(mus, path, loop);
   //soundSystem.play(mus);
   musicLoaded=true;
}
else {
   soundSystem.stop(mus);
   soundSystem.removeSource(mus);
   soundSystem.backgroundMusic(mus, path, loop);
   //soundSystem.play(mus);
}
mus is just a string I made to avoid writing "";
I call cleanup() whenever I change the game's state or level, because the memory usage keeps going up, and even after calling cleanup() it still goes up.
« Last Edit: November 23, 2017, 09:02:58 AM by FabianLC »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Sound System problems with cleanup and backgroundMusic
« Reply #1 on: November 27, 2017, 09:30:23 AM »
SoundSystem should only create two new threads.  One thread is for handling streaming sources (it feeds data into the streams, and handles transitions) and the other thread is for processing commands synchronously.  I am aware of a race condition between the command thread and streaming thread, which CreativeMD reported.  Since there is mention of streams in your crash log, it could be related to this defect.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted