Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update canvas.go - Length check added to fix panic out of range #4532

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/driver/common/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,10 @@ func (o *overlayStack) add(overlay fyne.CanvasObject) {
func (o *overlayStack) remove(overlay fyne.CanvasObject) {
o.OverlayStack.Remove(overlay)
overlayCount := len(o.List())
o.renderCaches[overlayCount] = nil // release memory reference to removed element
o.renderCaches = o.renderCaches[:overlayCount]
if len(o.renderCaches) > overlayCount {
Copy link
Member

Choose a reason for hiding this comment

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

The "happy path" should be left aligned - i.e. this should really be a check for if the count is too low then returning early.
In general this sort of safety is probably a good thing as we shouldn't really panic even if developer triggers a bad path.

o.renderCaches[overlayCount] = nil // release memory reference to removed element
o.renderCaches = o.renderCaches[:overlayCount]
}
}

type renderCacheTree struct {
Expand Down
Loading