FyroxEngine/Fyrox · error
Attempt to get reference to resource data while it is…
Error message
Attempt to get reference to resource data while it is loading! Type {} What it means
Deref on Resource<T> also panics while the resource is in the Pending state, i.e. the data is actively being loaded on another task. No data is available yet, so the panic reports 'while it is loading' with the type name.
Solutions
- Wait for the load to complete before dereferencing: await the resource or check state().is_ok().
- Render/use the handle itself (renderer handles Pending resources) instead of its data.
- Register a callback (ResourceEventBundles / on-loaded hook) to consume the data once Ok.
Example fix
// before
let model = rm.request::<Model>(path)?;
let data = model.data_ref(); // panics while loading
// after
let model = rm.request::<Model>(path)?;
if let ResourceState::Ok(_) = *model.state() {
let data = model.data_ref();
} Defensive patterns
Strategy: retry
Validate before calling
if let ResourceState::Pending { .. } = &*resource.state() {
// defer usage to next frame / callback
} Type guard
fn ready<T>(r: &Resource<T>) -> bool { matches!(&*r.state(), ResourceState::Ok { .. }) } Prevention
- Consume resource data only from a load-completed callback or after awaiting the future.
- Keep per-frame polls of pending resources instead of blocking/dereferencing immediately.
- Track pending resources in a queue and process them once they become Ok.
When it happens
Trigger: Dereferencing a resource handle whose background load task has not completed; checking/dereferencing in the same frame the request was issued in an async/parallel loading setup.
Common situations: Streaming world content and touching resource data before load completion; long loads (large textures/network paths) making the race window obvious; using a stale handle to a resource that was re-requested and is reloading.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Attempt to get reference to resource data while it is…
- Attempt to get reference to resource data while it is…
- Attempt to get reference to resource data while it is…
- Attempt to get reference to resource data which failed to…
- Animation pool must be empty on load!
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/6db195d3718b7335.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-resource/src/lib.rs:605
}
}
impl<T> Deref for ResourceDataRef<'_, T>
where
T: TypedResourceData,
{
type Target = T;
fn deref(&self) -> &Self::Target {
match self.guard.state {
ResourceState::Unloaded => {
panic!(
"Attempt to get reference to resource data while it is unloaded! Type {}",
std::any::type_name::<T>()
)
}
ResourceState::Pending { .. } => {
panic!(
"Attempt to get reference to resource data while it is loading! Type {}",
std::any::type_name::<T>()
)
}
ResourceState::LoadError {
ref path,
ref error,
} => {
let path = if path.as_os_str().is_empty() {
"Unknown".to_string()
} else {
format!("{path:?}")
};
panic!("Attempt to get reference to resource data which failed to load! Type {}. Path: {path}. Error: {error:?}", std::any::type_name::<T>())
}
ResourceState::Ok { ref data } => (data.inner_ref() as &dyn Any)
.downcast_ref()
.expect("Type mismatch!"),View on GitHub (pinned to 76c91aad8e)