mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 10:40:09 -06:00
Add the optional ability to print a stacktrace with an OpenGL error (closes #1700)
This commit is contained in:
@@ -108,6 +108,7 @@ struct Configuration {
|
||||
|
||||
struct OpenGLDebugContext {
|
||||
bool isActive = false;
|
||||
bool printStacktrace = false;
|
||||
bool isSynchronous = true;
|
||||
struct IdentifierFilter {
|
||||
std::string type;
|
||||
|
||||
@@ -238,6 +238,7 @@ ScreenSpaceRotation = { 0.0, 0.0, 0.0 }
|
||||
|
||||
OpenGLDebugContext = {
|
||||
Activate = true,
|
||||
PrintStacktrace = false,
|
||||
FilterIdentifier = {
|
||||
{ Type = "Other", Source = "API", Identifier = 131185 },
|
||||
-- API_ID_RECOMPILE_FRAGMENT_SHADER performance warning has been generated. Fragment shader recompiled due to state change
|
||||
|
||||
@@ -223,6 +223,11 @@ namespace {
|
||||
// Determines whether the OpenGL context should be a debug context
|
||||
bool activate;
|
||||
|
||||
// If this is set to 'true', everytime an OpenGL error is logged, the full
|
||||
// stacktrace leading to the error is printed as well, making debugging under
|
||||
// production situations much easier
|
||||
std::optional<bool> printStacktrace;
|
||||
|
||||
// Determines whether the OpenGL debug callbacks are performed synchronously.
|
||||
// If set to 'true' the callbacks are in the same thread as the context and in
|
||||
// the scope of the OpenGL function that triggered the message. The default
|
||||
@@ -478,6 +483,9 @@ void parseLuaState(Configuration& configuration) {
|
||||
if (p.openGLDebugContext.has_value()) {
|
||||
const Parameters::OpenGLDebugContext& l = *p.openGLDebugContext;
|
||||
c.openGLDebugContext.isActive = l.activate;
|
||||
c.openGLDebugContext.printStacktrace = l.printStacktrace.value_or(
|
||||
c.openGLDebugContext.printStacktrace
|
||||
);
|
||||
c.openGLDebugContext.isSynchronous = l.synchronous.value_or(
|
||||
c.openGLDebugContext.isSynchronous
|
||||
);
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/logging/visualstudiooutputlog.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <ghoul/misc/stacktrace.h>
|
||||
#include <ghoul/misc/stringconversion.h>
|
||||
#include <ghoul/opengl/debugcontext.h>
|
||||
#include <ghoul/opengl/shaderpreprocessor.h>
|
||||
@@ -560,6 +561,15 @@ void OpenSpaceEngine::initializeGL() {
|
||||
default:
|
||||
throw ghoul::MissingCaseException();
|
||||
}
|
||||
|
||||
if (global::configuration->openGLDebugContext.printStacktrace) {
|
||||
std::string stackString = "Stacktrace\n";
|
||||
std::vector<std::string> stack = ghoul::stackTrace();
|
||||
for (size_t i = 0; i < stack.size(); i++) {
|
||||
stackString += fmt::format("{}: {}\n", i, stack[i]);
|
||||
}
|
||||
LDEBUGC(category, stackString);
|
||||
}
|
||||
};
|
||||
ghoul::opengl::debug::setDebugCallback(callback);
|
||||
}
|
||||
|
||||
@@ -388,6 +388,7 @@ TEST_CASE("Configuration: openGLDebugContext", "[configuration]") {
|
||||
constexpr const char Extra[] = R"(OpenGLDebugContext = { Activate = true })";
|
||||
const Configuration c = loadConfiguration("openGLDebugContext1", Extra);
|
||||
CHECK(c.openGLDebugContext.isActive == true);
|
||||
CHECK(c.openGLDebugContext.printStacktrace == false);
|
||||
CHECK(
|
||||
c.openGLDebugContext.isSynchronous ==
|
||||
defaultConf.openGLDebugContext.isSynchronous
|
||||
@@ -451,6 +452,7 @@ OpenGLDebugContext = { Activate = true, Synchronous = true }
|
||||
constexpr const char Extra[] = R"(
|
||||
OpenGLDebugContext = {
|
||||
Activate = true,
|
||||
PrintStacktrace = true,
|
||||
FilterIdentifier = {
|
||||
{ Identifier = 1, Source = "API", Type = "Error" },
|
||||
{ Identifier = 2, Source = "Window System", Type = "Deprecated" },
|
||||
@@ -467,6 +469,7 @@ OpenGLDebugContext = {
|
||||
)";
|
||||
const Configuration c = loadConfiguration("openGLDebugContext3", Extra);
|
||||
CHECK(c.openGLDebugContext.isActive == true);
|
||||
CHECK(c.openGLDebugContext.printStacktrace == true);
|
||||
CHECK(
|
||||
c.openGLDebugContext.isSynchronous ==
|
||||
defaultConf.openGLDebugContext.isSynchronous
|
||||
@@ -515,6 +518,7 @@ OpenGLDebugContext = { Activate = true, FilterSeverity = { "High", "Medium" } }
|
||||
)";
|
||||
const Configuration c = loadConfiguration("openGLDebugContext4", Extra);
|
||||
CHECK(c.openGLDebugContext.isActive == true);
|
||||
CHECK(c.openGLDebugContext.printStacktrace == false);
|
||||
CHECK(
|
||||
c.openGLDebugContext.isSynchronous ==
|
||||
defaultConf.openGLDebugContext.isSynchronous
|
||||
|
||||
Reference in New Issue
Block a user