FyroxEngine/Fyrox · critical
Attempt to get reference to resource data which failed to…
Error message
Attempt to get reference to resource data which failed to load!
What it means
Same guard as the other state checks in deref_mut(): when the resource's load attempt failed, ResourceState::LoadError holds an error, not data. Handing out &mut T is impossible, so the code panics with this message.
Solutions
- Inspect the LoadError payload before touching data: match on resource.state() and log/fix the underlying io/parse error.
- Fix the asset path/extension or re-add the missing file so the load can succeed.
- Register the correct ResourceLoader in ResourceManagerBuilder so the extension maps to a loader.
- Re-request the resource after fixing the cause; failed loads are not automatically retried.
Example fix
// before
let mut data = model.data_mut(); // panics if load failed
// after
if let ResourceState::LoadError { error, .. } = &*model.state() {
eprintln!("model failed to load: {error}");
return;
}
let mut data = model.data_mut(); Defensive patterns
Strategy: validation
Validate before calling
fn resource_ok<T: ResourceData>(r: &Resource<T>) -> bool {
matches!(&*r.state(), ResourceState::Ok { .. })
} Type guard
fn load_error<T: ResourceData>(r: &Resource<T>) -> Option<String> {
if let ResourceState::LoadError { error, .. } = &*r.state() { Some(error.to_string()) } else { None }
} Prevention
- Check state() for LoadError and log the inner error before accessing data.
- Validate asset paths at build/startup time.
- Keep assets in the packaged build (CI check for referenced resources).
- Register all needed loaders in ResourceManagerBuilder.
When it happens
Trigger: Calling deref_mut()/data_mut() on a resource handle whose load previously failed (file missing, parse error, unsupported format), leaving it in ResourceState::LoadError.
Common situations: Typos in asset paths or extensions; asset files deleted/moved after being referenced; malformed resource files; running a packaged game without including assets; missing resource loader registration for the extension.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Attempt to get reference to resource data while it is…
- Graphics context is uninitialized!
- only rectangle textures can be used as render target!
- Graph pool must be empty on load!
- Height data type error
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/7af7453183497027.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-resource/src/lib.rs:642
}
}
}
impl<T> DerefMut for ResourceDataRef<'_, T>
where
T: TypedResourceData,
{
fn deref_mut(&mut self) -> &mut Self::Target {
let header = &mut *self.guard;
match header.state {
ResourceState::Unloaded => {
panic!("Attempt to get reference to resource data while it is unloaded!")
}
ResourceState::Pending { .. } => {
panic!("Attempt to get reference to resource data while it is loading!")
}
ResourceState::LoadError { .. } => {
panic!("Attempt to get reference to resource data which failed to load!")
}
ResourceState::Ok { ref mut data, .. } => (data.inner_mut() as &mut dyn Any)
.downcast_mut()
.expect("Type mismatch!"),
}
}
}
/// Collects all resources used by a given entity. Internally, it uses reflection to iterate over
/// each field of every descendant sub-object of the entity. This function could be used to collect
/// all resources used by an object, which could be useful if you're building a resource dependency
/// analyzer.
pub fn collect_used_resources(
entity: &dyn Reflect,
resources_collection: &mut FxHashSet<UntypedResource>,
) {
#[inline(always)]
fn type_is<T: Reflect>(entity: &dyn Reflect) -> bool {View on GitHub (pinned to 76c91aad8e)