Fix empty nodes crash (#38259)

localcc created

The crash occured because we raced against the platform windowing
backend to render a frame, and if we lost the race there would be no
frame on a window that we return, which breaks most of gpui

Release Notes:

- N/A

Change summary

crates/gpui/src/app.rs | 8 ++++++++
1 file changed, 8 insertions(+)

Detailed changes

crates/gpui/src/app.rs 🔗

@@ -958,6 +958,14 @@ impl App {
                     cx.window_update_stack.pop();
                     window.root.replace(root_view.into());
                     window.defer(cx, |window: &mut Window, cx| window.appearance_changed(cx));
+
+                    // allow a window to draw at least once before returning
+                    // this didn't cause any issues on non windows platforms as it seems we always won the race to on_request_frame
+                    // on windows we quite frequently lose the race and return a window that has never rendered, which leads to a crash
+                    // where DispatchTree::root_node_id asserts on empty nodes
+                    let clear = window.draw(cx);
+                    clear.clear();
+
                     cx.window_handles.insert(id, window.handle);
                     cx.windows.get_mut(id).unwrap().replace(window);
                     Ok(handle)