Update init_resource to not overwrite (#1349)
Update init_resource to not overwrite
This commit is contained in:
parent
8e0e4223e5
commit
b922a3ec60
@ -235,8 +235,13 @@ impl AppBuilder {
|
|||||||
where
|
where
|
||||||
R: FromResources + Send + Sync + 'static,
|
R: FromResources + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let resource = R::from_resources(&self.app.resources);
|
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed not to
|
||||||
self.app.resources.insert(resource);
|
// modify the map. However, we would need to be borrowing resources both mutably and immutably,
|
||||||
|
// so we would need to be extremely certain this is correct
|
||||||
|
if !self.resources().contains::<R>() {
|
||||||
|
let resource = R::from_resources(&self.resources());
|
||||||
|
self.add_resource(resource);
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -245,8 +250,11 @@ impl AppBuilder {
|
|||||||
where
|
where
|
||||||
R: FromResources + 'static,
|
R: FromResources + 'static,
|
||||||
{
|
{
|
||||||
let resource = R::from_resources(&self.app.resources);
|
// See perf comment in init_resource
|
||||||
self.app.resources.insert_thread_local(resource);
|
if self.app.resources.get_thread_local::<R>().is_none() {
|
||||||
|
let resource = R::from_resources(&self.app.resources);
|
||||||
|
self.app.resources.insert_thread_local(resource);
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,9 +177,7 @@ impl Plugin for RenderPlugin {
|
|||||||
shader::clear_shader_defs_system.system(),
|
shader::clear_shader_defs_system.system(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if app.resources().get::<Msaa>().is_none() {
|
app.init_resource::<Msaa>();
|
||||||
app.init_resource::<Msaa>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref config) = self.base_render_graph_config {
|
if let Some(ref config) = self.base_render_graph_config {
|
||||||
let resources = app.resources();
|
let resources = app.resources();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user