Skip to content

fix: Crash when bounding box touches image edge - #240

Merged
vietanhdev merged 1 commit into
vietanhdev:mainfrom
LeonKraim:fix/bounding-box-edge-crash
Jul 11, 2026
Merged

fix: Crash when bounding box touches image edge#240
vietanhdev merged 1 commit into
vietanhdev:mainfrom
LeonKraim:fix/bounding-box-edge-crash

Conversation

@LeonKraim

Copy link
Copy Markdown
Contributor

Summary

intersection_point() returns \QPoint\ (integer coords) while every other coordinate in the shape pipeline uses \QPointF. When a user drags a bounding box (or polygon, linestrip) to the image edge, the projected edge point (\QPoint) gets stored into shape/line point lists and eventually reaches \QPainterPath.lineTo(), which refuses \QPoint\ — causing a \TypeError: argument 1 has unexpected type 'QPoint'\ crash at \shape.py:199.

Fix

Changed all three return statements in \intersection_point()\ from \QtCore.QPoint\ to \QtCore.QPointF\ so types stay consistent through the entire drawing pipeline.

Related

Fixes a crash that occurs when creating or editing any shape type at the image boundary.

intersection_point() returned QPoint (integer coords) while
every other coordinate in the shape pipeline uses QPointF.
When a user dragged a bounding box to the image edge, the
QPoint was stored into self.line.points and eventually hit
QPainterPath.lineTo() which expects QPointF, causing a
TypeError crash in Shape.paint().

Changed all three return statements in intersection_point()
from QPoint to QPointF so the types stay consistent
throughout the drawing pipeline.
@LeonKraim LeonKraim changed the title Fix crash when bounding box touches image edge fix: Crash when bounding box touches image edge Jul 9, 2026
@vietanhdev
vietanhdev merged commit 2b093a5 into vietanhdev:main Jul 11, 2026
9 checks passed
@vietanhdev

Copy link
Copy Markdown
Owner

Thanks for the clean fix, @LeonKraim — merged as 2b093a5. Fixing intersection_point() at the source rather than patching call sites was the right call; it closes both the drawing-at-the-edge crash this PR targets and the bounded_move_vertex crash from #237 in one change.

For anyone following along: there's a third, independent crash in the same area (bounded_move_shapes, which doesn't go through intersection_point()), being tracked in #238.

vietanhdev added a commit that referenced this pull request Jul 11, 2026
bounded_move_shapes() mixed QPointF (pos, from mouse events) with
QPoint literals when clamping a dragged shape to the pixmap border,
raising a TypeError when a selected shape is dragged near the image
edge. This is the same class of bug as #237/#240 (intersection_point
returning QPoint) but an independent instance, since this path never
calls intersection_point().

Co-authored-by: chaosbee <chaosbee@163.com>
vietanhdev added a commit that referenced this pull request Jul 11, 2026
…242)

Copilot's review of #241 flagged that the left/top clamp still did
int(o1.x()) before wrapping in QPointF, so sub-pixel overflows (e.g.
-0.3) truncate to 0 and silently fail to correct the position.

Verifying that fix surfaced a second, independent bug in the same
lines: the right/bottom clamp corrects against pixmap.width()/height()
instead of (width() - 1)/(height() - 1), which is the bound
out_off_pixmap() actually enforces — so a shape overflowing the right
or bottom edge stayed uncorrected regardless of the int() truncation.

Both are pre-existing (predate #237/#238/#240/#241); this PR only
touches the four lines already modified by #241. Adds a regression
test covering both edges plus the original TypeError crash path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants