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(
   at paulscode.sound.libraries.LibraryLWJGLOpenAL.quickPlay(
   at paulscode.sound.SoundSystem.CommandQuickPlay(
   at paulscode.sound.SoundSystem.CommandQueue(

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

SoundSystem shutting down...
   at com.jcraft.jorbis.DspState.init(
   at com.jcraft.jorbis.DspState.synthesis_init(
   at paulscode.sound.codecs.CodecJOrbis.initialize(
   at paulscode.sound.libraries.SourceLWJGLOpenAL.preLoad(
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(
   at paulscode.sound.codecs.CodecJOrbis.readBytes(
   at paulscode.sound.libraries.SourceLWJGLOpenAL.preLoad(

My code:
if(!musicLoaded) {
   soundSystem.backgroundMusic(mus, path, loop);
else {
   soundSystem.backgroundMusic(mus, path, loop);
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
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)
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted