Skip to content

Commit a18a72c

Browse files
committed
Fixing segfault with offscreen plot tests on Linux
1 parent 48f20e4 commit a18a72c

1 file changed

Lines changed: 14 additions & 36 deletions

File tree

phy/plot/base.py

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import numpy as np
1515
from phylib.utils import Bunch, connect, emit
1616

17-
from phy.gui.qt import QEvent, QOpenGLWindow, Qt
17+
from phy.gui.qt import QOpenGLWindow, Qt
1818

1919
from . import gloo
2020
from .gloo import gl
@@ -824,41 +824,19 @@ def keyReleaseEvent(self, e):
824824
self._key_event('key_release', e)
825825
self._current_key_event = None
826826

827-
def event(self, e): # pragma: no cover
828-
"""Touch event."""
829-
out = super().event(e)
830-
t = e.type()
831-
# Two-finger pinch.
832-
if t == QEvent.TouchBegin:
833-
self.emit('pinch_begin')
834-
elif t == QEvent.TouchEnd:
835-
self.emit('pinch_end')
836-
elif t == QEvent.Gesture:
837-
gesture = e.gesture(Qt.PinchGesture)
838-
if gesture:
839-
(x, y) = gesture.centerPoint().x(), gesture.centerPoint().y()
840-
scale = gesture.scaleFactor()
841-
last_scale = gesture.lastScaleFactor()
842-
rotation = gesture.rotationAngle()
843-
self.emit(
844-
'pinch',
845-
pos=(x, y),
846-
scale=scale,
847-
last_scale=last_scale,
848-
rotation=rotation,
849-
)
850-
# General touch event.
851-
elif t == QEvent.TouchUpdate:
852-
points = e.touchPoints()
853-
# These variables are lists of (x, y) coordinates.
854-
pos, last_pos = zip(
855-
*[
856-
((p.pos().x(), p.pos.y()), (p.lastPos().x(), p.lastPos.y()))
857-
for p in points
858-
]
859-
)
860-
self.emit('touch', pos=pos, last_pos=last_pos)
861-
return out
827+
def close(self):
828+
"""Close the OpenGL canvas.
829+
830+
The Qt offscreen platform plugin crashes when closing a shown QOpenGLWindow after
831+
rendering. Hiding the window avoids the native crash and is sufficient for headless
832+
test cleanup.
833+
"""
834+
from os import environ
835+
836+
if environ.get('QT_QPA_PLATFORM') == 'offscreen':
837+
self.hide()
838+
return
839+
super().close()
862840

863841
def update(self):
864842
"""Update the OpenGL canvas."""

0 commit comments

Comments
 (0)