-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 potential segmentation fault on glBindSampler
#1806
Conversation
As per [https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindSampler.xhtml](the OpenGL 4 specification), `glBindSampler` is available only when the GL version is 3.3 or higher.
OpenGL version are tricky to get right in a cross platform way, see e.g. #1466 where the version was already changed from 3.3 to 3.2 on January 7 (read the comments about OS X). |
I did get a segmentation fault on Windows with MSYS2 (MSYS shell environment with |
Thank for the details! I don’t really know what’s the best course of action, will think about it. |
A little older, but the exact same situation appeared there (see the only comment on the only answer) : https://stackoverflow.com/questions/48582444/imgui-with-the-glad-opengl-loader-throws-segmentation-fault-core-dumped |
@matrefeytontias I guess we could do make those calls optionals: if (glBindSampler != NULL)
glBindSampler(0, 0); Are you aware of an OpenGL function that which would setup the functions in a way that would pass the if() test but still crash inside? |
I doubt it. As far as I know, segfaults related to OpenGL that aren't a programmer's mistake are always due to null function pointers, be it because extension wrangling has been done wrong or because the function is flat out not available in the context. However, I think that this test is more a work-around than a real fix, because if the program still works when the function isn't called, then what's the point in calling it to begin with ? |
If the OpenGL context has this functionality it needs to explicitly be set up, otherwise an application that sets a different sampler and run the imgui render function will get broken rendering. Also note that main.cpp is purely demo code while imgui_impl_opengl etc. are meant to be shared code. |
…to make the example code easier to use/share with different context version. (#1806)
Closing as fixed by 1954462 |
As per the OpenGL 4 specification,
glBindSampler
is available only when the GL version is 3.3 or higher. This fixes a potential segmentation fault when trying to run the OpenGL 3 example with another extension wrangler than the one included in the examples package.