mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
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:
parent
29d2e5c921
commit
75aafa1e5c
1 changed files with 17 additions and 7 deletions
|
@ -267,13 +267,23 @@ 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):
|
||||||
self.__array_interface__ = {
|
bits_pointer = qimage.bits()
|
||||||
"shape": (qimage.height(), qimage.width()),
|
if bits_pointer is None: # If this happens before there is a window.
|
||||||
"typestr": "|u4", # Use 4 bytes per pixel rather than 3, since Numpy doesn't support 3.
|
self.__array_interface__ = {
|
||||||
"data": (int(qimage.bits()), False),
|
"shape": (0, 0),
|
||||||
"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.
|
"typestr": "|u4",
|
||||||
"version": 3
|
"data": (0, False),
|
||||||
}
|
"strides": (1, 3),
|
||||||
|
"version": 3
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
self.__array_interface__ = {
|
||||||
|
"shape": (qimage.height(), qimage.width()),
|
||||||
|
"typestr": "|u4", # Use 4 bytes per pixel rather than 3, since Numpy doesn't support 3.
|
||||||
|
"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.
|
||||||
|
"version": 3
|
||||||
|
}
|
||||||
array = np.asarray(QImageArrayView(xray_img)).view(np.dtype({
|
array = np.asarray(QImageArrayView(xray_img)).view(np.dtype({
|
||||||
"r": (np.uint8, 0, "red"),
|
"r": (np.uint8, 0, "red"),
|
||||||
"g": (np.uint8, 1, "green"),
|
"g": (np.uint8, 1, "green"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue