better error message: specify which resource is missing (#1648)
This commit is contained in:
parent
86e2fc53d0
commit
ac661188c8
@ -234,7 +234,12 @@ impl<'a, T: Component> SystemParamFetch<'a> for ResState<T> {
|
|||||||
) -> Self::Item {
|
) -> Self::Item {
|
||||||
let column = world
|
let column = world
|
||||||
.get_populated_resource_column(state.component_id)
|
.get_populated_resource_column(state.component_id)
|
||||||
.expect("Requested resource does not exist");
|
.unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"Requested resource does not exist: {}",
|
||||||
|
std::any::type_name::<T>()
|
||||||
|
)
|
||||||
|
});
|
||||||
Res {
|
Res {
|
||||||
value: &*column.get_ptr().as_ptr().cast::<T>(),
|
value: &*column.get_ptr().as_ptr().cast::<T>(),
|
||||||
flags: *column.get_flags_mut_ptr(),
|
flags: *column.get_flags_mut_ptr(),
|
||||||
@ -371,7 +376,12 @@ impl<'a, T: Component> SystemParamFetch<'a> for ResMutState<T> {
|
|||||||
) -> Self::Item {
|
) -> Self::Item {
|
||||||
let value = world
|
let value = world
|
||||||
.get_resource_unchecked_mut_with_id(state.component_id)
|
.get_resource_unchecked_mut_with_id(state.component_id)
|
||||||
.expect("Requested resource does not exist");
|
.unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"Requested resource does not exist: {}",
|
||||||
|
std::any::type_name::<T>()
|
||||||
|
)
|
||||||
|
});
|
||||||
ResMut {
|
ResMut {
|
||||||
value: value.value,
|
value: value.value,
|
||||||
flags: value.flags,
|
flags: value.flags,
|
||||||
@ -603,7 +613,12 @@ impl<'a, T: 'static> SystemParamFetch<'a> for NonSendState<T> {
|
|||||||
NonSend {
|
NonSend {
|
||||||
value: world
|
value: world
|
||||||
.get_non_send_with_id::<T>(state.component_id)
|
.get_non_send_with_id::<T>(state.component_id)
|
||||||
.expect("Requested non-send resource does not exist"),
|
.unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"Requested non-send resource does not exist: {}",
|
||||||
|
std::any::type_name::<T>()
|
||||||
|
)
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -692,7 +707,12 @@ impl<'a, T: 'static> SystemParamFetch<'a> for NonSendMutState<T> {
|
|||||||
) -> Self::Item {
|
) -> Self::Item {
|
||||||
let value = world
|
let value = world
|
||||||
.get_non_send_unchecked_mut_with_id(state.component_id)
|
.get_non_send_unchecked_mut_with_id(state.component_id)
|
||||||
.expect("Requested non-send resource does not exist");
|
.unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"Requested non-send resource does not exist: {}",
|
||||||
|
std::any::type_name::<T>()
|
||||||
|
)
|
||||||
|
});
|
||||||
NonSendMut {
|
NonSendMut {
|
||||||
value: value.value,
|
value: value.value,
|
||||||
flags: value.flags,
|
flags: value.flags,
|
||||||
|
|||||||
@ -620,15 +620,15 @@ impl World {
|
|||||||
let component_id = self
|
let component_id = self
|
||||||
.components
|
.components
|
||||||
.get_resource_id(TypeId::of::<T>())
|
.get_resource_id(TypeId::of::<T>())
|
||||||
.expect("resource does not exist");
|
.unwrap_or_else(|| panic!("resource does not exist: {}", std::any::type_name::<T>()));
|
||||||
let (ptr, mut flags) = {
|
let (ptr, mut flags) = {
|
||||||
let resource_archetype = self.archetypes.resource_mut();
|
let resource_archetype = self.archetypes.resource_mut();
|
||||||
let unique_components = resource_archetype.unique_components_mut();
|
let unique_components = resource_archetype.unique_components_mut();
|
||||||
let column = unique_components
|
let column = unique_components.get_mut(component_id).unwrap_or_else(|| {
|
||||||
.get_mut(component_id)
|
panic!("resource does not exist: {}", std::any::type_name::<T>())
|
||||||
.expect("resource does not exist");
|
});
|
||||||
if column.is_empty() {
|
if column.is_empty() {
|
||||||
panic!("resource does not exist");
|
panic!("resource does not exist: {}", std::any::type_name::<T>());
|
||||||
}
|
}
|
||||||
// SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of
|
// SAFE: if a resource column exists, row 0 exists as well. caller takes ownership of
|
||||||
// the ptr value / drop is called when T is dropped
|
// the ptr value / drop is called when T is dropped
|
||||||
@ -644,7 +644,7 @@ impl World {
|
|||||||
let unique_components = resource_archetype.unique_components_mut();
|
let unique_components = resource_archetype.unique_components_mut();
|
||||||
let column = unique_components
|
let column = unique_components
|
||||||
.get_mut(component_id)
|
.get_mut(component_id)
|
||||||
.expect("resource does not exist");
|
.unwrap_or_else(|| panic!("resource does not exist: {}", std::any::type_name::<T>()));
|
||||||
// SAFE: new location is immediately written to below
|
// SAFE: new location is immediately written to below
|
||||||
let row = unsafe { column.push_uninit() };
|
let row = unsafe { column.push_uninit() };
|
||||||
// SAFE: row was just allocated above
|
// SAFE: row was just allocated above
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user