Crash on alDeleteSources

Hi, I’m having a problem with Joal. The code below crashes Java when I run it. If I change it, so that the sources are deleted in the same order as they are created then there are no problems, but when I delete the sources in a different order than they were created in, then an Java crashes with the error “java.exe has encountered a problem and needs to close. We are sorry for the inconvenience.”. Is there anything I can do? Since my system is to be dynamic, I need to be able to delete sources at any point in time, and thus not just in the order they were created…


import net.java.games.joal.*;
import net.java.games.joal.util.*;

public class TestSound {
    
    private AL al;
    
    public static void main(String[] args) {
        TestSound se = new TestSound();
    }
    
    public TestSound() {
        try {
            ALut.alutInit();
            al = ALFactory.getAL();
        } catch (OpenALException e) {
            e.printStackTrace();
            System.exit(1);
        }
        al.alGetError();
        
        int[] source0 = new int[1];
        al.alGenSources(1, source0);
        if (al.alGetError() != AL.AL_NO_ERROR) {
            System.err.println("Error generating source0."); System.exit(1);
        }
        
        int[] source1 = new int[1];
        al.alGenSources(1, source1);
        if (al.alGetError() != AL.AL_NO_ERROR) {
            System.err.println("Error generating source1."); System.exit(1);
        }
        
        al.alDeleteSources(1, source1);
        if (al.alGetError() != AL.AL_NO_ERROR) {
            System.err.println("Error destroying source1."); System.exit(1);
        }
        
        al.alDeleteSources(1, source0);
        if (al.alGetError() != AL.AL_NO_ERROR) {
            System.err.println("Error destroying source0."); System.exit(1);
        }
        
        ALut.alutExit();
    }
}

Ah, it also comes with this error information when I remove the System.exit(1) method calls:

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x2CD9D94
Function=alDistanceModel+0x1814
Library=D:\WINDOWS\System32\OpenAL32.dll

Current Java thread:
at net.java.games.joal.ALCImpl.destroyContextNative(Native Method)
at net.java.games.joal.ALCImpl.alcDestroyContext(ALCImpl.java:112)
at net.java.games.joal.util.ALut.alutExit(ALut.java:127)
at TestSound.(TestSound.java:44)
at TestSound.main(TestSound.java:9)

Dynamic libraries:
0x00400000 - 0x00406000 D:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\bin\java.exe
0x77F50000 - 0x77FF7000 D:\WINDOWS\System32\ntdll.dll
0x77E60000 - 0x77F46000 D:\WINDOWS\system32\kernel32.dll
0x77DD0000 - 0x77E5D000 D:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78087000 D:\WINDOWS\system32\RPCRT4.dll
0x77C10000 - 0x77C63000 D:\WINDOWS\system32\MSVCRT.dll
0x08000000 - 0x08136000 D:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\bin\client\jvm.dll
0x77D40000 - 0x77DCC000 D:\WINDOWS\system32\USER32.dll
0x7E090000 - 0x7E0D1000 D:\WINDOWS\system32\GDI32.dll
0x76B40000 - 0x76B6C000 D:\WINDOWS\System32\WINMM.dll
0x10000000 - 0x10007000 D:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\bin\hpi.dll
0x003E0000 - 0x003EE000 D:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\bin\verify.dll
0x008A0000 - 0x008B8000 D:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\bin\java.dll
0x003F0000 - 0x003FD000 D:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\bin\zip.dll
0x02CA0000 - 0x02CAF000 C:\Programming\sound\joal.dll
0x02CD0000 - 0x02DA0000 D:\WINDOWS\System32\OpenAL32.dll
0x771B0000 - 0x772D4000 D:\WINDOWS\system32\ole32.dll
0x7C890000 - 0x7C911000 D:\WINDOWS\System32\CLBCATQ.DLL
0x77120000 - 0x771AB000 D:\WINDOWS\system32\OLEAUT32.dll
0x77050000 - 0x77115000 D:\WINDOWS\System32\COMRes.dll
0x77C00000 - 0x77C07000 D:\WINDOWS\system32\VERSION.dll
0x51080000 - 0x510DD000 D:\WINDOWS\System32\dsound.dll
0x72D20000 - 0x72D29000 D:\WINDOWS\System32\wdmaud.drv
0x72D10000 - 0x72D18000 D:\WINDOWS\System32\msacm32.drv
0x77BE0000 - 0x77BF4000 D:\WINDOWS\System32\MSACM32.dll
0x77BD0000 - 0x77BD7000 D:\WINDOWS\System32\midimap.dll
0x5EF80000 - 0x5EF84000 D:\WINDOWS\System32\KsUser.dll
0x76C90000 - 0x76CB2000 D:\WINDOWS\system32\imagehlp.dll
0x6D510000 - 0x6D58D000 D:\WINDOWS\system32\DBGHELP.dll
0x76BF0000 - 0x76BFB000 D:\WINDOWS\System32\PSAPI.DLL

Heap at VM Abort:
Heap
def new generation total 576K, used 404K [0x10010000, 0x100b0000, 0x104f0000)
eden space 512K, 79% used [0x10010000, 0x10075380, 0x10090000)
from space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)
to space 64K, 0% used [0x100a0000, 0x100a0000, 0x100b0000)
tenured generation total 1408K, used 0K [0x104f0000, 0x10650000, 0x14010000)
the space 1408K, 0% used [0x104f0000, 0x104f0000, 0x104f0200, 0x10650000)
compacting perm gen total 4096K, used 1150K [0x14010000, 0x14410000, 0x18010000)
the space 4096K, 28% used [0x14010000, 0x1412fb30, 0x1412fc00, 0x14410000)

Local Time = Sun Sep 26 01:26:37 2004
Elapsed Time = 0

The exception above was detected in native code outside the VM

Java VM: Java HotSpot™ Client VM (1.4.2-b28 mixed mode)

If you want to investigate the problem not with basis in my minimal example code, but rather with basis in the demo file MultipleSources.java, then you the crash occurs if you replace the line

    al.alGenSources(NUM_SOURCES, sources);

with these lines that create the sources one by one:

    int[] source0 = new int[1];
    int[] source1 = new int[1];
    int[] source2 = new int[1];
    // not the same order as they will be deleted in:
    al.alGenSources(1, source0);
    al.alGenSources(1, source2);
    al.alGenSources(1, source1);
    sources = new int[] {source0[0],source1[0],source2[0]};

Is there anything I can do to be able to dynamically create and delete sources then?

Rune