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 unloaded! Type {}

What it means

Deref on Resource<T> gives direct access to the resource's data only while the resource is in the Ok state. If the resource is still Unloaded (header exists but data not yet loaded) the deref panics, since there is no data to reference. The message includes the concrete T type name.

Solutions

  1. Use the handle without dereferencing (pass Resource<T> to the renderer; it binds by state) and defer data access until state is Ok.
  2. Await the resource: use its state / commit (e.g. resource.state().use_data or awaiting the async load) before dereferencing.
  3. Ensure the resource manager's update is being called so Unloaded resources progress to Pending/Ok.

Example fix

// before
let texture = rm.request::<Texture>(path)?;
let size = texture.data_ref().size(); // panics if still Unloaded
// after
let texture = rm.request::<Texture>(path)?;
if texture.state().is_ok() {
    let size = texture.data_ref().size();
}
Defensive patterns

Strategy: type-guard

Validate before calling

if matches!(&*resource.state(), ResourceState::Ok { .. }) {
    let data = resource.data_ref();
}

Type guard

fn is_loaded<T>(r: &Resource<T>) -> bool { r.state().is_ok() }

Prevention

When it happens

Trigger: Dereferencing a Resource handle immediately after request::<T>(path) in a synchronous context before the async loader has finished; using the resource inside a frame where loading just started.

Common situations: Loading a texture/model and using its data in the same call frame; single-threaded usage without pumping the resource manager's update loop; forgetting that resource loading is asynchronous.

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


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/b75fe7077d76d7b2. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-resource/src/lib.rs:599

                    f,
                    "Attempt to get reference to resource data which failed to load!"
                )
            }
            ResourceState::Ok { ref data, .. } => data.fmt(f),
        }
    }
}

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:?}")

View on GitHub (pinned to 76c91aad8e)