Closed SnoutBug closed 10 months ago
This code has a race condition: all calls to GTK widgets (lbl.SetText
in this case) must be synchronized with glib.IdleAdd
, like so:
go func() {
// blocking call...
glib.IdleAdd(func() { label.SetText(...) })
}()
Also, prefer using ConnectDrop(...)
over Connect("drop", ...)
.
I think this issue need to be reopened. That does not seem to work.
The app crashed regardless no matter if I used glib.IdleAdd(...)
or not. Additionally the app also crashed when I didn't set the label in the go routine. I also tried to include readDir(...)
inside glib.IdleAdd(...)
which did not work either (that also locks the UI which I wanted to avoid).
The app always crashed with the same error.
ConnectDrop(...)
does not work as mentioned in #107.
The culprit seems to be os.ReadDir(...)
:
If I put
for {
os.ReadDir("/home/me")
}
inside either glib.IdleAdd(...)
or the go routine directly, the program will crash eventually. It seems like you need to hit the right timing, though.
What version of gotk4/pkg
are you on? Can you try v0.1.0
?
Whoops, I put the wrong issue number in there.
ConnectDrop
should work now, but the latest commit will also include commit 96fbd78af598f729089e8165fc68bed3abb2683e which is a very unstable/experimental commit that I'm not confident will be stable.
If you see any crashes occuring at package intern
, please make an issue.
What version of gotk4/pkg are you on?
I think I was on @0.0.6
if I am not mistaken.
Can you try v0.1.0?
I tried @0.1.0
with no success, the app would crash regardless.
I also tried the @4
branch directly, allowing me to use ConnectDrop(...)
which worked flawlessly with the go routine, as far as I could tell.
However, Connect("drop"...)
still did not work.
However,
Connect("drop"...)
still did not work.
This is acceptable. Connect("x")
should ideally never be used. I'm only keeping it around just in case it's necessary for some reason.
That works fine for me. Since I can now use the alternative I consider this issue resolved. Thanks a bunch for your help :)
I wanted to start a somewhat heavy task (counting files in directories recursively) after the user dropped the directory onto a DropTarget.
For that I use the following code in order for the GUI not to lock up: (for simplicity I hard coded the path for now)
The code for readDir, or simply filepath.Walk
For testing purposes I plugged the code into the
dragndrop
example you provided. After execution the program will sometimes, but not always crash with:Is this a bug or am I approaching this issue the wrong way?