Replies: 4 comments 11 replies
-
As you said, changing variables content in another goroutine needs to lock the memory (with Actually, Fyne let you manage the memory as you want, and that's right for a lot of others packages. So to respond the last quest, in my opinion, it's no 😄 For your example, I would create a custom widget ( |
Beta Was this translation helpful? Give feedback.
-
To propose something that "works" in my laptop, here is a gist: https://gist.github.com/metal3d/d6e295bef424ad18f801bf7f026f0019 The proposed example in the conversation was a good start, but the gist is tested. The widget correctly set the image with lock. Fyne does not read the image until you don't call It is, theoretically, OK. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this @metal3d - the toolkit could probably do more to make this easier. |
Beta Was this translation helpful? Give feedback.
-
The fact is that the canvas.Image is not a widget. It's a fine.CanvasObject
and this is why I proposed to create a custom widget to implement the
setter.
Actually, it could be enough to simply propose a widget.Image. isn't it ?
Le mar. 5 sept. 2023, 18:18, Drew Weymouth ***@***.***> a
écrit :
… Personally I'd be in favor of adding setters for widget properties. Keeps
the locking complexity hidden from the user, and the setters would ensure
that no data race will occur. Leave the exported properties but document
that setting them directly is only for constructors (eg when making
extended widgets). I also think this is a low-priority issue. I have a Fyne
app that uses images heavily and updates them from goroutines by just
setting the .Image property and I haven't hit the race condition (that I
know of).
—
Reply to this email directly, view it on GitHub
<#4213 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAYN4FGVP2HUYM6RW7AENLXY5GEPANCNFSM6AAAAAA4IXTWVU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Currently, I'm creating a
canvas.Image
image in the main goroutine as:And in another goroutine, I'm updating it as:
Although that seems to work. it does not feel correct to set that variable without a lock.
Is that the correct way to modify the image?
Should a
canvas.Image.SetImage
function exist?Beta Was this translation helpful? Give feedback.
All reactions