Skip to content

Commit

Permalink
Fixed handling of NoDisplay
Browse files Browse the repository at this point in the history
Now its __repr__ and __str__ don't cause exceptions, and it won't be eglTerminate'd at shutdown.
  • Loading branch information
perey committed Sep 29, 2021
1 parent 9a7815d commit 846da10
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/pegl/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def __del__(self):
# This instance never got cached.
pass

# Don't do anything else for NoDisplay.
if self._as_parameter_ is egl.EGL_NO_DISPLAY:
return

# Terminate this display.
try:
egl.eglTerminate(self)
Expand All @@ -114,7 +118,7 @@ def __del__(self):
egl.eglReleaseThread()

def __bool__(self):
return self._as_parameter_ != egl.EGL_NO_DISPLAY
return self._as_parameter_ is not egl.EGL_NO_DISPLAY

def __eq__(self, other):
try:
Expand All @@ -123,10 +127,23 @@ def __eq__(self, other):
return False

def __repr__(self):
if self._as_parameter_ is egl.EGL_NO_DISPLAY:
return '<{}: EGL_NO_DISPLAY>'.format(self.__class__.__name__)
return '<{}: {:#08x}>'.format(self.__class__.__name__,
self._as_parameter_)

def __str__(self):
if self._as_parameter_ is egl.EGL_NO_DISPLAY:
# The ability to get the version string from NoDisplay was added in
# a revision to EGL 1.5, so doing so may or may not fail on that
# version! Let's not worry about it and just try it anyway.
try:
vstring = self.version_string
except BadDisplayError:
return '<{}: EGL_NO_DISPLAY>'.format(self.__class__.__name__)
else:
return '<{}: EGL_NO_DISPLAY, EGL {}>'.format(
self.__class__.__name__, vstring)
return '<{}: {:#08x}, EGL {}>'.format(self.__class__.__name__,
self._as_parameter_,
self.version_string)
Expand Down

0 comments on commit 846da10

Please sign in to comment.