Skip to content

Commit

Permalink
Don't call GL functions in OpenGl3Renderer::GetIdent.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whitequark committed Nov 26, 2019
1 parent 22525e6 commit 0501f0c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/render/rendergl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class OpenGl3Renderer final : public ViewportCanvas {
Fill *fill;
std::weak_ptr<const Pixmap> texture;
} current;
const char *vendor = "<uninitialized>";
const char *renderer = "<uninitialized>";
const char *version = "<uninitialized>";

// List-initialize current to work around MSVC bug 746973.
OpenGl3Renderer() :
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -696,9 +703,9 @@ std::shared_ptr<Pixmap> 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) {
Expand Down

0 comments on commit 0501f0c

Please sign in to comment.