You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently if I want to a) execute a system only if a certain resource has been modified and b) to modify that resource in that system, I can do something like this:
Welp this prints out an ever increasing number so I'm gonna go ahead and say this is UB unless I have a fundamental misunderstanding of how resources work x]
use bevy::prelude::*;fnmain(){App::build().add_default_plugins().add_startup_system(startup.system()).add_system(ub.system()).run();}pubstructMyRes(Vec<usize>);pubfnstartup(mutcommands:Commands){
commands.insert_resource(MyRes(vec![0]));}pubfnub(res_1:Res<MyRes>,mutres_2:ResMut<MyRes>){dbg!("start of the system");for i in0..res_1.0.len(){dbg!(res_1.0[i]);
res_2.0.push(i);}}
Activity
[-]Introduce mutable version of ChangeRes<>[/-][+]Introduce mutable version of ChangedRes<>[/+]BoxyUwU commentedon Sep 29, 2020
wait that first code snippet works... Isn't that totally UB by providing a &MyRes and an &mut MyRes??
BoxyUwU commentedon Sep 29, 2020
Welp this prints out an ever increasing number so I'm gonna go ahead and say this is UB unless I have a fundamental misunderstanding of how resources work x]
ropewalker commentedon Sep 29, 2020
@EllenNyan I am not a big expert in smart pointers, but isn't the logic in your example the same as in the following?
At least I would intuitively expect resources to work somewhat like this.
BoxyUwU commentedon Sep 29, 2020
Resources in bevy aren't using Rc<RefCell<T>>, Res<T> internally just contains an &'a T, ResMut<T> stores a *mut T internally.
For what it's worth, for each systems have the same issue.
this will print out a constantly ascending number :)
ropewalker commentedon Sep 29, 2020
FWIW, this doesn't panic and does go infinite:
alice-i-cecile commentedon Feb 17, 2021
This should be solved by #1313.
alice-i-cecile commentedon Mar 7, 2021
Double-checking: @TheRawMeatball is this resolved now?
TheRawMeatball commentedon Mar 7, 2021
Yes, it is. Closing.
Update petgraph requirement from 0.6 to 0.7 (#18224)