bevyengine / bevyengine/bevy

LoadContext.get_handle() returns invalid or dropped handles

Open
#4,371 1 comment 0 reactions 0 assignees View on GitHub
A-Assets C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.6.1

## Operating system & version

Windows 10

## What you did

1. Create a custom `AssetLoader`
2. Create sub-asset resources, such as `StandardMaterial`s, and save them to the current `LoadContext` via `load_context.set_labeled_asset(label, LoadedAsset::new(asset))`
3. Reference these sub-asset resources via `let path = AssetPath::new_ref(load_context.path(), Some(label))`
4. Get a handle to the resource at the path `load_context.get_handle(path)`

5. Spawn entities with these handles

Repro documented in https://github.com/agg23/bevy_loadcontext_example

## What you expected to happen

With the bug repro code above, we would expect to see a 10x10 grid of cubes of various colors (`StandardMaterial`s) every time the program is run:

![bevy_test_2022-03-30_15-51-14](https://user-images.githubusercontent.com/238679/160945064-b80df3b8-8757-45d4-9fa5-363507bbd941.png)

## What actually happened

However, this complete grid appears rarely, and most of the time, many materials don't render:

![bevy_test_2022-03-30_15-51-25](https://user-images.githubusercontent.com/238679/160945130-09d259e5-960a-4c45-8d0f-b833bab3262f.png)

Inspecting using `bevy_editor_pls` shows the entities as we'd expect, but the material handles don't resolve to anything:

![bevy_test_2022-03-30_15-51-33](https://user-images.githubusercontent.com/238679/160945255-62de34a9-45cb-480f-9b73-752228d09c95.png)

Contributor guide

Open the contributing guide

Research direction

Start with the linked bevy_loadcontext_example and trace the custom AssetLoader flow through LoadContext.set_labeled_asset, AssetPath::new_ref, and LoadContext.get_handle. Reproduce the issue on Bevy 0.6.1 and verify that spawned entities consistently resolve their StandardMaterial handles and render the complete grid.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.