{"record":{"id":"b75fe7077d76d7b2","repo":"FyroxEngine/Fyrox","slug":"attempt-to-get-reference-to-resource-data-while-it","errorCode":null,"errorMessage":"Attempt to get reference to resource data while it is unloaded! Type {}","messagePattern":"Attempt to get reference to resource data while it is unloaded! Type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-resource/src/lib.rs","lineNumber":599,"sourceCode":"                    f,\n                    \"Attempt to get reference to resource data which failed to load!\"\n                )\n            }\n            ResourceState::Ok { ref data, .. } => data.fmt(f),\n        }\n    }\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:?}\")","sourceCodeStart":581,"sourceCodeEnd":617,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-resource/src/lib.rs#L581-L617","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the handle without dereferencing (pass Resource<T> to the renderer; it binds by state) and defer data access until state is Ok.","Await the resource: use its state / commit (e.g. resource.state().use_data or awaiting the async load) before dereferencing.","Ensure the resource manager's update is being called so Unloaded resources progress to Pending/Ok."],"exampleFix":"// before\nlet texture = rm.request::<Texture>(path)?;\nlet size = texture.data_ref().size(); // panics if still Unloaded\n// after\nlet texture = rm.request::<Texture>(path)?;\nif texture.state().is_ok() {\n    let size = texture.data_ref().size();\n}","handlingStrategy":"type-guard","validationCode":"if matches!(&*resource.state(), ResourceState::Ok { .. }) {\n    let data = resource.data_ref();\n}","typeGuard":"fn is_loaded<T>(r: &Resource<T>) -> bool { r.state().is_ok() }","tryCatchPattern":null,"preventionTips":["Treat resource loading as asynchronous: never use data in the same frame as request().","Use state checks or await/commit APIs before data_ref().","Pass Resource handles (not data) to render code, which tolerates unloaded resources."],"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"}