Sokol: Crash on macOS external monitor.

Created on 2 Nov 2020  路  7Comments  路  Source: floooh/sokol

So running the demo app will crash on macOS with an external monitor. I suspect this is a DPI math issue. I had a look around but this is my first time with these headers so don't really know where to start.

Screenshot 2020-11-02 at 08 29 14

bug

All 7 comments

The line

const float dpi_scale = _simgui.desc.dpi_scale;

dpi_scale is always 1 no matter which monitor I'm on.

Thanks for the report, I'll move this ticket over to the sokol repository.

Currently sokol_app.h has no special handling for multi-monitor-setups, which is "by design", but of course nothing should crash, at most stuff should be rendered with the wrong DPI.

It looks like sokol_gfx.h has the wrong idea about the default framebuffer size (the width and height that's passed into sg_begin_default_pass()). If this is bigger than the actual framebuffer size, then any scissor- or viewport-rects will be clipped to the wrong size and Metal complains.

Yeah DPI issues are a pain, I tried to look at it, but I was time bound this morning. I assumed that DPI should be 2 or somesuch on the 'retina' display, but yeah the time thing.

Just for claification, the crash happens if.

  • window spawns on external monitor.
  • window is dragged to external monitor (in this case the inital value is fine)

No worries. I'll see if I can reproduce this by plugging my 1080p PC monitor to my MBP, I have a lot of other things "in flight" currently though, so it might take a little while until I get around to it.

Just taking some notes:

After dragging a 640-pixel-width 'low-dpi' window from a Retina-display to a non-Retina-display, MTKView seems to change the size of its framebuffer to 320-pixels-wide while still reporting a drawableSize of 640. This triggers a Metal assertion when setting the scissor rectangle because the scissor-rect is bigger than the framebuffer size.

Setting MTKView.autoResizeDrawable to false fixes the assertion/crash, but then of course the backing buffer isn't resized automatically.

Potential solution: manually update the drawableSize in windowDidResize event.

Ok, I have committed a fix which disables MTKView.autoResizeDrawable and instead explicitly sets the MTKView drawable size during window resize events.

PS: tested on macOS 11.0.1 and Xcode 12.2

Nevermind, I messed up the Metal-version with the GL-version, the GL backend always had that behaviour. MTKView is behaving fine.

PPS: I just noticed a strange effect on macOS 11.0.1: rendering stops when grabbing a window border with the mouse (as if resizing) but not moving the mouse... rendering only happens during actual resizing... at first I thought that's a bug I introduced with the monitor-change fix, but it also happens when rolling sokol_app.h back to the previous version. So I guess it's a regression in macOS.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

datgame picture datgame  路  6Comments

pjako picture pjako  路  3Comments

siavashserver picture siavashserver  路  6Comments

DomDumont picture DomDumont  路  6Comments

PeterHiber picture PeterHiber  路  5Comments