diff options
| author | Andre Weissflog <floooh@gmail.com> | 2026-02-08 15:43:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-08 15:43:39 +0100 |
| commit | d48aa2ff673af2d6b981032dd43766ab15689163 (patch) | |
| tree | 6294e28de27159e71465eead68d349e1b2c34caa | |
| parent | f693b9e646d2cc46132a6bcbfc6b43f4c165fce8 (diff) | |
| parent | c3101666c29bd23afd443cf407d4009bd7c3e290 (diff) | |
Merge pull request #1438 from floooh/issue1437/ios_pass_dimensions
sokol_app.h ios/mtl: Fix drawable size mismatch assert on rotate
| -rw-r--r-- | CHANGELOG.md | 17 | ||||
| -rw-r--r-- | sokol_app.h | 28 |
2 files changed, 37 insertions, 8 deletions
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 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(); } |