5

i'm running ubuntu 12.04 off a pendrive. I've installed openAL and alut my main is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <al.h> 
#include <alc.h>

// Buffers hold sound data.
ALuint Buffer;
using namespace std;
string ErrorCheck(ALenum error)
{
    if(error == AL_INVALID_NAME)
    {
        return "Invalid name";
    }
    else if(error == AL_INVALID_ENUM)
    {
        return " Invalid enum ";
    }
    else if(error == AL_INVALID_VALUE)
    {
        return " Invalid value ";
    }
    else if(error == AL_INVALID_OPERATION)
    {
        return " Invalid operation ";
    }
    else if(error == AL_OUT_OF_MEMORY)
    {
        return " Out of memory like! ";
    }

    return " Don't know ";


}

int main(int argc, char **argv)

{
    ALenum error;   

    error = alGetError();
    cout << "\n\tInitial error at start of program - " << ErrorCheck(error);

    error = alGetError();
    cout << "\n\tError persists - " << ErrorCheck(error);

    cout << "\n\tGenerating buffer...";
    alGenBuffers(1, &Buffer);

    error = alGetError();
    if(error != AL_NO_ERROR)
    {
        cout << "\n\tError generating buffer - "<< ErrorCheck(error) << "\n\n";
        return 0;
    }


    return 0;
}

This compiles without error using the line

g++ main.cpp -I/usr/include/AL -lopenal -lalut

But when the program runs, every call to alGetError() returns AL_INVALID_OPERATION I thought that calling alGetError() was meant to reset the the error flag, so where i call it twice at the start, the second one should at least return no error. I am truly stuck!

arp2600
  • 51
  • 1
  • 3
  • Your method doesn't handle `AL_NO_ERROR`. Are there definitely `AL_INVALID_OPERATION` errors being returned? – RJFalconer May 09 '16 at 11:37

2 Answers2

0

The answer to this thread still rings true for your problem. I don't see any creation of an OpenAL context in your code.

http://opensource.creative.com/pipermail/openal/2008-May/011130.html

  • I have the same issue on Windows 7. Though I call `m_pDevice, = alcOpenDevice(NULL);` and `alcCreateContext(m_pDevice,NULL);`. The link above is not available anymore. – 0xC0DEGURU Jan 25 '16 at 18:14
0

I believe I ran into the same problem. alGetError() returns AL_INVALID_OPERATION if a current context is not set. Obviously this is confusing, since it represents an error in the error function itself, not that it actually retrieved an error, which arguably should be a different error code.

The following is taken directly from the OpenAL-Soft source (https://github.com/kcat/openal-soft/blob/master/OpenAL32/alError.cpp):

AL_API ALenum AL_APIENTRY alGetError(void)
START_API_FUNC
{
    ContextRef context{GetContextRef()};
    if(UNLIKELY(!context))
    {
        constexpr ALenum deferror{AL_INVALID_OPERATION};
        WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);
        if(TrapALError)
        {
#ifdef _WIN32
            if(IsDebuggerPresent())
                DebugBreak();
#elif defined(SIGTRAP)
            raise(SIGTRAP);
#endif
        }
        return deferror;
    }

    return context->LastError.exchange(AL_NO_ERROR);
}
END_API_FUNC
stands2reason
  • 672
  • 2
  • 7
  • 18