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
Alternating grid.Add() and grid.Remove() lets program crash #2775
Comments
Looks like we have missed some safety in the container add/remove functions |
Please complete this information so the bug can be correctly triaged/labelled/reproduced. (I cannot replicate on v2.1.2 locally) |
Hmm, this Info is at the end of my issue Report...
However I was not sure whether to include this between the comment signs or not. I did it within, believing these might be needed for some kind of automatic processing...
KR, Mike
13.02.2022 23:00:23 Andy Williams ***@***.***>:
*Device (please complete the following information):*
* > *OS:*
* > *Version:*
* > *Go version:*
* > *Fyne version:*
…
Please complete this information so the bug can be correctly triaged/labelled/reproduced.
—
Reply to this email directly, view it on GitHub[#2775 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AP3FEE6GM7M76OXBWSLKJBTU3ASXNANCNFSM5OJRPVWA].
Triage notifications on the go with GitHub Mobile for iOS[https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675] or Android[https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub].
You are receiving this because you authored the thread. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAoSURBVHic7cEBAQAAAIIg/69uSEABAAAAAAAAAAAAAAAAAAAAAACPBkiEAAHzeIrHAAAAAElFTkSuQmCC###24x24:true###][Verfolgungsbild][https://github.com/notifications/beacon/AP3FEE67GM34WVQJVA6IY5LU3ASXNA5CNFSM5OJRPVWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHXSXTMQ.gif]
|
Issue updated. Device information is now modified. |
Was this closed by mistake @midu-SA ? |
No, I am mit Aware that I closed it...
15.02.2022 17:52:07 Andy Williams ***@***.***>:
… Was this closed by mistake @midu-SA[https://github.com/midu-SA] ?
—
Reply to this email directly, view it on GitHub[#2775 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AP3FEE2FWED65MTCZ2ZJJ3LU3KADLANCNFSM5OJRPVWA].
Triage notifications on the go with GitHub Mobile for iOS[https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675] or Android[https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub].
You are receiving this because you were mentioned. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAoSURBVHic7cEBAQAAAIIg/69uSEABAAAAAAAAAAAAAAAAAAAAAACPBkiEAAHzeIrHAAAAAElFTkSuQmCC###24x24:true###][Verfolgungsbild][https://github.com/notifications/beacon/AP3FEE36ZHBZHTIVYGVB3KTU3KADLA5CNFSM5OJRPVWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHYCQT4Y.gif]
|
Hi Fyne Team I uploaded 3 files: a) modfied file layout/gridlayout.go with added debug information a)
c) However, after the wating of 200 msec the func MinSize still assumes that the objects are available. Kind regards, Mike |
Hi Fyne-Team, Please check if a similar change is needed in file container.go. In this file you also find several loops over all objects, without checking if the object is nil. |
I forgot to mention: I marked my changes in gridlayout.go with "//mdu" |
Just for posterity, I will copy over my answer from Slack. You won't end up with nil objects in the slice. It is the item that is being removed from the slice that is being set to nil to make sure that the GC runs on the element and thus doesn't cause a memory leak. The nil objects are coming from somewhere else. We probably want to add some nil checks in certain places but I think we need to track down and fix where they are coming from first. |
Yes, I also noticed that my argumentation was wrong. The nil objects come from somewhere else... |
I've gone through and cleaned up the testing code to be a bit simpler. I don't think there are any bugs in it, (at least not as far as I can see). The crash also still happens with #2898, so the issue does not occur due to adding any nil items. Looks like we need to debug a bit more as to where they are coming from. package main
import (
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
app := app.NewWithID("Test")
w := app.NewWindow("Test")
w.SetContent(makeUI())
w.Resize(fyne.NewSize(700, 400))
w.ShowAndRun()
}
func makeUI() fyne.CanvasObject {
var grid *fyne.Container
var button1, button2 *widget.Button
const buttonsLength = 50
buttons := make([]fyne.CanvasObject, buttonsLength)
for i := range buttons {
buttons[i] = widget.NewButton(strconv.Itoa(i), nil)
}
button1 = widget.NewButton("Add", func() {
for i := range buttons {
grid.Add(buttons[i])
}
button1.Disable()
button2.Enable()
})
button2 = widget.NewButton("Remove", func() {
for i := buttonsLength - 1; i >= 0; i-- {
grid.Remove(buttons[i])
}
button1.Enable()
button2.Disable()
})
button2.Disable()
grid = container.NewGridWithColumns(20)
return container.NewVBox(button1, button2, grid)
} EDIT: Managed to slim the code down a bit more. I also added a constant to more easily change the amount of buttons. I managed to replicate it with 50 buttons now. Below that, I did not experience the crash. |
Do I understand correctly that with your modified code, you can verify the bug?
Thanks for working on this issue! |
Yes, I can replicate the issue both with the original code and my simplified version. I see the exact same thing with it crashing on removing the items. I ran out of time today and didn't get to do any debugging. |
I tried to debug this in VSCode with delve, but it didn't seem to work very well. It did not show any callstack or local variable and when the crash occurred, it just froze the application without any output or useful stack traces. Someone with GoLand installed might have better luck with the debugging hopefully. |
Closing as duplicate of #2826. I know this opened before, but Ithe issue s tracked down in the other issue. |
This should now be fixed once #2844 lands. |
Describe the bug:
I create 100 buttons (stored in an array), which I alternatingly add into and remove from a grid, using grid.Add() and grid.Remove(). After a while the program crashes.
To Reproduce:
Steps to reproduce the behaviour:
Run the code provided below, where
Now use the add-button and the remove-button alternatingly a few times. After a while the program crashes. The crash does not happen always at the same step. But it always crashes when grid.Remove() is executed. It seems to be a memory problem which is not deterministic, e.g. the crash might happen when button no. 17 is removed, or no. 35 or no. 72, or ...
The output in a terminal is e.g.
Example code:
Device (please complete the following information):
The text was updated successfully, but these errors were encountered: