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 potential segmentation fault on glBindSampler #1806

Closed
wants to merge 1 commit into from

Conversation

matrefeytontias
Copy link

@matrefeytontias matrefeytontias commented May 10, 2018

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.

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.
@ocornut ocornut added the opengl label May 10, 2018
@ocornut
Copy link
Owner

ocornut commented May 10, 2018

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).
Did you actually get a segmentation fault? Could you specify which OpenGL loader/extension wrangler/OS/GPU/driver?

@matrefeytontias
Copy link
Author

I did get a segmentation fault on Windows with MSYS2 (MSYS shell environment with -mwin32 passed to gcc), GLAD set to OpenGL 4.6 compatibility mode with latest GLFW, running on an Nvidia GeForce GTX 1050 with latest drivers. I have asserted that printf("%p", (void*)glBindSampler); displays 0x0 with the various GLFW hints set to OpenGL 3.2 and that the program is working fine with the various hints pointing to OpenGL 3.3 .

@ocornut
Copy link
Owner

ocornut commented May 10, 2018

Thank for the details! I don’t really know what’s the best course of action, will think about it.

@matrefeytontias
Copy link
Author

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

@ocornut
Copy link
Owner

ocornut commented May 14, 2018

@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?

@matrefeytontias
Copy link
Author

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 ?

@ocornut
Copy link
Owner

ocornut commented May 14, 2018

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.

ocornut added a commit that referenced this pull request May 14, 2018
…to make the example code easier to use/share with different context version. (#1806)
@ocornut
Copy link
Owner

ocornut commented Jun 7, 2018

Closing as fixed by 1954462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants