From 3cd619850c77967b14ab7cfe139a92cdf65f3c45 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 8 Feb 2026 15:00:28 +0100 Subject: sokol_app.h ios/mtl: fix drawable size mismatch assert on rotate (see https://github.com/floooh/sokol/issues/1437) --- sokol_app.h | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/sokol_app.h b/sokol_app.h index 7fa97330..3b965980 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -6215,16 +6215,23 @@ _SOKOL_PRIVATE void _sapp_ios_mtl_discard_state(void) { } _SOKOL_PRIVATE bool _sapp_ios_mtl_update_framebuffer_dimensions(CGRect screen_rect) { - _sapp.framebuffer_width = _sapp_roundf_gzero(screen_rect.size.width * _sapp.dpi_scale); - _sapp.framebuffer_height = _sapp_roundf_gzero(screen_rect.size.height * _sapp.dpi_scale); - const CGSize fb_size = _sapp.ios.view.drawableSize; - int cur_fb_width = _sapp_roundf_gzero(fb_size.width); - int cur_fb_height = _sapp_roundf_gzero(fb_size.height); - bool dim_changed = (_sapp.framebuffer_width != cur_fb_width) || (_sapp.framebuffer_height != cur_fb_height); - if (dim_changed) { - const CGSize drawable_size = { (CGFloat) _sapp.framebuffer_width, (CGFloat) _sapp.framebuffer_height }; + // get current screen size and if it changed, update the MTKView drawable size + const int screen_width = _sapp_roundf_gzero(screen_rect.size.width * _sapp.dpi_scale); + const int screen_height = _sapp_roundf_gzero(screen_rect.size.height * _sapp.dpi_scale); + const CGSize view_size = _sapp.ios.view.drawableSize; + const int view_width = _sapp_roundf_gzero(view_size.width); + const int view_height = _sapp_roundf_gzero(view_size.height); + const bool needs_update = (screen_width != view_width) || (screen_height != view_height); + if (needs_update) { + const CGSize drawable_size = { (CGFloat) screen_width, (CGFloat) screen_height }; _sapp.ios.view.drawableSize = drawable_size; } + // now separately, get the current drawable's size + const int cur_fb_width = _sapp_roundf_gzero(_sapp.ios.view.currentDrawable.texture.width); + const int cur_fb_height = _sapp_roundf_gzero(_sapp.ios.view.currentDrawable.texture.height); + const bool dim_changed = (cur_fb_width != _sapp.framebuffer_width) || (cur_fb_height != _sapp.framebuffer_height); + _sapp.framebuffer_width = cur_fb_width; + _sapp.framebuffer_height = cur_fb_height; return dim_changed; } #endif @@ -6366,6 +6373,11 @@ _SOKOL_PRIVATE void _sapp_ios_update_dimensions(void) { } _SOKOL_PRIVATE void _sapp_ios_frame(void) { + // NOTE: it's not great to call _sapp_ios_update_dimensions() so early in + // the frame, since this calls MTKView.currentDrawable, which should be + // delayed until the latest possible moment (e.g. sapp_get_swapchain()). + // MTKView is on the chopping block anyway though, so don't bother too much + // getting it right until MTKView is replaced with CAMetalLayer. _sapp_ios_update_dimensions(); _sapp_frame(); } -- cgit v1.2.3 From c3101666c29bd23afd443cf407d4009bd7c3e290 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sun, 8 Feb 2026 15:08:42 +0100 Subject: update changelog (https://github.com/floooh/sokol/pull/1438) --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02789ce3..ec7486c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ ## Updates +### 08-Feb-2026 + +- sokol_app.h ios/mtl: Fix a spurious assert when applying scissor rect after + rotating the device and which might lead to a drawable-size mismatch. This + doesn't appear to be 100% watertight but works much better than + before. The assert might be the result of a behaviour change in MTKView + between iOS versions (which tbh wouldn't be the first time this happened). + A 'perfect' solution will need to wait until the next round of iOS/macOS + window system glue updates which will finally get rid of MTKView and instead + use `CAMetalLayer` and `CADisplayLink` directly. Until then it's definitely + recommended to disable display rotation for your application via the Info.plist + file. Many thanks to @ArMuSebastian for writing the issue and providing + a simple reproducer. + + Issue: https://github.com/floooh/sokol/issues/1437 + PR: https://github.com/floooh/sokol/pull/1438 + ### 03-Feb-2026 - sokol_gfx.h vulkan: another round of small fixes and code cleanups in the -- cgit v1.2.3