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

Bug in asset loading #10695

Closed
torsteingrindvik opened this issue Nov 22, 2023 · 6 comments · Fixed by #10698
Closed

Bug in asset loading #10695

torsteingrindvik opened this issue Nov 22, 2023 · 6 comments · Fixed by #10698
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior

Comments

@torsteingrindvik
Copy link
Contributor

torsteingrindvik commented Nov 22, 2023

Bevy version

Using git bisect show 57a175f as the commit which introduced the issue.
cc @bushrat011899

What you did

Run my Bevy app.

What went wrong

Panic in asset on getting infos.

For me it seems to relate to loading things within a gltf model- if I add some more logging around the bad unwrap I see the asset path is stuff like a Mesh1 or Animation1 within one of my gltf models.

Additional information

Other discord users hit the same issue:

https://discordapp.com/channels/691052431525675048/749332104487108618/1176633456835428453

That backtrace points to:

let info = self.infos.get_mut(&id).unwrap();

which I have hit as well.

But I have also hit this one:

.expect("Asset info should always exist at this point");

and the same discord user has hit this one:

.expect("Asset info should always exist at this point");

@torsteingrindvik torsteingrindvik added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 22, 2023
@DasLixou
Copy link
Contributor

Found it.
Your mentioned PR added hashing the typeid next to the asset id for Handles: https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/handle.rs#L225-L226
But the typeid is already hashed inside AssetId: https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/id.rs#L118-L119
So we are hashing the typeid 2 times for a typed asset id.
I wonder how the tests, which should assert that typed and untyped are the same didnt fail

@bushrat011899
Copy link
Contributor

I'll start looking into this once I get home. That commit should only have a handful of observable changes that could even be the cause of any change in behavior.

@bushrat011899
Copy link
Contributor

Found it.
Your mentioned PR added hashing the typeid next to the asset id for Handles: https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/handle.rs#L225-L226
But the typeid is already hashed inside AssetId: https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/id.rs#L118-L119
So we are hashing the typeid 2 times for a typed asset id.
I wonder how the tests, which should assert that typed and untyped are the same didnt fail

The UntypedAssetId and handle should have the exact same hashing function as the typed version, including hashing the type twice. If that is the cause, I'm even more confused.

@bushrat011899
Copy link
Contributor

bushrat011899 commented Nov 22, 2023

This looks like a race condition, likely the same one in #10688 Nope completely unrelated. Running alien_cake_addict multiple times in release mode (same binary) will produce anything from a crash on load, through to running the game correctly, through to not loading some of the models, etc.

@DasLixou
Copy link
Contributor

Found it.
Your mentioned PR added hashing the typeid next to the asset id for Handles: https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/handle.rs#L225-L226
But the typeid is already hashed inside AssetId: https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/id.rs#L118-L119
So we are hashing the typeid 2 times for a typed asset id.
I wonder how the tests, which should assert that typed and untyped are the same didnt fail

The UntypedAssetId and handle should have the exact same hashing function as the typed version, including hashing the type twice. If that is the cause, I'm even more confused.

Really sorry to tell you:
https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/handle.rs#L395-L396
https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/id.rs#L283-L284
May the confusion be with you :>

@bushrat011899
Copy link
Contributor

Below is an example of one of the times alien_cake_addict ran, but clearly failed to load assets:

image

@nicopap nicopap added A-Assets Load files from disk to use for things like images, models, and sounds and removed S-Needs-Triage This issue needs to be labelled labels Nov 22, 2023
github-merge-queue bot pushed a commit that referenced this issue Nov 22, 2023
# Objective

- Fixes #10695

## Solution

Fixed obvious blunder in `PartialEq` implementation for
`UntypedAssetId`'s where the `TypeId` was not included in the
comparison. This was not picked up in the unit tests I added because
they only tested over a single asset type.
github-merge-queue bot pushed a commit that referenced this issue Nov 23, 2023
# Objective

There is a double hash for the typeid for asset handles. (see
[this](#10695 (comment))
for more info)

## Solution

- Remove the second hash of the typeid
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
# Objective

- Fixes bevyengine#10695

## Solution

Fixed obvious blunder in `PartialEq` implementation for
`UntypedAssetId`'s where the `TypeId` was not included in the
comparison. This was not picked up in the unit tests I added because
they only tested over a single asset type.
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
# Objective

There is a double hash for the typeid for asset handles. (see
[this](bevyengine#10695 (comment))
for more info)

## Solution

- Remove the second hash of the typeid
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 a pull request may close this issue.

4 participants