raw-gl-context
raw-gl-context copied to clipboard
Add more error checking on X11
This PR adds some infrastructure to handle errors that can be raised when making X11 API calls:
- Adds a private, platform-specific field to
GlError::CreationFailed
for implementations to add more information on the source of the failure for debugging. This is just an empty tuple for on non-X11 for now. This is a breaking change, as this breaks enum exhaustiveness. - Adds an
XLibError
helper struct, with aDebug
implementation showing the text version of the error usingXGetErrorText
, to help debugging when usingunwrap()
. - Adds an
XErrorHandler
helper struct, which helps setup a temporary error handler for the duration of a given closure (after which the previous error handler is restored, which is needed for embedding). It also ensures the error handler is properly restored after an early return or a panic.
I realize this may be a bit late now (as it probably has been superseded by https://github.com/RustAudio/baseview/pull/115), but I did the small change anyway. :slightly_smiling_face:
Feel free to close this PR if this isn't relevant anymore.
It's appreciated! I'll try to re-review and merge this when I get the chance.
It would be great if you could also submit these changes for the OpenGL context creation in baseview. The code there was taken from the old version of this PR. Until baseview has some kind of API to hook into some low level window creation options the a separate raw-gl-context crate sadly cannot work correctly on Linux, so getting these improvements into baseview would help a lot in the meantime.
The OpenGL context creation code in Baseview was already changed to use a thread local (see https://github.com/RustAudio/baseview/pull/115#discussion_r820871427), so I don't think there's anything in this PR that's missing from Baseview.