macOS Metal Issue - App Crashes Immediately

58 views
Skip to first unread message

Henry M

unread,
Mar 15, 2024, 12:43:39 PMMar 15
to wx-users
I have no issues building and running my wxWidgets project with Xcode 14 on macOS 12.7. However, when building it and running it with Xcode 15 on macOS 14.4, the app crashes once it gets to this line: wxIMPLEMENT_APP(myApp);

I first thought the crash was due to an outdated wxWidgets build, so I rebuilt it with the following commands, but that didn't fix it.

git clone --recurse-submodules https://github.com/wxWidgets/wxWidgets.git ./configure --disable-sys-libs --enable-macosx_arch=x86_64,arm64 make -j5

The stack trace shows that the crash comes from an instruction in MTLInputStageReflectionReader::deserialize(id<MTLDeviceSPI>, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>) (), which is is a Metal library.

Does anyone have any ideas where I should start looking to fix this issue?


Full stack trace: 
Thread 1:
* thread #1, queue = 'com.apple.main-thread' frame #0: 0x00007ff80e105b3e libsystem_kernel.dylib`kevent_id + 10 frame #1: 0x00000001011da866 libdispatch.dylib`_dispatch_kq_poll + 169 frame #2: 0x00000001011db313 libdispatch.dylib`_dispatch_event_loop_wait_for_ownership + 519 frame #3: 0x00000001011c7adb libdispatch.dylib`__DISPATCH_WAIT_FOR_QUEUE__ + 305 frame #4: 0x00000001011c72a5 libdispatch.dylib`_dispatch_sync_f_slow + 222 frame #5: 0x00007ff816834708 QuartzCore`CABackingStoreGetFrontTexture(CABackingStore*, CGColorSpace*) + 180 frame #6: 0x00007ff8168255ce QuartzCore`-[NSObject(CARenderValue) CA_prepareRenderValue] + 175 frame #7: 0x00007ff816a6a005 QuartzCore`CA::Layer::prepare_contents(CALayer*, CA::Transaction*) + 183 frame #8: 0x00007ff816822137 QuartzCore`CA::Layer::prepare_commit(CA::Transaction*) + 293 frame #9: 0x00007ff8169b4e64 QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 978 frame #10: 0x00007ff8167fdd31 QuartzCore`CA::Transaction::commit() + 725 frame #11: 0x00007ff8119e234d AppKit`__62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 285 frame #12: 0x00007ff8124cfe59 AppKit`___NSRunLoopObserverCreateWithHandler_block_invoke + 41 frame #13: 0x00007ff80e21ffa6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 frame #14: 0x00007ff80e21feca CoreFoundation`__CFRunLoopDoObservers + 493 frame #15: 0x00007ff80e21f44c CoreFoundation`__CFRunLoopRun + 850 frame #16: 0x00007ff80e21eb32 CoreFoundation`CFRunLoopRunSpecific + 557 frame #17: 0x00007ff818c30829 HIToolbox`RunCurrentEventLoopInMode + 292 frame #18: 0x00007ff818c30466 HIToolbox`ReceiveNextEventCommon + 201 frame #19: 0x00007ff818c30381 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 66 frame #20: 0x00007ff811886be5 AppKit`_DPSNextEvent + 880 frame #21: 0x00007ff812196fe9 AppKit`-[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1273 frame #22: 0x00007ff811878005 AppKit`-[NSApplication run] + 603 frame #23: 0x0000000102890c6a libwx_osx_cocoau_core-3.3.0.0.0.dylib`wxGUIEventLoop::OSXDoRun() + 186 frame #24: 0x000000010161147d libwx_baseu-3.3.0.0.0.dylib`wxCFEventLoop::DoRun() + 29 frame #25: 0x0000000101548abe libwx_baseu-3.3.0.0.0.dylib`wxEventLoopBase::Run() + 158 frame #26: 0x0000000101511193 libwx_baseu-3.3.0.0.0.dylib`wxAppConsoleBase::MainLoop() + 99 frame #27: 0x00000001028182ba libwx_osx_cocoau_core-3.3.0.0.0.dylib`wxApp::OnRun() + 26 frame #28: 0x000000010158a5b9 libwx_baseu-3.3.0.0.0.dylib`wxEntry(int&, wchar_t**) + 169 * frame #29: 0x00000001000065f3 ctrl+cam`main(argc=1, argv=0x00007ff7bfeff668) at Main.cpp:37:1 frame #30: 0x00007ff80ddb8366 dyld`start + 1942 Thread 2:
* thread #2, queue = 'CA::CG::Queue', stop reason = EXC_BAD_ACCESS (code=1, address=0x700003f8e822) * frame #0: 0x000000010308c0e0 MetalOld.dylib`MTLInputStageReflectionReader::deserialize(id<MTLDeviceSPI>, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>) + 222 frame #1: 0x0000000103117f87 MetalOld.dylib`-[MTLRenderPipelineReflectionInternal initWithVertexData:fragmentData:serializedVertexDescriptor:device:options:flags:] + 207 frame #2: 0x00000001030f8823 MetalOld.dylib`newRenderPipeline(MTLProgramObject*, MTLFunctionVariant*, MTLProgramObject*, MTLFunctionVariant*, MTLProgramObject*, MTLFunctionVariant*, NSObject<OS_dispatch_data>*, MTLProgramObject*, MTLFunctionVariant*, NSObject<OS_dispatch_data>*, _MTLDevice*, NSObject<OS_dispatch_data>*, MTLRenderPipelineDescriptor*, unsigned long, unsigned long, MTLRenderPipelineReflection**, NSMutableDictionary*, NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>*, void (id<MTLRenderPipelineState>, MTLRenderPipelineReflection*, NSError*) block_pointer, NSError*) + 590 frame #3: 0x00000001030ffb9b MetalOld.dylib`__252-[MTLCompiler createVertexStageAndLinkPipelineWithFragment:fragmentVariant:vertexFunction:serializedVertexDescriptor:descriptor:destinationArchive:options:reflection:compileStatistics:fragmentCompileTimeData:pipelineArchiverId:error:completionHandler:]_block_invoke_2 + 395 frame #4: 0x00000001030fef3a MetalOld.dylib`-[MTLCompiler createVertexStageAndLinkPipelineWithFragment:fragmentVariant:vertexFunction:serializedVertexDescriptor:descriptor:destinationArchive:options:reflection:compileStatistics:fragmentCompileTimeData:pipelineArchiverId:error:completionHandler:] + 1890 frame #5: 0x0000000103101cfb MetalOld.dylib`__128-[MTLCompiler newRenderPipelineStateWithDescriptorInternal:options:reflection:destinationBinaryArchive:error:completionHandler:]_block_invoke_2 + 378 frame #6: 0x0000000103100c9f MetalOld.dylib`-[MTLCompiler newRenderPipelineStateWithDescriptorInternal:options:reflection:destinationBinaryArchive:error:completionHandler:] + 2988 frame #7: 0x00000001030181d8 MetalOld.dylib`-[MTLCompiler newRenderPipelineStateWithDescriptor:options:reflection:error:completionHandler:] + 27 frame #8: 0x000000010309b25b MetalOld.dylib`-[_MTLDevice newRenderPipelineStateWithDescriptor:options:reflection:error:] + 76 frame #9: 0x00007ff80e9982a9 MetalTools`-[MTLDebugDevice _newRenderPipelineStateWithDescriptor:options:reflection:error:] + 717 frame #10: 0x00007ff80e99846b MetalTools`-[MTLDebugDevice newRenderPipelineStateWithDescriptor:error:] + 40 frame #11: 0x00007ff8168582c4 QuartzCore`CA::OGL::MetalContext::create_pipeline_state(CA::OGL::MetalContext::Pipeline::Spec const&, unsigned int*, std::__1::atomic<bool>*) + 5538 frame #12: 0x00007ff816a233af QuartzCore`CA::OGL::MetalContext::draw(MTLPrimitiveType, unsigned int, unsigned int, void const*, unsigned long, unsigned long, unsigned int, unsigned int, unsigned short const*, CA::OGL::ClipPlane const*, CA::OGL::MetalBufferPool::MetalBuffer const*) + 13569 frame #13: 0x00007ff816854b34 QuartzCore`CA::OGL::MetalContext::draw_elements(CA::OGL::PrimitiveMode, unsigned int, unsigned short const*, CA::OGL::Vertex const*, unsigned int, unsigned int, CA::OGL::ClipPlane const*) + 110 frame #14: 0x00007ff816854a85 QuartzCore`CA::OGL::Context::array_flush() + 55 frame #15: 0x00007ff816a740bb QuartzCore`CA::OGL::emit_combine(CA::OGL::Context&, CA::OGL::TextureFunction, CA::OGL::Surface*, int, CA::OGL::Surface*, int, CA::Shape const*, CA::Vec4<float> const&) + 1268 frame #16: 0x00007ff8168544ce QuartzCore`CA::CG::FillRects::draw_shape(CA::CG::Renderer&) const + 682 frame #17: 0x00007ff816851f6f QuartzCore`CA::CG::DrawOp::render(CA::CG::Renderer&) const + 3835 frame #18: 0x00007ff81684e5a5 QuartzCore`CA::CG::Queue::render_callback(void*) + 1391 frame #19: 0x00000001011b6a7b libdispatch.dylib`_dispatch_client_callout + 8 frame #20: 0x00000001011be429 libdispatch.dylib`_dispatch_lane_serial_drain + 1397 frame #21: 0x00000001011bf121 libdispatch.dylib`_dispatch_lane_invoke + 431 frame #22: 0x00000001011cc21b libdispatch.dylib`_dispatch_root_queue_drain_deferred_wlh + 301 frame #23: 0x00000001011cb770 libdispatch.dylib`_dispatch_workloop_worker_thread + 490 frame #24: 0x0000000100421370 libsystem_pthread.dylib`_pthread_wqthread + 327 frame #25: 0x0000000100427beb libsystem_pthread.dylib`start_wqthread + 15

Also, I should mention that on the newer Mac, I'm able to build (from the command line) all the wxWidgets OpenGL samples and the wxWidgets minimal sample and run them without issue.

Vadim Zeitlin

unread,
Mar 15, 2024, 3:00:38 PMMar 15
to wx-u...@googlegroups.com
On Fri, 15 Mar 2024 09:43:38 -0700 (PDT) Henry M wrote:

HM> I have no issues building and running my wxWidgets project with Xcode 14 on
HM> macOS 12.7. However, when building it and running it with Xcode 15 on macOS
HM> 14.4, the app crashes once it gets to this line: wxIMPLEMENT_APP(myApp);

Sorry, I don't have Xcode 15 yet, so I can't test this and all I can say
is that "this line" is the application entry point, so it doesn't really
say much. Also, the crash doesn't happen in the main thread.

HM> I first thought the crash was due to an outdated wxWidgets build, so I
HM> rebuilt it with the following commands, but that didn't fix it.
HM>
HM> git clone --recurse-submodules
HM> https://github.com/wxWidgets/wxWidgets.git ./configure --disable-sys-libs
HM> --enable-macosx_arch=x86_64,arm64 make -j5

Does this happen only with the universal builds or with just arm64 one
too?

HM> The stack trace shows that the crash comes from an instruction in
HM> MTLInputStageReflectionReader::deserialize(id<MTLDeviceSPI>,
HM> NSObject<OS_dispatch_data>*, NSObject<OS_dispatch_data>) (), which is is a
HM> Metal library.
HM>
HM> Does anyone have any ideas where I should start looking to fix this issue?

As wx doesn't Metal at all, it's really difficult to say, unfortunately.

HM> Also, I should mention that on the newer Mac, I'm able to build (from the
HM> command line) all the wxWidgets OpenGL samples and the wxWidgets minimal
HM> sample and run them without issue.

The usual advice is to start bisecting the problem, i.e. reduce your
application code, by disabling parts of it, until the issue disappears.

Good luck,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/

Henry M

unread,
Mar 21, 2024, 4:11:09 PMMar 21
to wx-users
VZ> Does this happen only with the universal builds or with just arm64 one
too?

I'm on an x86_64 Mac, but it happens with the universal builds as well as the x86_64 build

I tried your advice (reducing my application code until the issue disappears) by commenting out a large chunk of the GUI setup code, and my app ran without crashing. However, clicking on any button or menu item causes the same Metal-related crash.

I did more experiments with the environment—I tried downgrading to the MacOS 13.1 SDK, but that didn't fix it. I tried downloading Xcode 14, but Xcode 14 won't run on macOS 14. So I made a bootable USB with macOS 13 and Xcode 14, and the app runs perfectly using the exact same Xcode project.

I then exported the build commands from both Xcode 15 and Xcode 14 and did a git diff on them. There are numerous differences. I can post both files somewhere if anyone wants to see them.

Anyways, I'm currently circumventing the problem by using a bash script made up of all the Xcode 14 build commands.

Conclusion: I think the problem is the interaction between wxWidgets and Xcode 15.

Vadim Zeitlin

unread,
Mar 21, 2024, 5:40:42 PMMar 21
to wx-u...@googlegroups.com
On Thu, 21 Mar 2024 13:11:08 -0700 (PDT) Henry M wrote:

HM> I tried your advice (reducing my application code until the issue
HM> disappears) by commenting out a large chunk of the GUI setup code, and my
HM> app ran without crashing. However, clicking on any button or menu item
HM> causes the same Metal-related crash.

But this doesn't happen with the sample, does it? If it doesn't, it means
that there is still something in your application which triggers the
problem.

HM> Conclusion: I think the problem is the interaction between wxWidgets and
HM> Xcode 15.

This is good to know, but unfortunately doesn't help with fixing it. And
having a way to reproduce it in the minimal sample would still be very
helpful, so if you can change it to show it, it would be great.

Thanks,
Reply all
Reply to author
Forward
0 new messages