Hello Guest

Memory could not be read ERROR MESSAGE

  • 2 Replies
  • 10526 Views
Memory could not be read ERROR MESSAGE
« on: February 22, 2011, 12:06:12 »
Help!

I am new to OpenAL and am trying to build a blank 3d environment with only a number of 3d point sounds. I then want to record how players navigate through this sound field. So to start with i thought i would begin with a simple Lesson1 using LWJGL to understand sound. Code is at the bottom. I have 2 issues. Firstly the following kernel pops up when i try to run it:-

The instruction at "0x0c42c5b5" referenced memory at "0x0c7c4190". The memory could not be "read". Click on OK to terminate program.

I have tried all the tips at http://www.java.com/en/download/help/ikernel.xml to fix it but no luck.

Secondly, this error message appears:-

run:
Exception in thread "main" java.lang.NullPointerException
at Lesson1.loadALData(Lesson1.java:65)
at Lesson1.execute(Lesson1.java:125)
at Lesson1.main(Lesson1.java:111)
Java Result: -1073741819


Here is the code i am using:-

import java.io.FileNotFoundException;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Scanner;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
import org.lwjgl.util.WaveData;

public class Lesson1 {
/** Buffers hold sound data. */
IntBuffer buffer = BufferUtils.createIntBuffer(1);

/** Sources are points emitting sound. */
IntBuffer source = BufferUtils.createIntBuffer(1);

/** Position of the source sound. */
FloatBuffer sourcePos = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }).rewind();

/** Velocity of the source sound. */
FloatBuffer sourceVel = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }).rewind();

/** Position of the listener. */
FloatBuffer listenerPos = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }).rewind();

/** Velocity of the listener. */
FloatBuffer listenerVel = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }).rewind();

/** Orientation of the listener. (first 3 elements are "at", second 3 are "up") */
FloatBuffer listenerOri = (FloatBuffer)BufferUtils.createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }).rewind();

/**
* boolean LoadALData()
*
* This function will load our sample data from the disk using the Alut
* utility and send the data into OpenAL as a buffer. A source is then
* also created to play that buffer.
*/
int loadALData() {
// Load wav data into a buffer.
AL10.alGenBuffers(buffer);

if(AL10.alGetError() != AL10.AL_NO_ERROR)
return AL10.AL_FALSE;

//Loads the wave file from your file system
/*java.io.FileInputStream fin = null;
try {
fin = new java.io.FileInputStream("FancyPants.wav");
} catch (java.io.FileNotFoundException ex) {
ex.printStackTrace();
return AL10.AL_FALSE;
}
WaveData waveFile = WaveData.create(fin);
try {
fin.close();
} catch (java.io.IOException ex) {
}*/

//Loads the wave file from this class's package in your classpath
WaveData waveFile = WaveData.create("FancyPants.wav");

AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
waveFile.dispose();

// Bind the buffer with the source.
AL10.alGenSources(source);

if (AL10.alGetError() != AL10.AL_NO_ERROR)
return AL10.AL_FALSE;

AL10.alSourcei(source.get(0), AL10.AL_BUFFER, buffer.get(0) );
AL10.alSourcef(source.get(0), AL10.AL_PITCH, 1.0f );
AL10.alSourcef(source.get(0), AL10.AL_GAIN, 1.0f );
AL10.alSource (source.get(0), AL10.AL_POSITION, sourcePos );
AL10.alSource (source.get(0), AL10.AL_VELOCITY, sourceVel );

// Do another error check and return.
if (AL10.alGetError() == AL10.AL_NO_ERROR)
return AL10.AL_TRUE;

return AL10.AL_FALSE;
}

/**
* void setListenerValues()
*
* We already defined certain values for the Listener, but we need
* to tell OpenAL to use that data. This function does just that.
*/
void setListenerValues() {
AL10.alListener(AL10.AL_POSITION, listenerPos);
AL10.alListener(AL10.AL_VELOCITY, listenerVel);
AL10.alListener(AL10.AL_ORIENTATION, listenerOri);
}

/**
* void killALData()
*
* We have allocated memory for our buffers and sources which needs
* to be returned to the system. This function frees that memory.
*/
void killALData() {
AL10.alDeleteSources(source);
AL10.alDeleteBuffers(buffer);
}

public static void main(String[] args) {
new Lesson1().execute();
}

public void execute() {
// Initialize OpenAL and clear the error bit.
try{
AL.create();
} catch (LWJGLException le) {
le.printStackTrace();
return;
}
AL10.alGetError();

// Load the wav data.
if(loadALData() == AL10.AL_FALSE) {
System.out.println("Error loading data.");
return;
}

setListenerValues();

// Loop.
System.out.println("OpenAL Tutorial 1 - Single Static Source");
System.out.println("[Menu]");
System.out.println("p - Play the sample.");
System.out.println("s - Stop the sample.");
System.out.println("h - Pause the sample.");
System.out.println("q - Quit the program.");
char c = ' ';
Scanner stdin = new Scanner(System.in);
while(c != 'q') {
try {
System.out.print("Input: ");
c = (char)stdin.nextLine().charAt(0);
} catch (Exception ex) {
c = 'q';
}

switch(c) {
// Pressing 'p' will begin playing the sample.
case 'p': AL10.alSourcePlay(source.get(0)); break;

// Pressing 's' will stop the sample from playing.
case's': AL10.alSourceStop(source.get(0)); break;

// Pressing 'h' will pause the sample.
case 'h': AL10.alSourcePause(source.get(0)); break;
};
}
killALData();
AL.destroy();
}
}

------


If you could please help me, that would be great. Thanks



Re: Memory could not be read ERROR MESSAGE
« Reply #1 on: March 02, 2011, 18:29:06 »
The null reference exception looks like it failed to find the .wav file to open (I'm guessing you didn't actually try debug it?  :-\).
As for the memory error, put a breakpoint in your code and try figure out which line of code is throwing that error. That would help us tell you what might be wrong.

Also, more information would help (OS, Java version, etc.)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: Memory could not be read ERROR MESSAGE
« Reply #2 on: March 02, 2011, 18:35:38 »
I have tried debugging the file but it just throws up the same error message
I am using Netbeans JAVA

Thanks