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
|
||||
R: FromResources + Send + Sync + 'static,
|
||||
{
|
||||
let resource = R::from_resources(&self.app.resources);
|
||||
self.app.resources.insert(resource);
|
||||
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed not to
|
||||
// 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
|
||||
}
|
||||
@ -245,8 +250,11 @@ impl AppBuilder {
|
||||
where
|
||||
R: FromResources + 'static,
|
||||
{
|
||||
let resource = R::from_resources(&self.app.resources);
|
||||
self.app.resources.insert_thread_local(resource);
|
||||
// See perf comment in init_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
|
||||
}
|
||||
|
||||
@ -177,9 +177,7 @@ impl Plugin for RenderPlugin {
|
||||
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 {
|
||||
let resources = app.resources();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user