Skip to content

Commit bb99267

Browse files
Benoît Rouleaunot-fl3
authored andcommitted
ios: implement required mtkView:drawableSizeWillChange: selector
`MTKViewDelegate` declares two `@required` methods: `mtkView:drawableSizeWillChange:` and `drawInMTKView:`. The `QuadViewDlg` class only registered the latter, so any actual drawable-size change (window resize, rotation under a non-locked orientation set, split-view drag on iPad) crashed: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[QuadViewDlg mtkView:drawableSizeWillChange:]: unrecognized selector sent to instance 0x...' ... [MTKView _resizeDrawable] ... [UIView setFrame:] ... [UIWindow _rotateWindowToOrientation:...] Reproduced on the iPad Air 11-inch simulator on iOS 27 by rotating the device. Did not reproduce on the iPhone 17 simulator there because CHOMP's Info.plist locks orientation, so the drawable size never actually changes. Implementation is a stub: `draw_in_rect` already polls `UIScreen.mainScreen.bounds` every frame and emits `Message::Resize` on a delta, so a no-op satisfies the protocol without changing the existing resize path.
1 parent 413218d commit bb99267

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/native/ios.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ pub fn define_glk_or_mtk_view_dlg(superclass: &Class) -> *const Class {
376376
draw_in_rect(this, s, o, nil);
377377
}
378378

379+
// `MTKViewDelegate` requires both `drawInMTKView:` AND
380+
// `mtkView:drawableSizeWillChange:`. MTKView invokes the
381+
// size-change selector before the first `drawInMTKView:` after
382+
// any drawable-size change (window resize, rotation under a
383+
// non-locked orientation set, split-view drag on iPad). Without
384+
// an implementation, `_resizeDrawable` raises
385+
// `NSInvalidArgumentException` and crashes the process.
386+
//
387+
// The real resize handling lives in `draw_in_rect`, which polls
388+
// `UIScreen.mainScreen.bounds` every frame and emits
389+
// `Message::Resize` on a delta — so a stub is enough here.
390+
extern "C" fn drawable_size_will_change(_: &Object, _: Sel, _: ObjcId, _: NSSize) {}
391+
379392
unsafe {
380393
decl.add_method(
381394
sel!(glkView: drawInRect:),
@@ -386,6 +399,11 @@ pub fn define_glk_or_mtk_view_dlg(superclass: &Class) -> *const Class {
386399
sel!(drawInMTKView:),
387400
draw_in_rect2 as extern "C" fn(&Object, Sel, ObjcId),
388401
);
402+
403+
decl.add_method(
404+
sel!(mtkView: drawableSizeWillChange:),
405+
drawable_size_will_change as extern "C" fn(&Object, Sel, ObjcId, NSSize),
406+
);
389407
}
390408

391409
decl.add_ivar::<*mut c_void>("display_ptr");

0 commit comments

Comments
 (0)