Programming => OpenAL => Topic started by: silent_ptr on August 03, 2020, 14:49:36

Title: Loading and playing audio causes access violation
Post by: silent_ptr on August 03, 2020, 14:49:36
I'm trying to create a simple sound demo for my game engine using OpenAL. I don't need any special 3D sound effects at the moment, I'm just trying to play a normal music mp3. This is the code I use to initialise OpenAL and load the sound file:
Code: [Select]
device = ALC11.alcOpenDevice((ByteBuffer)null);

if (device == 0)
return false;

capabilities = ALC.createCapabilities(device);

if (capabilities == null)
return false;

context = ALC11.alcCreateContext(device, (IntBuffer)null);
buffer = AL11.alGenBuffers();

int sampleRate;

try (MemoryStack stack = MemoryStack.stackPush())
IntBuffer channelsPtr = stack.mallocInt(1);
IntBuffer sampleRatePtr = stack.mallocInt(1);
PointerBuffer dataPtr = stack.mallocPointer(1);
STBVorbis.stb_vorbis_decode_filename("test.mp3", channelsPtr, sampleRatePtr, dataPtr);
sampleRate = sampleRatePtr.get(0);
AL11.alBufferData(buffer, AL11.AL_FORMAT_STEREO16, dataPtr.getByteBuffer(dataPtr.sizeof()), sampleRate);

source = AL11.alGenSources();
AL11.alSourcei(source, AL11.AL_BUFFER, buffer);
return true;
When this code runs I get an access violation and my program shuts down. It does not give more specific information than this:
# A fatal error has been detected by the Java Runtime Environment:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffbbf83dec8, pid=16576, tid=7492
# JRE version: Java(TM) SE Runtime Environment (14.0.1+7) (build 14.0.1+7)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (14.0.1+7, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C  [OpenAL.dll+0x4dec8]
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
# An error report file with more information is saved as:
# C:\Users\logan\Documents\Phantasm Entertainment\Face Engine\Face Engine Eclipse Workspace\Face Engine Test\hs_err_pid16576.log
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

Am I doing something wrong with my pointers?