From 3ca5d4ab298c5ce5ff24b79c1a84d2a0fc1ea572 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 31 Aug 2026 05:45:35 +1200 Subject: [PATCH] Fix GitHub issue #798: element editor crash on scroll-wheel zoom ElementView applied scale() on every wheel notch with no bound on the resulting view transform. Held down, the scroll-wheel zoom drives the transform scale (m11) to floating-point overflow; the transform becomes non-invertible, mapToScene() returns NaN and the next background paint aborts the editor ("program closes completely" as reported on Windows). Route zoomIn/zoomOut/zoomInSlowly/zoomOutSlowly through a new scaleClamped() helper that only applies the scale while the result stays within [m_min_zoom, m_max_zoom] (0.1 .. 200). Behaviour within that range is unchanged. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01HdWpDp3TrPKbHnv7YUcNJj --- sources/editor/elementview.cpp | 25 +++++++++++++++++++++---- sources/editor/elementview.h | 7 +++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/sources/editor/elementview.cpp b/sources/editor/elementview.cpp index 62226f748..b1f4e30ec 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -100,13 +100,30 @@ void ElementView::setSelectionMode() emit(modeChanged()); } +/** + Applique un facteur d'echelle a la vue en bornant l'echelle resultante + entre m_min_zoom et m_max_zoom. Sans cette borne, un zoom repete (molette) + finit par faire deborder la transformation de la vue et fait planter + l'editeur (issue #798). + @param factor facteur d'echelle a appliquer +*/ +void ElementView::scaleClamped(qreal factor) +{ + const qreal current = transform().m11(); + const qreal target = current * factor; + if (target < m_min_zoom || target > m_max_zoom) { + return; + } + scale(factor, factor); +} + /** Agrandit le schema (+33% = inverse des -25 % de zoomMoins()) */ void ElementView::zoomIn() { adjustSceneRect(); - scale(4.0/3.0, 4.0/3.0); + scaleClamped(4.0/3.0); } /** @@ -115,7 +132,7 @@ void ElementView::zoomIn() void ElementView::zoomOut() { adjustSceneRect(); - scale(0.75, 0.75); + scaleClamped(0.75); } /** @@ -123,7 +140,7 @@ void ElementView::zoomOut() */ void ElementView::zoomInSlowly() { - scale(1.02, 1.02); + scaleClamped(1.02); } /** @@ -131,7 +148,7 @@ void ElementView::zoomInSlowly() */ void ElementView::zoomOutSlowly() { - scale(0.98, 0.98); + scaleClamped(0.98); } /** diff --git a/sources/editor/elementview.h b/sources/editor/elementview.h index 54e5dc49d..09168b996 100644 --- a/sources/editor/elementview.h +++ b/sources/editor/elementview.h @@ -53,6 +53,13 @@ class ElementView : public QGraphicsView { private: QRectF applyMovement(const QRectF &, const QPointF &); + void scaleClamped(qreal factor); + + /// Lowest and highest allowed value of the view transform scale (m11). + /// Prevents the wheel-zoom from driving the transform to overflow, which + /// crashes the editor (bugtracker / GitHub issue #798). + static constexpr qreal m_min_zoom = 0.1; + static constexpr qreal m_max_zoom = 200.0; public slots: void setVisualisationMode();