From eb4a2dbe0fe80c975a1592429e9eda8131b7409e Mon Sep 17 00:00:00 2001 From: vittorioromeo Date: Thu, 26 Sep 2024 15:10:04 +0200 Subject: [PATCH] Drain errors in [E]GLCheck via loop --- src/SFML/Graphics/GLCheck.hpp | 41 +++++++++++++++++++++++------------ src/SFML/Window/EGLCheck.hpp | 41 +++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/SFML/Graphics/GLCheck.hpp b/src/SFML/Graphics/GLCheck.hpp index 2f289bc5d..7368d12f7 100644 --- a/src/SFML/Graphics/GLCheck.hpp +++ b/src/SFML/Graphics/GLCheck.hpp @@ -29,10 +29,15 @@ //////////////////////////////////////////////////////////// #include +#include + +#include + #include #include #include + namespace sf::priv { //////////////////////////////////////////////////////////// @@ -53,20 +58,28 @@ bool glCheckError(const std::filesystem::path& file, unsigned int line, std::str #ifdef SFML_DEBUG // In debug mode, perform a test on every OpenGL call // The lamdba allows us to call glCheck as an expression and acts as a single statement perfect for if/else statements -#define glCheck(...) \ - [](auto&& glCheckInternalFunction) \ - { \ - if constexpr (!std::is_void_v) \ - { \ - const auto glCheckInternalReturnValue = glCheckInternalFunction(); \ - sf::priv::glCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__); \ - return glCheckInternalReturnValue; \ - } \ - else \ - { \ - glCheckInternalFunction(); \ - sf::priv::glCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__); \ - } \ +#define glCheck(...) \ + [](auto&& glCheckInternalFunction) \ + { \ + if (const GLenum glCheckInternalError = glGetError(); glCheckInternalError != GL_NO_ERROR) \ + sf::err() << "OpenGL error (" << glCheckInternalError << ") detected during glCheck call" << std::endl; \ + \ + if constexpr (!std::is_void_v) \ + { \ + const auto glCheckInternalReturnValue = glCheckInternalFunction(); \ + \ + while (!sf::priv::glCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__)) \ + /* no-op */; \ + \ + return glCheckInternalReturnValue; \ + } \ + else \ + { \ + glCheckInternalFunction(); \ + \ + while (!sf::priv::glCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__)) \ + /* no-op */; \ + } \ }([&]() { return __VA_ARGS__; }) #else diff --git a/src/SFML/Window/EGLCheck.hpp b/src/SFML/Window/EGLCheck.hpp index bf84b1120..523577535 100644 --- a/src/SFML/Window/EGLCheck.hpp +++ b/src/SFML/Window/EGLCheck.hpp @@ -29,8 +29,13 @@ //////////////////////////////////////////////////////////// #include +#include + +#include + #include #include +#include namespace sf::priv @@ -54,20 +59,28 @@ bool eglCheckError(const std::filesystem::path& file, unsigned int line, std::st // In debug mode, perform a test on every EGL call // The lamdba allows us to call eglCheck as an expression and acts as a single statement perfect for if/else statements -#define eglCheck(...) \ - [](auto&& eglCheckInternalFunction) \ - { \ - if constexpr (!std::is_void_v) \ - { \ - const auto eglCheckInternalReturnValue = eglCheckInternalFunction(); \ - sf::priv::eglCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__); \ - return eglCheckInternalReturnValue; \ - } \ - else \ - { \ - eglCheckInternalFunction(); \ - sf::priv::eglCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__); \ - } \ +#define eglCheck(...) \ + [](auto&& eglCheckInternalFunction) \ + { \ + if (const EGLint eglCheckInternalError = eglGetError(); eglCheckInternalError != EGL_SUCCESS) \ + sf::err() << "EGL error (" << eglCheckInternalError << ") detected during eglCheck call" << std::endl; \ + \ + if constexpr (!std::is_void_v) \ + { \ + const auto eglCheckInternalReturnValue = eglCheckInternalFunction(); \ + \ + while (!sf::priv::eglCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__)) \ + /* no-op */; \ + \ + return eglCheckInternalReturnValue; \ + } \ + else \ + { \ + eglCheckInternalFunction(); \ + \ + while (!sf::priv::eglCheckError(__FILE__, static_cast(__LINE__), #__VA_ARGS__)) \ + /* no-op */; \ + } \ }([&]() { return __VA_ARGS__; }) #else