Skip to content

Commit 48c0832

Browse files
committed
fix(ios): dynamic drawable resize on orientation change
Query the actual view bounds each frame in begin_drawing and resize the Metal drawable + wgpu surface to match. Fixes distorted rendering when the app starts in portrait but locks to landscape.
1 parent dc316df commit 48c0832

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

native/ios/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,27 @@ pub extern "C" fn bloom_window_should_close() -> f64 {
607607
pub extern "C" fn bloom_begin_drawing() {
608608
// No run loop pumping needed — UIApplicationMain handles the main run loop
609609
// on its own thread. The game runs on the game thread.
610+
611+
// Update drawable size to match actual view bounds (handles orientation changes)
612+
unsafe {
613+
if let Some(view) = &UI_VIEW {
614+
let view_ptr = Retained::as_ptr(view);
615+
let layer: Retained<AnyObject> = msg_send![&*view_ptr, layer];
616+
let view_bounds: CGRect = msg_send![&*view_ptr, bounds];
617+
let scale = SCREEN_SCALE;
618+
let pw = (view_bounds.size.width * scale) as u32;
619+
let ph = (view_bounds.size.height * scale) as u32;
620+
let eng = engine();
621+
if pw > 0 && ph > 0 && (pw != eng.renderer.width() || ph != eng.renderer.height()) {
622+
let ds = CGSize { width: pw as f64, height: ph as f64 };
623+
let _: () = msg_send![&*layer, setDrawableSize: ds];
624+
eng.renderer.resize(pw, ph);
625+
} else {
626+
eng.begin_frame();
627+
return;
628+
}
629+
}
630+
}
610631
engine().begin_frame();
611632
}
612633

0 commit comments

Comments
 (0)