File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,14 +14,21 @@ thread_local! {
1414}
1515
1616pub fn app_mut < T > ( cb : impl FnOnce ( & mut App ) -> error:: Result < T > ) -> error:: Result < T > {
17- let res = APP . with ( |app_cell| {
18- let mut app_borrow = app_cell. borrow_mut ( ) ;
17+ // `try_with` so a `Drop` running after the TLS is destroyed sees an
18+ // `AppAccess` error rather than panicking
19+ let res = APP . try_with ( |app_cell| {
20+ let mut app_borrow = app_cell
21+ . try_borrow_mut ( )
22+ . map_err ( |_| error:: ProcessingError :: AppAccess ) ?;
1923 let app = app_borrow
2024 . as_mut ( )
2125 . ok_or ( error:: ProcessingError :: AppAccess ) ?;
2226 cb ( app)
23- } ) ?;
24- Ok ( res)
27+ } ) ;
28+ match res {
29+ Ok ( inner) => inner,
30+ Err ( _) => Err ( error:: ProcessingError :: AppAccess ) ,
31+ }
2532}
2633
2734pub fn is_already_init ( ) -> error:: Result < bool > {
Original file line number Diff line number Diff line change @@ -1017,7 +1017,7 @@ mod mewnala {
10171017 return Ok ( ( ) ) ;
10181018 }
10191019
1020- Python :: attach ( |py| {
1020+ let result : PyResult < ( ) > = Python :: attach ( |py| {
10211021 let builtins = PyModule :: import ( py, "builtins" ) ?;
10221022 let locals = builtins. getattr ( "locals" ) ?. call0 ( ) ?;
10231023
@@ -1138,7 +1138,13 @@ mod mewnala {
11381138 }
11391139
11401140 Ok ( ( ) )
1141- } )
1141+ } ) ;
1142+
1143+ // tear the app down here while the TLS is still alive; the eager
1144+ // TLS destructor aborts inside a Bevy resource drop
1145+ let _ = :: processing:: exit ( 0 ) ;
1146+
1147+ result
11421148 }
11431149
11441150 #[ pyfunction]
You can’t perform that action at this time.
0 commit comments