Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on macOS Catalina where GL info is missing #508

Closed

Conversation

vespakoen
Copy link
Contributor

Opening the preferences no macOS Catalina crashes SolveSpace.
This is due to the way the gl_vendor / gl_renderer and gl_version is retrieved.
We use glGetString in rendergl3.cpp (in the getIdent function).

Somehow this doesn't seem to work anymore in Catalina.

Let me know if anything needs to change.

@whitequark
Copy link
Contributor

glGetString can return NULL if for some reason there is no current OpenGL context. But that should not be possible by the time when you click on the preferences link.

Could you catch the crash with a debugger (or just put a breakpoint at GetIdent), and print the value of [NSOpenGLContext currentContext] at that point? It should not be nil.

@vespakoen
Copy link
Contributor Author

So it looks like our change that removed the framebuffer caused this, the code below fixes that:

I'll make a new PR for it if you are happy with it.

Screenshot 2019-11-25 at 10 48 42

diff --git a/src/platform/guimac.mm b/src/platform/guimac.mm
index 33901ff..b8aa938 100644
--- a/src/platform/guimac.mm
+++ b/src/platform/guimac.mm
@@ -385,6 +385,7 @@ - (id)initWithFrame:(NSRect)frameRect {
         editor.bezeled = NO;
         editor.target = self;
         editor.action = @selector(didEdit:);
+        [[self openGLContext] makeCurrentContext];
     }
     return self;
 }
(END)

@whitequark
Copy link
Contributor

Your fix is a bit dirty. The platform code does not really guarantee that there will be an active GL context outside of onRender, and it should not. What about this?

diff --git a/src/render/rendergl3.cpp b/src/render/rendergl3.cpp
index b3ae1fa6..e4faf4d8 100644
--- a/src/render/rendergl3.cpp
+++ b/src/render/rendergl3.cpp
@@ -87,6 +87,7 @@ public:
         Fill       *fill;
         std::weak_ptr<const Pixmap> texture;
     } current;
+    const char *vendor, *renderer, *version;
 
     // List-initialize current to work around MSVC bug 746973.
     OpenGl3Renderer() :
@@ -440,6 +441,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 +701,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) {

@vespakoen
Copy link
Contributor Author

Cool! Yes that looks a lot better. I will test it after work (in about 4 hours)

@vespakoen
Copy link
Contributor Author

Yes that worked as well! Shall I make a PR for it or will you apply it yourself?

@whitequark
Copy link
Contributor

whitequark commented Nov 26, 2019

Fixed in 0501f0c.

@whitequark whitequark closed this Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants