-
Notifications
You must be signed in to change notification settings - Fork 10
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
Use std::sync::Arc<cosmic-text::Buffer>
in bevy component
#146
Conversation
copy on write shouldn't happen with current code changes, right? |
seems like i was hitting some copy-on-write stuff? not sure
That's what I was thinking but I'm a bit new to the concept. I think that anything that touches the buffer while it's in an editor would cause a copy? Unsure, but I did break text centering when using the single buffer so there must still be two allocations somewhere |
I see, what do you think about |
Cosmic text doesn't accept a mutex, that's what tripped me up when I tried
this before
…On Wed, 5 Jun 2024, 16:06 Dimchikkk, ***@***.***> wrote:
I see, what do you think about Arc<Mutex<...>> ? :)
—
Reply to this email directly, view it on GitHub
<#146 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKMCYIY632YFOXLDIA4DE4DZF4SOPAVCNFSM6AAAAABI2VV3EWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJQGMYDQMJSHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I think the solution is that we can never use Having all of this be hidden from the user would be ideal. Perhaps the |
I want to undestand issue better xD a bit lost |
Internally I think that if our code never calls The problem is that we'd like user code and plugin code to be able to modify a buffer, both when it is not owned by an So the solution I'm thinking of is tracking when a given buffer is owned by an editor, and redirecting any modifications through the editor reference when it is, while still being able to directly modify the buffer when it's not in an editor, without the user having to use different functions. I think that this could be done with pattern matching on the result of All the problems that are solved with a |
I think with the borrowed version we run into lifetime issues, holding a mutable borrow to the buffer past the function's return. Maybe a static lifetime saves us here, maybe not After a bit more reading I feel even the Arc approach will always lead to a forced clone, as the bevy component holds an Arc at the same time the editor calls make_mut. I'll make another branch and try out my optional call redirection idea, perhaps using a shared trait on the CosmicBuffer and CosmicEditor wrappers for simplicity, and the public impl on the buffer can decide which call should be used based on some sort of editor relationship stored on the buffer wrapper. Another approach could be to store the editor and buffer in a struct, and then that decides where to send the calls to buffer functions? Lots of thinking out loud, I'll have a play around and see what I come up with |
Nice, have a nice play :D |
closing for now |
I'm not too sure about using
make_mut
whenever modification to the buffer is needed, as I don't have the best understanding of copy-on-write and how that will work, though I'd like to think bevy's scheduler will prevent race conditions.Needs a fair bit more testing, but this change should remove the need for double checking the editor buffer everywhere there could be two, as there is now one buffer per widget.
Fixes #145
Fixes #138 (untested so far)