Skip to content

Fix crash when cancelling a polyline drag that leaves a single point#6610

Merged
derwin12 merged 2 commits into
xLightsSequencer:masterfrom
o0charlie0o:fix/polyline-escape-drag-crash
Jun 27, 2026
Merged

Fix crash when cancelling a polyline drag that leaves a single point#6610
derwin12 merged 2 commits into
xLightsSequencer:masterfrom
o0charlie0o:fix/polyline-escape-drag-crash

Conversation

@o0charlie0o

Copy link
Copy Markdown
Contributor

Problem

xLights crashes (out-of-bounds std::vector access) when you cancel a polyline drag during model creation:

  1. Start creating a polyline in the Layout tab
  2. Click and drag a vertex
  3. Press Escape while still dragging

The crash aborts in PolyLineModel::DistributeLightsEvenly (PolyLineModel.cpp), reached via OnCharHook (Escape) → LayoutPanel::FinalizeModelPolyLineModel::DeleteHandleInitModel.

Root cause

DeleteHandle removes the in-flight vertex. If the polyline had only two points, num_points drops to 1, so _numSegments becomes 0 and the per-segment vectors (_polyLineSizes / _polyLineSegDropSizes) resize to empty. But _totalLightCount is still > 0, so DistributeLightsEvenly runs anyway and indexes _polyLineSegDropSizes[0] on an empty vector, aborting.

The existing resize guard in InitModel keeps those vectors consistent in size but doesn't handle the degenerate zero-segment case.

Fix

Bail out of InitModel early when there are no segments (_numSegments < 1). A polyline with fewer than two points is degenerate, and FinalizeModel deletes such a model immediately after DeleteHandle returns — so skipping light distribution is safe and avoids the crash.

Testing

  • Reproduced the crash on master, confirmed the fix resolves it.
  • macOS desktop Debug build succeeds.

🤖 Generated with Claude Code

Pressing Escape mid-create deletes the in-flight handle; if the polyline
had only two points num_points drops to 1, so _numSegments becomes 0 and
the per-segment vectors resize to empty. _totalLightCount is still > 0, so
DistributeLightsEvenly runs and indexes _polyLineSegDropSizes[0] on an
empty vector, aborting. Bail out of InitModel early when there are no
segments; FinalizeModel deletes the degenerate model right after.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 25, 2026 22:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a reproducible crash in the Layout polyline creation workflow when canceling (Escape) mid-drag leaves the in-flight model in a degenerate “single point / zero segments” state. The change is in src-core, so it applies to both desktop and iPad (shared core), while the user-facing crash is a desktop Layout interaction.

Changes:

  • Add an early return in PolyLineModel::InitModel() when _numSegments < 1 to avoid running light distribution on a zero-segment polyline (prevents out-of-bounds access).
  • Add a release note entry documenting the crash fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src-core/models/PolyLineModel.cpp Guard against degenerate polylines (0 segments) during InitModel to prevent OOB access during light distribution.
README.txt Add a desktop release note line for the polyline Escape-cancel crash fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Remove comments explaining polyline segment requirements.
@derwin12 derwin12 merged commit e7d6213 into xLightsSequencer:master Jun 27, 2026
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.

3 participants