LWJGL Forum

Programming => OpenAL => Topic started by: Cottonwood on December 06, 2010, 22:26:47

Title: [solved] Windows\lwjgl-2.6 sample lesson1 is not working
Post by: Cottonwood on December 06, 2010, 22:26:47
Hi,

I'm new here, so a kind hello to you all.

I tried to run the Windows sample lesson1. The download of the sample had compile errors. It seems to be an older version. So I took the source by adding the code snippets from http://lwjgl.org/documentation_openal_01.php

Even that had an error. I hopefully corrected it. Here is the result:

Code: [Select]
import java.io.IOException;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

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 = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });

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

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

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

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


  /**
   * 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;

    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;
  }                            // <=== <=== <=== <=== <=== <=== <=== <=== <=== <=== this line was inserted by me.

  /**
   * 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.
    char c = ' ';
    while(c != 'q') {
      try {
      c = (char) System.in.read();
      } catch (IOException ioe) {
      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();
  }
}

But when I run that program I get error messages:

Code: [Select]
Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 1
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:258)
at org.lwjgl.openal.AL10.alSource(AL10.java:823)
at Lesson1.loadALData(Lesson1.java:63)
at Lesson1.execute(Lesson1.java:111)
at Lesson1.main(Lesson1.java:97)

What please am I doing wrong?

//Edit:
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 07, 2010, 00:46:09
Wow!  :o

You've uncovered a major bug in LWJGL.  When alSource checks if value (FloatBuffer) is valid, it uses checkBuffer/checkBufferSize, which then checks Buffer.remaining -- which is "limit - position."

In the creation of Buffers in LWJGL (and normal nio's methods I believe also), position is not set to 0!  So Buffer.remaining returns "3 -3" or 0!

This is a major bug that either needs to be fixed in AL10 or in how LWJGL creates buffers!  Reset the position back to 0!

Here's the current workaround for your code:
Code: [Select]
public Lesson1() {
    sourcePos.position(0);
    sourceVel.position(0);
    listenerPos.position(0);
    listenerVel.position(0);
    listenerOri.position(0);
  }

After I added this code, worked like a charm for me!

For other people reading this, the "path" in WaveData might trip you up.  It's actually wanting a resource path.  To specifiy a file path, pass in "new FileInputStream(myFilePath)".  Also, type 'p' to play, 's' to stop, 'q' to quit.

I hope someone that works on LWJGL reads this.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Matthias on December 07, 2010, 01:01:24
FloatBuffer.put(float[]) will advance the position. And the correct way is to use flip() - not position(0).
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 07, 2010, 01:08:21
FloatBuffer.put(float[]) will advance the position. And the correct way is to use flip() - not position(0).

Then flip() it is  :)  but position(0) will also work and without adjusting limit.  rewind() would probably be best, doesn't really matter.

OpenAL tutorial code needs to be changed then or checkBuffer in OpenAL code.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 07, 2010, 05:38:14
Thanks a lot. After inserting those statements it seemed to work. But there was no sound. Doubleclicking the wav showed me that the speakers are working.

So i tried it with the complete path for the wav and got the next error.

Here the actual source:
Code: [Select]
import java.io.IOException;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

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 = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });

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

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

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

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


  /**
   * 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() {

sourcePos.position(0);
sourceVel.position(0);
listenerPos.position(0);
listenerVel.position(0);
listenerOri.position(0);

// Load wav data into a buffer.
    AL10.alGenBuffers(buffer);

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

    WaveData waveFile = WaveData.create("d:\\java\\lwjgl\\project\\lession1\\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;
  }                            // <=== this line was inserted by me.

  /**
   * 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.
    char c = ' ';
    while(c != 'q') {
      try {
      c = (char) System.in.read();
      } catch (IOException ioe) {
      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();
  }
}

And here the new error message:
Code: [Select]
Exception in thread "main" java.lang.NullPointerException
at Lesson1.loadALData(Lesson1.java:57)
at Lesson1.execute(Lesson1.java:117)
at Lesson1.main(Lesson1.java:103)

What is the problem now?
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 07, 2010, 06:53:11
When it runs, type in 'p' to play the sound and then push enter.
Type in 'q' to quit and 's' to stop playing.


To access a file and not a resource path, use this (BUT this is unnecessary in your case, since it ran without exceptions the first time):

FileInputStream fis = null;
try {
  fis = new FileInputStream("d:\\java\\lwjgl\\project\\lession1\\FancyPants.wav");
}
catch(FileIOException ex) {
  System.err("file io error");
  System.exit(0);
}
WaveData waveFile = WaveData.create(fstream);


You probably want to use Slick-Util instead of all of this stuff though.
https://bob.newdawnsoftware.com/repos/slick/trunk/Slick/src/org/newdawn/slick/tests/TestUtils.java
http://slick.cokeandcode.com/javadoc-util/
http://slick.cokeandcode.com/javadoc/org/newdawn/slick/util/package-summary.html
http://slick.cokeandcode.com/wiki/doku.php?id=loading_and_binding_opengl_textures_with_slick-util
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 07, 2010, 11:08:04
Thank you very much.

After removing the path from the filename, playing of the sound works fine. But whe I quit with 'q' I get an error message, that means

jawaw.exe - Error in application.
The statement in "0x03888f8c" points to storage in "0x0397ecd0". Couldn't "read" this storage.
Click "OK" to terminate the program.

There is no difference whether I use 's' = stop before quitting or not. And there is no message in the console window of Eclipse.

Does that also happen when you quit? Or may that be a problem in my XP environment only?
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 07, 2010, 23:30:39
That didn't happen for me; the memory address might have been corrupted from the previously failed attempts.  Restart your computer and see if you have the problem again.  You're using the latest version of LWJGL, right?  Can you please copy and paste the line of code it says the error occurs at?
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 08, 2010, 02:15:37
I updated the wiki with my modified source in an Appendix A section which includes:  the rewind fix, a message about 'p'/etc., and a commented section for how to load a file instead of a resource file.  All I did was add Appendix A; I didn't touch anything else.  I only did this so that if someone asks about this question again I can just redirect them to the working source code.  Feel free to delete/undo it of course; I don't care.  http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source (http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source)
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 08, 2010, 15:20:11
That didn't happen for me; the memory address might have been corrupted from the previously failed attempts.  Restart your computer and see if you have the problem again.
The error happens even after restarting the computer.

You're using the latest version of LWJGL, right?
All the jar files have date/time like this: 2010-10-18 20:44. That may differ from what you have due to different time zones. (see(3))

Can you please copy and paste the line of code it says the error occurs at?
There is no more message than what I showed. I inserted two printouts. Maybe it helps. (see (1))

I updated the wiki with my modified source in an Appendix A section which includes:  the rewind fix, a message about 'p'/etc., and a commented section for how to load a file instead of a resource file.  All I did was add Appendix A; I didn't touch anything else.  I only did this so that if someone asks about this question again I can just redirect them to the working source code.  Feel free to delete/undo it of course; I don't care.  http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source (http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source)
After it happend with my version it also happens with your source code. (see(2))
After rebooting your code works fine. But mine brings the error again.

//Edit: It was just 1 time that your code worked fine after reboot. I tried to find out the statement that caused the error. So i copied statement for statement from your source to mine and tested the result after reboot. As there was no longer any essential difference I took your code again. And since that I get the error with your source as well.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: kappa on December 08, 2010, 15:38:31
I updated the wiki with my modified source in an Appendix A section which includes:  the rewind fix, a message about 'p'/etc., and a commented section for how to load a file instead of a resource file.  All I did was add Appendix A; I didn't touch anything else.  I only did this so that if someone asks about this question again I can just redirect them to the working source code.  Feel free to delete/undo it of course; I don't care.  http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source (http://lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source)

hey great work, that's a pretty old tutorial and any fixes and updates are appreciated. Feel free to update anything on the wiki, good documentation is probably the things that's most lacking atm and any updates are welcome, thx.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 08, 2010, 20:48:36
Cottonwood, sorry, there is nothing more I can do.  Because it worked once and then crashed again and because it works fine on my computer, I can only assume that either you're using native libraries with a memory leak (but then I would get it also, but perhaps, I'd need to run it 100 times on my system) or your main memory is faulty (more likely).  Try running some RAM tests on your computer.  Also, if you can, try running the code on multiple computers (just use a jar with the native libraries in the same directory as the jar), and you can more than likely get people here to also try the code.  If everyone else's works fine but yours, your main memory could be faulty and needs to be replaced.

It's just really odd that this occurs when freeing up the resources.  You could try this:

AL10.alSourceStop(source.get(0));
killALData();

ALSO, your JDK/JRE could be to blame, perhaps damaged or out of date (where a bug hasn't been fixed).  What version of Java are you using?  Make sure that both the JDK and JRE are up-to-date, and reinstall them if it's not too much trouble.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 10, 2010, 19:53:55
I'm rather sure that it is really not a problem with the source code.

My java:
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

I tried it on a different Windows-XP-computer and with an older java version. Same error. (see =1=)

And I tried it on the original PC with "AL10.alSourceStop(source.get(0));". Same error even without playing before quitting. (see =2=)

Did you try it with Windows XP?

Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 11, 2010, 02:10:36
I tried it on Windows XP Home (32-bit), Windows Vista Home (32-bit), and Windows 7 Home (64-bit, already tested on).  Unfortunately, I still did not get the error that you got.

However, on Windows XP Home, it took a lot longer to load and made my hard drive spin/scratch for some reason.  I haven't used it in a while though, so it probably just needs a good defrag and update.  On Windows Vista Home, it also took longer to load, but once loaded, it ran quickly and worked perfectly.

What version of Windows XP Home are you using?  Make sure you have the latest updates installed.  Also, you should really try reinstalling Java and LWJGL.  It looks like your Java is corrupt.  When you re-download it, make sure to check the md5sum.

Sorry.  Will someone else here also try it please?  I could also try it on Linux and Solaris if you want me to.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 11, 2010, 07:12:02
With new software I always do it this way: First I install and test it. When I decide to use it for longer/ever I reload my last image, process my 2bd1 list with all the informations what I did since last image creation such as setting CLASSPATH, install the new software, do all updates, do reorganization of the boot drive and finally I create a new image. So I did it also with my freshly reloaded image that I made directly after installing java. This keeps my computer clean. And if I'm in doubt I check my pc after image creation with Kaspersky.

An so I tried it on a different computer too I dont't believe that my installation is corrupted.

Checking the md5sum with fciv.exe didn't report any checksum error on my boot drive and on my download directory.

My xp versions have both sp3 and all the updates. They come automatically.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 11, 2010, 09:40:52
I want to try it with linux/debian (Knoppix). And I don't understand why java doesn't find lwjgl in java.library.path.

Code: [Select]
root@Microknoppix:/media/sda2/java/lwjgl# java -cp .:res:jar/lwjgl.jar:jar/lwjgl_test.jar:jar/lwjgl_util.jar:jar/lwjgl_fmod3.jar:jar/lwjgl_devil.jar:jar/jinput.jar: -Djava.library.path=jar org.lwjgl.test.WindowCreationTest
The following keys are available:
ESCAPE: Exit test
ARROW Keys: Move window when in non-fullscreen mode
L: List selectable display modes
0-8: Selection of display modes
F: Toggle fullscreen
SHIFT-F: Toggle fullscreen with Display.destroy()/create() cycle
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:82)
at org.lwjgl.Sys.<clinit>(Sys.java:99)
at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
at org.lwjgl.test.WindowCreationTest.initialize(WindowCreationTest.java:82)
at org.lwjgl.test.WindowCreationTest.main(WindowCreationTest.java:286)
root@Microknoppix:/media/sda2/java/lwjgl# ls -l jar
insgesamt 2305
-rwxr-xr-x 1 root root   4189 18. Okt 21:44 AppleJavaExtensions.jar
-rwxr-xr-x 1 root root 214859 18. Okt 21:44 jinput.jar
-rwxr-xr-x 1 root root 880824 18. Okt 21:44 lwjgl-debug.jar
-rwxr-xr-x 1 root root 867028 18. Okt 21:44 lwjgl.jar
-rwxr-xr-x 1 root root 206493 18. Okt 21:44 lwjgl_test.jar
-rwxr-xr-x 1 root root  31423 18. Okt 21:44 lwjgl_util_applet.jar
-rwxr-xr-x 1 root root 127598 18. Okt 21:44 lwjgl_util.jar
-rwxr-xr-x 1 root root   5762 18. Okt 21:44 lzma.jar
root@Microknoppix:/media/sda2/java/lwjgl#

As you can see it is in. What please is the problem?
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 11, 2010, 10:12:28
Wow, it definitely seems like your computer is in tip-top shape.  I wonder if it could be some type of Unicode problem since you're using another language, but that wouldn't make sense.  I really wish that I could recreate the error; this is definitely crazy.   :-\


As for Linux, (1) you're using old files and the old way to test and (2) your java.library.path should be "native/linux" or "./native/linux".  Please read "Testing LWJGL" at the bottom here:
http://lwjgl.org/wiki/index.php?title=Downloading_and_Setting_Up_LWJGL (http://lwjgl.org/wiki/index.php?title=Downloading_and_Setting_Up_LWJGL)
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 11, 2010, 10:54:48
Thank you. Just a joke in between: The test program org.lwjgl.test.WindowCreationTest is working and as I switched to full screen mode my linux window within the sun virtual box became the size of the WindowCreationTest window. Should be the other way around. :-* :'( ::) ??? ;D ;D ;D ;D ;D ;D ;D (upper picture)

No problem. I reboot from linux cd image and renew the linux hdd installation. So I thought. But it remains that small linux window.

No problem. I have a working XP image. That will help always.

Edit: Now again it is as it should be. (lower picture)
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 11, 2010, 13:42:22
Meanwhile I could test Lesson1 under linux/debian (Knoppix). It works fine:

Code: [Select]
root@Microknoppix:/media/sda2/java/lwjgl# java -cp .:res:jar/lwjgl.jar:jar/lwjgl_test.jar:jar/lwjgl_util.jar:jar/lwjgl_fmod3.jar:jar/lwjgl_devil.jar:jar/jinput.jar: -Djava.library.path=native/linux Lesson1
OpenAL Tutorial 1 - Single Static Source
[Menu]
p - Play the sample.
s - Stop the sample.
h - Pause the sample.
q - Quit the program.
Input: p
Input: q
root@Microknoppix:/media/sda2/java/lwjgl#

As you can see here, there is only one "Input: " prompt between p and q.
When I tried it under Windows there were more prompts and I had to enter the q twice.
Can that stick together with the termination error?
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 11, 2010, 14:00:41
As you can see here, there is only one "Input: " prompt between p and q.
When I tried it under Windows there were more prompts and I had to enter the q twice.
Can that stick together with the termination error?

I noticed that problem on my Windows machine, so I fixed it (very) recently on the tutorial, so I don't think that's the problem, but could have been.  The other way I was doing input shouldn't have caused that crash, as it didn't on my machine.

One thing you could do is try and see if you can catch the exception, but it looks like you can't.  Worth a shot anyway.  Add this code:

Code: [Select]
public static void main(String[] args) {
  try {
    new Lesson1().execute();
  }
  catch(Exception ex) {
    ex.printStackTrace();
  }
}
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 11, 2010, 14:57:27
Sorry. There is no difference.

//Edit:
I noticed that problem on my Windows machine, so I fixed it (very) recently on the tutorial, so I don't think that's the problem, but could have been.  The other way I was doing input shouldn't have caused that crash, as it didn't on my machine.
You're right. The new version didn't touch the problem.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 11, 2010, 18:56:20
 :-\  Sorry, there's got to be a problem with this Windows machine; it worked on Linux, right?  Search google for "javaw fehler in anwendung" or "javaw application error."  It could be your registry.
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 11, 2010, 22:08:22
Yes, it worked on Linux. But that was what I expected. It has a totally different native code and the error happens within the native code.
I googled for "javaw application error" and found out that that doesn't match my problem.

But I found something else. Someone wrote that it could work with msjava. Are you using Oracle Java too?
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: jediTofu on December 11, 2010, 23:22:38
Yes, I'm using Oracle Java.

Have you tried a Nightly Build (https://www.newdawnsoftware.com/hudson/view/LWJGL/job/LWJGL/) or an Older Release (http://sourceforge.net/projects/java-game-lib/files/Official%20Releases/)?  If it does not crash in 2.5 and it is in fact a native code problem, we'd at least know where to look.  You could also try running Windows in safe mode; worth a shot.  Wish I was more help  :-\
Title: Re: Windows\lwjgl-2.6 sample lession1 is not working
Post by: Cottonwood on December 12, 2010, 16:51:34
Last night I did a complete check with Kaspersky 11. No problems found.

Today I first tried the Nightly Build as well as the 1.5. Same problem. :(

Then I wanted to try it in safe mode. And Windows began joking with me. My XP was no longer activated. Something like "3 days left for activation - since windows was first activated on this computer, the hardware on the computer has changed significantly. Due to these changes, windows must be reactivated within 3 days-"

And Eclipse coundn't find the OpenAL library:
Code: [Select]
org.lwjgl.LWJGLException: Could not locate OpenAL library.
at org.lwjgl.openal.AL.create(AL.java:153)
at org.lwjgl.openal.AL.create(AL.java:104)
at org.lwjgl.openal.AL.create(AL.java:203)
at Lesson1.execute(Lesson1.java:117)
at Lesson1.main(Lesson1.java:111)

To show you that there is no difference between safe and regular mode I repeated it with a cmd window. This was with a boot in safe mode:
Code: [Select]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Dokumente und Einstellungen\Admin>d:

D:\>cd java

D:\java>cd lwjgl

D:\java\lwjgl>cd project

D:\java\lwjgl\project>cd lesson1

D:\java\lwjgl\project\lesson1>set Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS
\System32\Wbem;C:\Programme\ATI Technologies\ATI.ACE\Core-Static;C:\Programme\Ja
va\jdk1.6.0_22\bin;d:\java\lwjgl\jar;d:\java\lwjgl\native\windows

D:\java\lwjgl\project\lesson1>java Lesson1
org.lwjgl.LWJGLException: Could not locate OpenAL library.
        at org.lwjgl.openal.AL.create(AL.java:153)
        at org.lwjgl.openal.AL.create(AL.java:104)
        at org.lwjgl.openal.AL.create(AL.java:203)
        at Lesson1.execute(Lesson1.java:117)
        at Lesson1.main(Lesson1.java:111)

D:\java\lwjgl\project\lesson1>set
ALLUSERSPROFILE=C:\Dokumente und Einstellungen\All Users
APPDATA=C:\Dokumente und Einstellungen\Admin\Anwendungsdaten
CLASSPATH=.;.;C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1\JMF21~1.1E\lib\jm
f.jar;C:\PROGRA~1\JMF21~1.1E\lib;D:\java\lwjgl\jar\AppleJavaExtensions.jar;D:\ja
va\lwjgl\jar\jinput.jar;D:\java\lwjgl\jar\lwjgl-debug.jar;D:\java\lwjgl\jar\lwjg
l.jar;D:\java\lwjgl\jar\lwjgl_test.jar;D:\java\lwjgl\jar\lwjgl_util.jar;D:\java\
lwjgl\jar\lwjgl_util_applet.jar;D:\java\lwjgl\jar\lzma.jar;
CLIENTNAME=Console
CommonProgramFiles=C:\Programme\Gemeinsame Dateien
COMPUTERNAME=BRYCECANYON
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Dokumente und Einstellungen\Admin
LOGONSERVER=\\BRYCECANYON
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\ATI Te
chnologies\ATI.ACE\Core-Static;C:\Programme\Java\jdk1.6.0_22\bin;d:\java\lwjgl\j
ar;d:\java\lwjgl\native\windows
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 104 Stepping 2, AuthenticAMD
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=6802
ProgramFiles=C:\Programme
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOKUME~1\Admin\LOKALE~1\Temp
TMP=C:\DOKUME~1\Admin\LOKALE~1\Temp
USERDOMAIN=BRYCECANYON
USERNAME=Admin
USERPROFILE=C:\Dokumente und Einstellungen\Admin
VBOX_INSTALL_PATH=C:\Programme\Oracle\VirtualBox\
windir=C:\WINDOWS
ZKA_SIG_HOME=C:\Programme\REINER SCT\cyberJack

D:\java\lwjgl\project\lesson1>
And here with regular boot:
Code: [Select]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Dokumente und Einstellungen\Admin>D:

D:\>cd \java\lwjgl\project\lesson1

D:\java\lwjgl\project\lesson1>set Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS
\System32\Wbem;C:\Programme\ATI Technologies\ATI.ACE\Core-Static;C:\Programme\Ja
va\jdk1.6.0_22\bin;d:\java\lwjgl\jar;d:\java\lwjgl\native\windows

D:\java\lwjgl\project\lesson1>
D:\java\lwjgl\project\lesson1>java Lesson1
OpenAL Tutorial 1 - Single Static Source
[Menu]
p - Play the sample.
s - Stop the sample.
h - Pause the sample.
q - Quit the program.
Input: q   <=== at this moment the window with the error message appeared.

D:\java\lwjgl\project\lesson1>set
ALLUSERSPROFILE=C:\Dokumente und Einstellungen\All Users
APPDATA=C:\Dokumente und Einstellungen\Admin\Anwendungsdaten
CLASSPATH=.;.;C:\PROGRA~1\JMF21~1.1E\lib\sound.jar;C:\PROGRA~1\JMF21~1.1E\lib\jm
f.jar;C:\PROGRA~1\JMF21~1.1E\lib;D:\java\lwjgl\jar\AppleJavaExtensions.jar;D:\ja
va\lwjgl\jar\jinput.jar;D:\java\lwjgl\jar\lwjgl-debug.jar;D:\java\lwjgl\jar\lwjg
l.jar;D:\java\lwjgl\jar\lwjgl_test.jar;D:\java\lwjgl\jar\lwjgl_util.jar;D:\java\
lwjgl\jar\lwjgl_util_applet.jar;D:\java\lwjgl\jar\lzma.jar;
CLIENTNAME=Console
CommonProgramFiles=C:\Programme\Gemeinsame Dateien
COMPUTERNAME=BRYCECANYON
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Dokumente und Einstellungen\Admin
LOGONSERVER=\\BRYCECANYON
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\ATI Te
chnologies\ATI.ACE\Core-Static;C:\Programme\Java\jdk1.6.0_22\bin;d:\java\lwjgl\j
ar;d:\java\lwjgl\native\windows
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 104 Stepping 2, AuthenticAMD
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=6802
ProgramFiles=C:\Programme
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOKUME~1\Admin\LOKALE~1\Temp
TMP=C:\DOKUME~1\Admin\LOKALE~1\Temp
USERDOMAIN=BRYCECANYON
USERNAME=Admin
USERPROFILE=C:\Dokumente und Einstellungen\Admin
VBOX_INSTALL_PATH=C:\Programme\Oracle\VirtualBox\
windir=C:\WINDOWS
ZKA_SIG_HOME=C:\Programme\REINER SCT\cyberJack

D:\java\lwjgl\project\lesson1>

There is absolutely no difference in the result of the set commands.

Do you have an idea what's to do to run it in safe boot mode?
Title: Re: Windows\lwjgl-2.6 sample lesson1 is not working
Post by: Cottonwood on December 13, 2010, 17:31:38
Now I reduced the code to these statements:
Code: [Select]
import org.lwjgl.LWJGLException;
import org.lwjgl.openal.AL;
 
public class Lesson2 {
    public static void main(String[] args) {
        // Initialize OpenAL
        try{
            AL.create();
        } catch (LWJGLException le) {
            le.printStackTrace();
            return;
        }
    System.out.println("Program terminates.");
    }
}
Even now the error happens. Any idea?
Title: Re: Windows\lwjgl-2.6 sample lesson1 is not working
Post by: Cottonwood on December 13, 2010, 18:21:18
I inserted one more statement at the end of the code: "    AL.destroy();". Now it works.
I found it here: http://lwjgl.org/javadoc/org/lwjgl/openal/AL.html

Can anybody change the sample within the tutorial? Here's the working code:
Code: [Select]
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();
  }
}

Many thanks to jediTofu.
Title: Re: [solved] Windows\lwjgl-2.6 sample lesson1 is not working
Post by: jediTofu on December 13, 2010, 19:57:00
Wow, duh, I feel dumb.  I updated the source code on the 1st tutorial.  At least that one is good now.

It's still odd that it happened on your systems and not mine.