{"record":{"id":"ede2d49d21f55759","repo":"FyroxEngine/Fyrox","slug":"type-mismatch","errorCode":null,"errorMessage":"Type mismatch!","messagePattern":"Type mismatch!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"fyrox-resource/src/lib.rs","lineNumber":623,"sourceCode":"                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!\"),\n        }\n    }\n}\n\nimpl<T> DerefMut for ResourceDataRef<'_, T>\nwhere\n    T: TypedResourceData,\n{\n    fn deref_mut(&mut self) -> &mut Self::Target {\n        let header = &mut *self.guard;\n        match header.state {\n            ResourceState::Unloaded => {\n                panic!(\"Attempt to get reference to resource data while it is unloaded!\")\n            }\n            ResourceState::Pending { .. } => {\n                panic!(\"Attempt to get reference to resource data while it is loading!\")\n            }\n            ResourceState::LoadError { .. } => {","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-resource/src/lib.rs#L605-L641","documentation":"ResourceDataRef::deref casts the internally stored resource data (as &dyn Any) down to the requested type T and panics if the cast fails. This means the concrete Resource<T> handle being dereferenced does not actually hold data of type T — a programming/type confusion bug, not a load failure.","triggerScenarios":"Dereferencing a Resource<T> whose handle was produced from a differently-typed resource (e.g. via UntypedResource::try_cast or clone of a resource of another type), or after unsafely mixing typed/untyped resource APIs.","commonSituations":"Casting an UntypedResource to the wrong model type and calling data_ref(); passing a Texture where a Model is expected; generic code that lost the concrete type of the resource.","solutions":["Check the resource's actual type before dereferencing (e.g. untyped.procedural_data_source / instance_id type, or use UntypedResource::try_cast::<T>() and handle None).","Ensure the Resource<T> handle came from the correctly typed load call (resource_manager.request::<Model, _>(path) etc.).","In generic code, use downcast_ref::<T>() manually with a graceful error instead of blindly dereferencing."],"exampleFix":"// before\nlet model: UntypedResource = ...;\nlet data = model.try_cast::<Texture>().unwrap();\nlet tex = data.data_ref(); // panics: actually a Model\n// after\nif let Some(tex_res) = model.try_cast::<Texture>() {\n    let tex = tex_res.data_ref();\n} else {\n    Log::err(\"Resource is not a Texture\");\n}","handlingStrategy":"type-guard","validationCode":"if untyped.try_cast::<T>().is_none() {\n    // handle wrong-typed resource before calling data_ref()\n}","typeGuard":"fn is_of_type<T: ResourceData>(r: &UntypedResource) -> bool { r.try_cast::<T>().is_some() }","tryCatchPattern":null,"preventionTips":["Use try_cast instead of casting and dereferencing directly","Keep resources in their concrete typed handles"],"tags":["type-mismatch","downcast","panic","resource"],"backgroundTag":"type-mismatch","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"}