DioxusLabs/dioxus · error
from_raw called with a null pointer
Error message
from_raw called with a null pointer
What it means
manganis generates Objective-C wrappers for Xcode asset-catalog APIs. from_raw converts a raw AnyObject pointer into an objc2 Retained wrapper, and Retained::from_raw returns None when the pointer is null, so a nil object coming back from the Objective-C side triggers this expect inside the generated code.
Source
Thrown at packages/manganis/manganis-macro/src/ffi.rs:849
// `alloc` + `init` returns a +1 retained object; `Retained::from_raw`
// takes over that reference and sends `release` on drop.
let inner = manganis::objc2::rc::Retained::from_raw(instance)
.ok_or("Failed to initialize instance")?;
Ok(Self { inner })
}
}
/// Create from an existing object pointer.
///
/// # Safety
///
/// `ptr` must be a valid, non-null pointer to an Objective-C object,
/// and the caller must transfer ownership of one retain count (+1)
/// to the returned wrapper, which sends `release` on drop.
pub unsafe fn from_raw(ptr: *mut manganis::objc2::runtime::AnyObject) -> Self {
let inner = manganis::objc2::rc::Retained::from_raw(ptr)
.expect("from_raw called with a null pointer");
Self { inner }
}
}
};
output.extend(type_def);
}
// Generate function implementations
for func in &self.functions {
let func_code = self.generate_ios_function(func);
output.extend(func_code);
}
// Generate linker metadata
let metadata = self.generate_ios_metadata();
output.extend(metadata);
// Wrap in cfgView on GitHub (pinned to 393d190a80)
Solutions
- Check for null/nil on the Objective-C side before passing the pointer into from_raw
- Verify the requested asset name exists in the asset catalog
- Audit ownership: from_raw must receive a +1 retain count exactly once
- Prefer nullable/Option-returning API variants instead of non-null from_raw wrappers
Defensive patterns
Strategy: type-guard
Validate before calling
// unsafe { if ptr.is_null() { /* handle nil result instead of calling from_raw */ } } Type guard
// Generated-wrapper equivalent of a nullable check:
unsafe fn try_from_raw(ptr: *mut AnyObject) -> Option<Wrapper> {
if ptr.is_null() { None } else { Some(Wrapper::from_raw(ptr)) }
} Prevention
- Audit every objc API you bind for nil-returning failure modes and mark those as nullable
- Verify asset names exist in the .xcassets before requesting them
- Follow the +1 retain-count contract exactly once per from_raw call
- Add null checks on the Swift/ObjC side before bridging pointers out
When it happens
Trigger: Calling a generated objc2 binding whose underlying Objective-C API returned nil (lookup miss such as a named asset/color not present in the .xcassets, allocation failure), or an ownership bug where the pointer was already released before from_raw.
Common situations: iOS asset catalog integration requesting an asset name that doesn't exist; double-release making the pointer nil; hand-written bridging code with wrong retain/release counts.
Related errors
- Failed to deserialize asset. Make sure you built with the ma
- todo: convert_resize_data in dioxus-native. requires support
- todo: convert_visible_data in dioxus-native. requires suppor
- expected URL to be UTF-8 encoded
- Failed to get asset manager
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/ea9b6940f4062ca7.
Report an issue: GitHub.