From 0501f0c99e75ff0e6c5d07d1cd7bcdc119f6b3af Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 25 Nov 2019 10:51:29 +0000 Subject: [PATCH] Don't call GL functions in OpenGl3Renderer::GetIdent. GetIdent is called from an UI event callback, at which point there might well not be an active GL context. Before this commit, that would return a NULL pointer and result in a crash. --- src/render/rendergl3.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/render/rendergl3.cpp b/src/render/rendergl3.cpp index b3ae1fa6..b620aee0 100644 --- a/src/render/rendergl3.cpp +++ b/src/render/rendergl3.cpp @@ -87,6 +87,9 @@ public: Fill *fill; std::weak_ptr texture; } current; + const char *vendor = ""; + const char *renderer = ""; + const char *version = ""; // List-initialize current to work around MSVC bug 746973. OpenGl3Renderer() : @@ -440,6 +443,10 @@ void OpenGl3Renderer::Init() { meshRenderer.Init(); imeshRenderer.Init(); + vendor = (const char *)glGetString(GL_VENDOR); + renderer = (const char *)glGetString(GL_RENDERER); + version = (const char *)glGetString(GL_VERSION); + #if !defined(HAVE_GLES) && !defined(__APPLE__) GLuint array; glGenVertexArrays(1, &array); @@ -696,9 +703,9 @@ std::shared_ptr OpenGl3Renderer::ReadFrame() { } void OpenGl3Renderer::GetIdent(const char **vendor, const char **renderer, const char **version) { - *vendor = (const char *)glGetString(GL_VENDOR); - *renderer = (const char *)glGetString(GL_RENDERER); - *version = (const char *)glGetString(GL_VERSION); + *vendor = this->vendor; + *renderer = this->renderer; + *version = this->version; } void OpenGl3Renderer::SetCamera(const Camera &c) {