1////////////////////////////////////////////////////////////
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2020 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
23////////////////////////////////////////////////////////////
24
25////////////////////////////////////////////////////////////
26// Headers
27////////////////////////////////////////////////////////////
28#include <SFML/Audio/ALCheck.hpp>
29#include <SFML/System/Err.hpp>
30#include <string>
31
32
33namespace sf
34{
35namespace priv
36{
37////////////////////////////////////////////////////////////
38void alCheckError(const char* file, unsigned int line, const char* expression)
39{
40 // Get the last error
41 ALenum errorCode = alGetError();
42
43 if (errorCode != AL_NO_ERROR)
44 {
45 std::string fileString = file;
46 std::string error = "Unknown error";
47 std::string description = "No description";
48
49 // Decode the error code
50 switch (errorCode)
51 {
52 case AL_INVALID_NAME:
53 {
54 error = "AL_INVALID_NAME";
55 description = "A bad name (ID) has been specified.";
56 break;
57 }
58
59 case AL_INVALID_ENUM:
60 {
61 error = "AL_INVALID_ENUM";
62 description = "An unacceptable value has been specified for an enumerated argument.";
63 break;
64 }
65
66 case AL_INVALID_VALUE:
67 {
68 error = "AL_INVALID_VALUE";
69 description = "A numeric argument is out of range.";
70 break;
71 }
72
73 case AL_INVALID_OPERATION:
74 {
75 error = "AL_INVALID_OPERATION";
76 description = "The specified operation is not allowed in the current state.";
77 break;
78 }
79
80 case AL_OUT_OF_MEMORY:
81 {
82 error = "AL_OUT_OF_MEMORY";
83 description = "There is not enough memory left to execute the command.";
84 break;
85 }
86 }
87
88 // Log the error
89 err() << "An internal OpenAL call failed in "
90 << fileString.substr(fileString.find_last_of("\\/") + 1) << "(" << line << ")."
91 << "\nExpression:\n " << expression
92 << "\nError description:\n " << error << "\n " << description << "\n"
93 << std::endl;
94 }
95}
96
97} // namespace priv
98
99} // namespace sf
100