{"record":{"id":"6db195d3718b7335","repo":"FyroxEngine/Fyrox","slug":"attempt-to-get-reference-to-resource-data-while-it-6db195","errorCode":null,"errorMessage":"Attempt to get reference to resource data while it is loading! Type {}","messagePattern":"Attempt to get reference to resource data while it is loading! Type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-resource/src/lib.rs","lineNumber":605,"sourceCode":"    }\n}\n\nimpl<T> Deref for ResourceDataRef<'_, T>\nwhere\n    T: TypedResourceData,\n{\n    type Target = T;\n\n    fn deref(&self) -> &Self::Target {\n        match self.guard.state {\n            ResourceState::Unloaded => {\n                panic!(\n                    \"Attempt to get reference to resource data while it is unloaded! Type {}\",\n                    std::any::type_name::<T>()\n                )\n            }\n            ResourceState::Pending { .. } => {\n                panic!(\n                    \"Attempt to get reference to resource data while it is loading! Type {}\",\n                    std::any::type_name::<T>()\n                )\n            }\n            ResourceState::LoadError {\n                ref path,\n                ref error,\n            } => {\n                let path = if path.as_os_str().is_empty() {\n                    \"Unknown\".to_string()\n                } else {\n                    format!(\"{path:?}\")\n                };\n                panic!(\"Attempt to get reference to resource data which failed to load! Type {}. Path: {path}. Error: {error:?}\", std::any::type_name::<T>())\n            }\n            ResourceState::Ok { ref data } => (data.inner_ref() as &dyn Any)\n                .downcast_ref()\n                .expect(\"Type mismatch!\"),","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-resource/src/lib.rs#L587-L623","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet model = rm.request::<Model>(path)?;\nlet data = model.data_ref(); // panics while loading\n// after\nlet model = rm.request::<Model>(path)?;\nif let ResourceState::Ok(_) = *model.state() {\n    let data = model.data_ref();\n}","handlingStrategy":"retry","validationCode":"if let ResourceState::Pending { .. } = &*resource.state() {\n    // defer usage to next frame / callback\n}","typeGuard":"fn ready<T>(r: &Resource<T>) -> bool { matches!(&*r.state(), ResourceState::Ok { .. }) }","tryCatchPattern":null,"preventionTips":["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."],"tags":["panic","async","resource-state","loading"],"backgroundTag":"invalid-state-transition","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}