Fix crash when cancelling a polyline drag that leaves a single point#6610
Merged
derwin12 merged 2 commits intoJun 27, 2026
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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 < 1to 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
xLights crashes (out-of-bounds
std::vectoraccess) when you cancel a polyline drag during model creation:The crash aborts in
PolyLineModel::DistributeLightsEvenly(PolyLineModel.cpp), reached viaOnCharHook(Escape) →LayoutPanel::FinalizeModel→PolyLineModel::DeleteHandle→InitModel.Root cause
DeleteHandleremoves the in-flight vertex. If the polyline had only two points,num_pointsdrops to 1, so_numSegmentsbecomes0and the per-segment vectors (_polyLineSizes/_polyLineSegDropSizes) resize to empty. But_totalLightCountis still > 0, soDistributeLightsEvenlyruns anyway and indexes_polyLineSegDropSizes[0]on an empty vector, aborting.The existing resize guard in
InitModelkeeps those vectors consistent in size but doesn't handle the degenerate zero-segment case.Fix
Bail out of
InitModelearly when there are no segments (_numSegments < 1). A polyline with fewer than two points is degenerate, andFinalizeModeldeletes such a model immediately afterDeleteHandlereturns — so skipping light distribution is safe and avoids the crash.Testing
🤖 Generated with Claude Code