-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Bevy version
0.16.0
What you did
I've been reading bevy's source code and found this peculiar thing. When SubApp
is being passed as App
to Plugin::build
, a plugin can call any app's function, including App::insert_sub_app
. And then I tested that.
What went wrong
When a plugin is added to a SubApp
the subapp is being passed to the Plugin::build
as an App
with SubApp::run_as_app
workaroung. And that allows all functions of the App
to be called on subapp. The problem with this is when a plugin adds a subapp to a subapp, this new subapp would be dropped in the end of run_as_app
without any crash or even notifying the user.
Additional information
It happens because run_as_app
is creating a "fake" App
and mem::swap
s the target subapp with this "fake" app's main subapp. And after provided closure is called with this app, app's main gets swapped back with the subapp.
So basically, if we have this situation:
before building plugin:
App -> SubAppA
after swap:
SubAppA (as App)
after Plugin::build:
SubAppA (as App) -> SubAppB
after swapping again
App -> SubAppA
The newly added subapp (SubAppB) is left behind on the "fake" app and gets dropped along with it when run_as_app
returns.