mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Improved diagnostic output for glCheck and alCheck macros
Changes: * In addition to source file and line, the expression itself is output * For better readability, the log is split across multiple lines * alCheck() doesn't unnecessarily construct std::string when there is no error * Unused #include directives are removed
This commit is contained in:
parent
0bcd7d39f2
commit
e5f98a6575
@ -26,8 +26,8 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -35,14 +35,16 @@ namespace sf
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void alCheckError(const std::string& file, unsigned int line)
|
||||
void alCheckError(const char* file, unsigned int line, const char* expression)
|
||||
{
|
||||
// Get the last error
|
||||
ALenum errorCode = alGetError();
|
||||
|
||||
if (errorCode != AL_NO_ERROR)
|
||||
{
|
||||
std::string error, description;
|
||||
std::string fileString = file;
|
||||
std::string error = "Unknown error";
|
||||
std::string description = "No description";
|
||||
|
||||
// Decode the error code
|
||||
switch (errorCode)
|
||||
@ -50,43 +52,44 @@ void alCheckError(const std::string& file, unsigned int line)
|
||||
case AL_INVALID_NAME:
|
||||
{
|
||||
error = "AL_INVALID_NAME";
|
||||
description = "an unacceptable name has been specified";
|
||||
description = "A bad name (ID) has been specified.";
|
||||
break;
|
||||
}
|
||||
|
||||
case AL_INVALID_ENUM:
|
||||
{
|
||||
error = "AL_INVALID_ENUM";
|
||||
description = "an unacceptable value has been specified for an enumerated argument";
|
||||
description = "An unacceptable value has been specified for an enumerated argument.";
|
||||
break;
|
||||
}
|
||||
|
||||
case AL_INVALID_VALUE:
|
||||
{
|
||||
error = "AL_INVALID_VALUE";
|
||||
description = "a numeric argument is out of range";
|
||||
description = "A numeric argument is out of range.";
|
||||
break;
|
||||
}
|
||||
|
||||
case AL_INVALID_OPERATION:
|
||||
{
|
||||
error = "AL_INVALID_OPERATION";
|
||||
description = "the specified operation is not allowed in the current state";
|
||||
description = "The specified operation is not allowed in the current state.";
|
||||
break;
|
||||
}
|
||||
|
||||
case AL_OUT_OF_MEMORY:
|
||||
{
|
||||
error = "AL_OUT_OF_MEMORY";
|
||||
description = "there is not enough memory left to execute the command";
|
||||
description = "There is not enough memory left to execute the command.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Log the error
|
||||
err() << "An internal OpenAL call failed in "
|
||||
<< file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< fileString.substr(fileString.find_last_of("\\/") + 1) << "(" << line << ")."
|
||||
<< "\nExpression:\n " << expression
|
||||
<< "\nError description:\n " << error << "\n " << description << "\n"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,6 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
#include <OpenAl/al.h>
|
||||
#include <OpenAl/alc.h>
|
||||
@ -45,7 +43,7 @@ namespace sf
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenAL API calls
|
||||
/// Let's define a macro to quickly check every OpenAL API call
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
@ -56,7 +54,7 @@ namespace priv
|
||||
#else
|
||||
|
||||
// Else, we don't add any overhead
|
||||
#define alCheck(Func) (Func)
|
||||
#define alCheck(expr) (expr)
|
||||
|
||||
#endif
|
||||
|
||||
@ -66,9 +64,10 @@ namespace priv
|
||||
///
|
||||
/// \param file Source file where the call is located
|
||||
/// \param line Line number of the source file where the call is located
|
||||
/// \param expression The evaluated expression as a string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void alCheckError(const std::string& file, unsigned int line);
|
||||
void alCheckError(const char* file, unsigned int line, const char* expression);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -34,16 +35,16 @@ namespace sf
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void glCheckError(const char* file, unsigned int line)
|
||||
void glCheckError(const char* file, unsigned int line, const char* expression)
|
||||
{
|
||||
// Get the last error
|
||||
GLenum errorCode = glGetError();
|
||||
|
||||
if (errorCode != GL_NO_ERROR)
|
||||
{
|
||||
std::string fileString(file);
|
||||
std::string error = "unknown error";
|
||||
std::string description = "no description";
|
||||
std::string fileString = file;
|
||||
std::string error = "Unknown error";
|
||||
std::string description = "No description";
|
||||
|
||||
// Decode the error code
|
||||
switch (errorCode)
|
||||
@ -51,57 +52,58 @@ void glCheckError(const char* file, unsigned int line)
|
||||
case GL_INVALID_ENUM:
|
||||
{
|
||||
error = "GL_INVALID_ENUM";
|
||||
description = "an unacceptable value has been specified for an enumerated argument";
|
||||
description = "An unacceptable value has been specified for an enumerated argument.";
|
||||
break;
|
||||
}
|
||||
|
||||
case GL_INVALID_VALUE:
|
||||
{
|
||||
error = "GL_INVALID_VALUE";
|
||||
description = "a numeric argument is out of range";
|
||||
description = "A numeric argument is out of range.";
|
||||
break;
|
||||
}
|
||||
|
||||
case GL_INVALID_OPERATION:
|
||||
{
|
||||
error = "GL_INVALID_OPERATION";
|
||||
description = "the specified operation is not allowed in the current state";
|
||||
description = "The specified operation is not allowed in the current state.";
|
||||
break;
|
||||
}
|
||||
|
||||
case GL_STACK_OVERFLOW:
|
||||
{
|
||||
error = "GL_STACK_OVERFLOW";
|
||||
description = "this command would cause a stack overflow";
|
||||
description = "This command would cause a stack overflow.";
|
||||
break;
|
||||
}
|
||||
|
||||
case GL_STACK_UNDERFLOW:
|
||||
{
|
||||
error = "GL_STACK_UNDERFLOW";
|
||||
description = "this command would cause a stack underflow";
|
||||
description = "This command would cause a stack underflow.";
|
||||
break;
|
||||
}
|
||||
|
||||
case GL_OUT_OF_MEMORY:
|
||||
{
|
||||
error = "GL_OUT_OF_MEMORY";
|
||||
description = "there is not enough memory left to execute the command";
|
||||
description = "There is not enough memory left to execute the command.";
|
||||
break;
|
||||
}
|
||||
|
||||
case GLEXT_GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||
{
|
||||
error = "GL_INVALID_FRAMEBUFFER_OPERATION";
|
||||
description = "the object bound to FRAMEBUFFER_BINDING is not \"framebuffer complete\"";
|
||||
description = "The object bound to FRAMEBUFFER_BINDING is not \"framebuffer complete\".";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Log the error
|
||||
err() << "An internal OpenGL call failed in "
|
||||
<< fileString.substr(fileString.find_last_of("\\/") + 1) << " (" << line << ") : "
|
||||
<< error << ", " << description
|
||||
<< fileString.substr(fileString.find_last_of("\\/") + 1) << "(" << line << ")."
|
||||
<< "\nExpression:\n " << expression
|
||||
<< "\nError description:\n " << error << "\n " << description << "\n"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/Graphics/GLExtensions.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
@ -38,7 +37,7 @@ namespace sf
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenGL API calls
|
||||
/// Let's define a macro to quickly check every OpenGL API call
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
@ -49,7 +48,7 @@ namespace priv
|
||||
#else
|
||||
|
||||
// Else, we don't add any overhead
|
||||
#define glCheck(call) (call)
|
||||
#define glCheck(expr) (expr)
|
||||
|
||||
#endif
|
||||
|
||||
@ -58,9 +57,10 @@ namespace priv
|
||||
///
|
||||
/// \param file Source file where the call is located
|
||||
/// \param line Line number of the source file where the call is located
|
||||
/// \param expression The evaluated expression as a string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void glCheckError(const char* file, unsigned int line);
|
||||
void glCheckError(const char* file, unsigned int line, const char* expression);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user