Delphi

OpenAL

Tutorials

Lesson #5 (error checking)

In the previous lessons we assumed that nothing goes wrong. However you cannot be sure of that. Therefore OpenAL has a command to check on errors: alGetError .

After some OpenAL commands you can call alGetError to see if an error has occurred. Unfortunately not all OpenAL commands work together with alGetError. But there only a few places in your program where you would like to check on errors:

  • after creating buffers
  • after deleting buffers
  • after assigning data to a buffer
  • after creating sources
  • after deleting sources

If no error occurred alGetError will return AL_NO_ERROR. This means that your program can go on. If it does not return AL_NO_ERROR you can go see if it is AL_OUT_OF_MEMORY. Then the requested operation resulted in OpenAL running out of memory. There are more return values possible but if these occurr you have made a programming mistake.

The idea is that if the creating of a buffer went wrong you should not use that buffer. Or you could delete some unused buffers and then try again to create a buffer.

Take a look on the example below on how the above is implemented in the example from the first lesson. Try to find the programming error in the example that prevents the example from running properly.

Next implement the error checking for the destroy event to find out what we were doing wrong there in the previous lessons.

Do not forget to use the error checking you normaly would use in your programs like: does the file exist that the program has to load.

In the previous lessons we assumed that nothing goes wrong. However you cannot be sure of that. Therefore OpenAL has a command to check on errors: alGetError .

After some OpenAL commands you can call alGetError to see if an error has occurred. Unfortunately not all OpenAL commands work together with alGetError. But there only a few places in your program where you would like to check on errors:

  • after creating buffers
  • after deleting buffers
  • after assigning data to a buffer
  • after creating sources
  • after deleting sources

If no error occurred alGetError will return AL_NO_ERROR. This means that your program can go on. If it does not return AL_NO_ERROR you can go see if it is AL_OUT_OF_MEMORY. Then the requested operation resulted in OpenAL running out of memory. There are more return values possible but if these occurr you have made a programming mistake.

The idea is that if the creating of a buffer went wrong you should not use that buffer. Or you could delete some unused buffers and then try again to create a buffer.

Take a look on the example below on how the above is implemented in the example from the first lesson. Try to find the programming error in the example that prevents the example from running properly.

Next implement the error checking for the destroy event to find out what we were doing wrong there in the previous lessons.

Do not forget to use the error checking you normaly would use in your programs like: does the file exist that the program has to load.