Audio/OpenALDevice: Improve error when buffer/source creation fails
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Audio/OpenALBuffer.hpp>
|
||||
#include <Nazara/Audio/OpenALLibrary.hpp>
|
||||
#include <Nazara/Audio/OpenALSource.hpp>
|
||||
#include <Nazara/Audio/OpenALUtils.hpp>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Audio/Debug.hpp>
|
||||
@@ -69,11 +70,16 @@ namespace Nz
|
||||
{
|
||||
MakeContextCurrent();
|
||||
|
||||
m_library.alGetError(); // Clear error flags
|
||||
|
||||
ALuint bufferId = 0;
|
||||
m_library.alGenBuffers(1, &bufferId);
|
||||
|
||||
if (bufferId == 0)
|
||||
if (ALenum lastError = m_library.alGetError(); lastError != AL_NO_ERROR)
|
||||
{
|
||||
NazaraErrorFmt("failed to create OpenAL buffer: {0}", TranslateOpenALError(lastError));
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::make_shared<OpenALBuffer>(shared_from_this(), m_library, bufferId);
|
||||
}
|
||||
@@ -82,11 +88,16 @@ namespace Nz
|
||||
{
|
||||
MakeContextCurrent();
|
||||
|
||||
m_library.alGetError(); // Clear error flags
|
||||
|
||||
ALuint sourceId = 0;
|
||||
m_library.alGenSources(1, &sourceId);
|
||||
|
||||
if (sourceId == 0)
|
||||
if (ALenum lastError = m_library.alGetError(); lastError != AL_NO_ERROR)
|
||||
{
|
||||
NazaraErrorFmt("failed to create OpenAL source: {0}", TranslateOpenALError(lastError));
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::make_shared<OpenALSource>(shared_from_this(), m_library, sourceId);
|
||||
}
|
||||
|
||||
40
src/Nazara/Audio/OpenALUtils.cpp
Normal file
40
src/Nazara/Audio/OpenALUtils.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Audio module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Audio/OpenALUtils.hpp>
|
||||
#include <Nazara/Core/Format.hpp>
|
||||
#include <Nazara/Audio/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
std::string TranslateOpenALError(ALenum code)
|
||||
{
|
||||
// From https://www.openal.org/documentation/OpenAL_Programmers_Guide.pdf
|
||||
switch (code)
|
||||
{
|
||||
case AL_NO_ERROR:
|
||||
return "No error";
|
||||
|
||||
case AL_INVALID_NAME:
|
||||
return "A bad name (ID) was passed to an OpenAL function";
|
||||
|
||||
case AL_INVALID_ENUM:
|
||||
return "An invalid enum value was passed to an OpenAL function";
|
||||
|
||||
case AL_INVALID_VALUE:
|
||||
return "An invalid value was passed to an OpenAL function";
|
||||
|
||||
case AL_INVALID_OPERATION:
|
||||
return "The requested operation is not valid";
|
||||
|
||||
case AL_OUT_OF_MEMORY:
|
||||
return "The requested operation resulted in OpenAL running out of memory";
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Format("Unknown OpenAL error ({0:#x})", code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user