Skip to content

Commit

Permalink
#5336: Move assertNoGlErrors() method to debugging/gl.h header. On fa…
Browse files Browse the repository at this point in the history
…ilure, the global error handler is invoked instead of directly opening an wxutil::Messagebox.
  • Loading branch information
codereader committed Sep 20, 2020
1 parent da70add commit a88a9c9
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 61 deletions.
17 changes: 0 additions & 17 deletions include/igl.h
Expand Up @@ -69,10 +69,6 @@ class OpenGLBinding :
public:
virtual ~OpenGLBinding() {}

/// \brief Asserts that there no OpenGL errors have occurred since the last call to glGetError.
// Normally, you want to use the debug::assertNoGlErrors() wrapper which does nothing in release builds
virtual void assertNoErrors() = 0;

virtual int getFontHeight() = 0;

/// \brief Renders \p string at the current raster-position of the current context.
Expand All @@ -92,16 +88,3 @@ inline OpenGLBinding& GlobalOpenGL()
);
return _openGL;
}

namespace debug
{

inline void assertNoGlErrors()
{
#ifdef _DEBUG
GlobalOpenGL().assertNoErrors();
#endif
}

}

1 change: 1 addition & 0 deletions libs/RGBAImage.h
Expand Up @@ -5,6 +5,7 @@
#include "BasicTexture2D.h"
#include <memory>
#include "util/Noncopyable.h"
#include "debugging/gl.h"

struct RGBAPixel
{
Expand Down
47 changes: 47 additions & 0 deletions libs/debugging/gl.h
@@ -0,0 +1,47 @@
#pragma once

#ifdef _DEBUG
#include "igl.h"
#include "string/convert.h"
#endif

namespace debug
{

/// \brief Asserts that there no OpenGL errors have occurred since the last call to glGetError.
inline void assertNoGlErrors()
{
#ifdef _DEBUG
// Return if no error
GLenum error = glGetError();

if (error == GL_NO_ERROR)
{
return;
}

// Build list of all GL errors
std::string allErrString = "GL errors encountered: ";
int maxErrors = 100;

for (; error != GL_NO_ERROR; error = glGetError())
{
const char* strErr = reinterpret_cast<const char*>(
gluErrorString(error)
);
allErrString += string::to_string(error);
allErrString += " (" + std::string(strErr) + ") ";

if (--maxErrors <= 0)
{
allErrString += "---> Maximum number of GL errors reached, maybe there is a problem with the GL context?";
break;
}
}

// Show the error message and terminate
GlobalErrorHandler()("OpenGL Error", allErrString);
#endif
}

}
1 change: 1 addition & 0 deletions libs/wxutil/preview/GuiView.cpp
Expand Up @@ -3,6 +3,7 @@
#include "igl.h"
#include "math/Matrix4.h"
#include <functional>
#include "debugging/gl.h"

namespace wxutil
{
Expand Down
1 change: 1 addition & 0 deletions plugins/dm.gui/gui/RenderableCharacterBatch.cpp
@@ -1,6 +1,7 @@
#include "RenderableCharacterBatch.h"

#include "render.h"
#include "debugging/gl.h"

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

Expand Down
1 change: 1 addition & 0 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -29,6 +29,7 @@
#include "selection/SelectionTest.h"

#include "debugging/debugging.h"
#include "debugging/gl.h"
#include <wx/sizer.h>
#include "util/ScopedBoolLock.h"
#include <functional>
Expand Down
41 changes: 0 additions & 41 deletions radiant/render/OpenGLModule.cpp
Expand Up @@ -2,56 +2,15 @@

#include "irender.h"
#include "itextstream.h"
#include "imainframe.h"
#include "debugging/debugging.h"
#include "module/StaticModule.h"

#include <string/convert.h>
#include "wxutil/GLWidget.h"
#include "wxutil/dialog/MessageBox.h"

#include <stdexcept>
#include <FTGL/ftgl.h>

OpenGLModule::OpenGLModule() :
_unknownError("Unknown error.")
{}

void OpenGLModule::assertNoErrors()
{
#ifdef _DEBUG
// Return if no error
GLenum error = glGetError();

if (error == GL_NO_ERROR)
{
return;
}

// Build list of all GL errors
std::string allErrString = "GL errors encountered: ";
int maxErrors = 100;

for ( ; error != GL_NO_ERROR; error = glGetError())
{
const char* strErr = reinterpret_cast<const char*>(
gluErrorString(error)
);
allErrString += string::to_string(error);
allErrString += " (" + std::string(strErr) + ") ";

if (--maxErrors <= 0)
{
allErrString += "---> Maximum number of GL errors reached, maybe there is a problem with the GL context?";
break;
}
}

// Show the error message and terminate
wxutil::Messagebox::ShowFatalError(allErrString);
#endif
}

void OpenGLModule::sharedContextCreated()
{
// Initialise the font before firing the extension initialised signal
Expand Down
2 changes: 0 additions & 2 deletions radiant/render/OpenGLModule.h
Expand Up @@ -23,8 +23,6 @@ class OpenGLModule :
public:
OpenGLModule();

void assertNoErrors() override;

void drawString(const std::string& string) const override;
void drawChar(char character) const override;
int getFontHeight() override;
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/texturebrowser/TextureBrowser.cpp
Expand Up @@ -32,6 +32,7 @@
#include <wx/sizer.h>

#include "string/case_conv.h"
#include "debugging/gl.h"
#include "TextureBrowserManager.h"

namespace ui
Expand Down
1 change: 1 addition & 0 deletions radiant/xyview/XYWnd.cpp
Expand Up @@ -26,6 +26,7 @@
#include "selection/Device.h"
#include "selection/SelectionTest.h"
#include "util/ScopedBoolLock.h"
#include "debugging/gl.h"

#include "GlobalXYWnd.h"
#include "XYRenderer.h"
Expand Down
1 change: 1 addition & 0 deletions radiantcore/imagefile/DDSImage.cpp
Expand Up @@ -2,6 +2,7 @@

#include "itextstream.h"
#include "BasicTexture2D.h"
#include "debugging/gl.h"

TexturePtr DDSImage::bindTexture(const std::string& name) const
{
Expand Down
1 change: 1 addition & 0 deletions radiantcore/rendersystem/backend/GLProgramFactory.cpp
Expand Up @@ -12,6 +12,7 @@
#include "os/file.h"
#include "string/convert.h"
#include "debugging/debugging.h"
#include "debugging/gl.h"

#include <fstream>

Expand Down
1 change: 1 addition & 0 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.cpp
Expand Up @@ -9,6 +9,7 @@
#include "iglprogram.h"

#include "debugging/render.h"
#include "debugging/gl.h"

namespace render
{
Expand Down
Expand Up @@ -4,6 +4,7 @@
#include "igame.h"
#include "string/convert.h"
#include "math/Matrix4.h"
#include "debugging/gl.h"

namespace render
{
Expand Down
@@ -1,5 +1,6 @@
#include "ARBDepthFillProgram.h"
#include "../GLProgramFactory.h"
#include "debugging/gl.h"

namespace render
{
Expand Down
Expand Up @@ -4,6 +4,7 @@
#include "itextstream.h"
#include "igame.h"
#include "string/convert.h"
#include "debugging/gl.h"
#include "math/Matrix4.h"

namespace render
Expand Down
@@ -1,5 +1,6 @@
#include "GLSLDepthFillProgram.h"
#include "../GLProgramFactory.h"
#include "debugging/gl.h"

#include "itextstream.h"

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/shaders/CameraCubeMapDecl.cpp
@@ -1,6 +1,6 @@
#include "CameraCubeMapDecl.h"
#include "textures/CubeMapTexture.h"

#include "debugging/gl.h"
#include "itextstream.h"
#include <stdexcept>

Expand Down
7 changes: 7 additions & 0 deletions test/TestContext.h
Expand Up @@ -3,6 +3,7 @@
#include "module/ApplicationContextBase.h"
#include "os/fs.h"
#include "os/dir.h"
#include "debugging/debugging.h"

namespace radiant
{
Expand All @@ -26,6 +27,12 @@ class TestContext :

os::removeDirectory(_settingsFolder);
os::makeDirectory(_settingsFolder);

setErrorHandlingFunction([&](const std::string& title, const std::string& message)
{
std::cerr << "Fatal error " << title << "\n" << message << std::endl;
DEBUGGER_BREAKPOINT();
});
}

~TestContext()
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/libs.vcxproj
Expand Up @@ -145,6 +145,7 @@
<ClInclude Include="..\..\libs\command\ExecutionFailure.h" />
<ClInclude Include="..\..\libs\command\ExecutionNotPossible.h" />
<ClInclude Include="..\..\libs\debugging\debugging.h" />
<ClInclude Include="..\..\libs\debugging\gl.h" />
<ClInclude Include="..\..\libs\debugging\render.h" />
<ClInclude Include="..\..\libs\debugging\ScenegraphUtils.h" />
<ClInclude Include="..\..\libs\debugging\ScopedDebugTimer.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/libs.vcxproj.filters
Expand Up @@ -252,6 +252,9 @@
<ClInclude Include="..\..\libs\time\ScopeTimer.h">
<Filter>time</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\debugging\gl.h">
<Filter>debugging</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="util">
Expand Down

0 comments on commit a88a9c9

Please sign in to comment.