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

Resources are marked as !Send and !Sync? #278

Closed
simast opened this issue Sep 11, 2021 · 2 comments
Closed

Resources are marked as !Send and !Sync? #278

simast opened this issue Sep 11, 2021 · 2 comments

Comments

@simast
Copy link

simast commented Sep 11, 2021

Struggling a bit with the Resources container from legion. I want to store terrain heightmap as part of resources, so it is a significant chunk of data. Was just thinking I could create the following struct:

struct Game {
    world: World,
    resources: Resources,
}

And then create a new instance of Game in a separate thread and send it back to the main thread (with thread::spawn and mpsc channels). Basically so I do not block the main UI thread while the game is starting up or being loaded from disk.

But digging in the code I see Resources is actually explicitly marked as not !Send in legion code:

_not_send_sync: PhantomData<*const u8>,

So that does not seem to be an option. Also Resources::insert() consumes the value, so I am really puzzled how can I implement loading of resources in a separate thread here, without resorting to copying and cloning data around.

Any hints or best practices or good examples for Resources usage?

@simast
Copy link
Author

simast commented Sep 12, 2021

Well, after a good nights sleep I figured I can solve this by manually marking mentioned Game struct with a Send:

unsafe impl Send for Game {}

Will close this issue.

@simast simast closed this as completed Sep 12, 2021
@zedrian
Copy link

zedrian commented Sep 12, 2021

Looks like you hacked Legion, but if that works normally, then okay :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants