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

[Merged by Bors] - [assets] Fix AssetServer::get_handle_path #2310

Closed

Conversation

NathanSWard
Copy link
Contributor

@NathanSWard NathanSWard commented Jun 6, 2021

Objective

  • Currently AssetServer::get_handle_path always returns None since the inner hash map is never written to.

Solution

  • Inside the load_untracked function, insert the asset path into the map.

This is similar to #1290 (thanks @TheRawMeatball)

@NathanSWard NathanSWard added A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior labels Jun 6, 2021
@NathanSWard
Copy link
Contributor Author

A few notes:

This PR unblocks
#2306
#2268

I would like to write some tests for this, however, I would like that base that off of #2226

@cart
Copy link
Member

cart commented Jun 7, 2021

So doing this in load_async creates timing issues that could affect the PRs mentioned above (as discussed in #1290). If we're going to rely on this for things like serialization / deserialization, I don't think we can have nondeterministic behavior based on whether or not a load_async task has been run yet. In some cases, "behavior that cannot be relied upon" is worse than "consistently not working correctly".

@NathanSWard
Copy link
Contributor Author

So doing this in load_async creates timing issues that could affect the PRs mentioned above (as discussed in #1290). If we're going to rely on this for things like serialization / deserialization, I don't think we can have nondeterministic behavior based on whether or not a load_async task has been run yet. In some cases, "behavior that cannot be relied upon" is worse than "consistently not working correctly".

This is all fair.
However, it worries me that we have to grab the RwLock via write() inside the load_untracked function directly.
Also not only that, but if someone calls

asset_server.load("mypath");

multiple times, the value keeps getting overwritten.

I guess we could do something like:

if self.handle_to_path.read().contains(&handle_id) {
    self.handle_to_path.write().insert(handle_id, asset_path.clone());
}

Actually now thinking about it, this isn't the worst solution.

@NathanSWard
Copy link
Contributor Author

Just updated the PR to add the path in the load_untracked function to avoid the nondeterministic behavior.

@cart
Copy link
Member

cart commented Jun 7, 2021

Actually now thinking about it, this isn't the worst solution.

Honestly its probably not great. For the "happy path" where asset_server.load("my_path") is called exactly once (which is likely going to be very common), we've added an additional read() lock and hashmap lookup.

Just doing unconditional write().insert() is much better for that case.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Jun 7, 2021
@NathanSWard
Copy link
Contributor Author

NathanSWard commented Jun 7, 2021

Honestly its probably not great. For the "happy path" where asset_server.load("my_path") is called exactly once (which is likely going to be very common), we've added an additional read() lock and hashmap lookup.

I'm not the biggest fan on banking on the called exactly once argument, however, since it does make sense that this is the happy and common path, I'm ok with removing the read call.

@NathanSWard NathanSWard removed the S-Needs-Triage This issue needs to be labelled label Jun 7, 2021
@cart
Copy link
Member

cart commented Jun 8, 2021

I'm not the biggest fan on banking on the called exactly once argument

I'd argue that your impl is banking on the "called more than once argument" 😄
This is just a choice about what call pattern we intend to encourage. And I think "reusing handles" is the pattern we should encourage.

@NathanSWard
Copy link
Contributor Author

I'd argue that your impl is banking on the "called more than once argument" 😄

That's fair 😛

This is just a choice about what call pattern we intend to encourage. And I think "reusing handles" is the pattern we should encourage.

Yep! I complete agree with the argument that we should we should encourage handle reuse!

And the PR is currently updated with the write only call.
So it should be good to merge.
Ideally I'd like to add testing but the tests I'd like to base off #2226 but I'm happy to have this merged first and then I'll follow up with a PR adding tests.

@cart
Copy link
Member

cart commented Jun 8, 2021

Cool I think this is good to go, but I just merged #2226 and I'm happy to wait for tests 😄

@NathanSWard
Copy link
Contributor Author

Cool I think this is good to go, but I just merged #2226 and I'm happy to wait for tests 😄

thanks! just added the tests!

@NathanSWard NathanSWard requested a review from mockersf June 8, 2021 16:48
@NathanSWard
Copy link
Contributor Author

This PR should be ready to go now with the additional testing :)

@cart
Copy link
Member

cart commented Jun 9, 2021

bors r+

bors bot pushed a commit that referenced this pull request Jun 9, 2021
# Objective

- Currently `AssetServer::get_handle_path` always returns `None` since the inner hash map is never written to.

## Solution

- Inside the `load_untracked` function, insert the asset path into the map.

This is similar to #1290 (thanks @TheRawMeatball)
@bors bors bot changed the title [assets] Fix AssetServer::get_handle_path [Merged by Bors] - [assets] Fix AssetServer::get_handle_path Jun 9, 2021
@bors bors bot closed this Jun 9, 2021
@NathanSWard NathanSWard mentioned this pull request Jun 9, 2021
2 tasks
ostwilkens pushed a commit to ostwilkens/bevy that referenced this pull request Jul 27, 2021
# Objective

- Currently `AssetServer::get_handle_path` always returns `None` since the inner hash map is never written to.

## Solution

- Inside the `load_untracked` function, insert the asset path into the map.

This is similar to bevyengine#1290 (thanks @TheRawMeatball)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants