Fix memory leak issues in minitor page

Issue was that QT (incorrectly?) asserted that there was a binding loop between width and height in the `NetworkMJPGImage` component. This caused the height to evalualte to `infinity`, making QT create a buffer with an infinite amount of memory. Solved by calculating a serpeate `img_scale_factor` which both the width and height uses.

CURA-11180
This commit is contained in:
c.lamboo 2023-10-19 11:53:41 +02:00
parent e5e941aeba
commit 0e1262126a
2 changed files with 24 additions and 15 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2019 Ultimaker B.V.
// Copyright (c) 2023 UltiMaker
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2
@ -6,7 +6,7 @@ import UM 1.3 as UM
import Cura 1.0 as Cura
Item {
property var cameraUrl: "";
property string cameraUrl: "";
Rectangle {
anchors.fill:parent;
@ -34,22 +34,29 @@ Item {
Cura.NetworkMJPGImage {
id: cameraImage
anchors.horizontalCenter: parent.horizontalCenter;
anchors.verticalCenter: parent.verticalCenter;
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
readonly property real img_scale_factor: {
if (imageWidth > maximumWidth || imageHeight > maximumHeight) {
return Math.min(maximumWidth / imageWidth, maximumHeight / imageHeight);
}
return 1.0;
}
width: imageWidth === 0 ? 800 * screenScaleFactor : imageWidth * img_scale_factor
height: imageHeight === 0 ? 600 * screenScaleFactor : imageHeight * img_scale_factor
onVisibleChanged: {
if (cameraUrl === "") return;
if (visible) {
if (cameraUrl != "") {
start();
}
start();
} else {
if (cameraUrl != "") {
stop();
}
stop();
}
}
source: cameraUrl
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
z: 1
}