Don't crash if rendering without any window

Probably it'll still crash somewhere else then, but we'll rely on Sentry to find that for us.

Fixes Sentry issue CURA-KW.
This commit is contained in:
Ghostkeeper 2020-04-23 13:41:06 +02:00
parent 29d2e5c921
commit 75aafa1e5c
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -267,10 +267,20 @@ class SolidView(View):
Class that ducktypes to be a Numpy ndarray. Class that ducktypes to be a Numpy ndarray.
""" """
def __init__(self, qimage): def __init__(self, qimage):
bits_pointer = qimage.bits()
if bits_pointer is None: # If this happens before there is a window.
self.__array_interface__ = {
"shape": (0, 0),
"typestr": "|u4",
"data": (0, False),
"strides": (1, 3),
"version": 3
}
else:
self.__array_interface__ = { self.__array_interface__ = {
"shape": (qimage.height(), qimage.width()), "shape": (qimage.height(), qimage.width()),
"typestr": "|u4", # Use 4 bytes per pixel rather than 3, since Numpy doesn't support 3. "typestr": "|u4", # Use 4 bytes per pixel rather than 3, since Numpy doesn't support 3.
"data": (int(qimage.bits()), False), "data": (int(bits_pointer), False),
"strides": (qimage.bytesPerLine(), 3), # This does the magic: For each line, skip the correct number of bytes. Bytes per pixel is always 3 due to QImage.Format.Format_RGB888. "strides": (qimage.bytesPerLine(), 3), # This does the magic: For each line, skip the correct number of bytes. Bytes per pixel is always 3 due to QImage.Format.Format_RGB888.
"version": 3 "version": 3
} }