On Xcode13.0,my Metal-app successfully run on independent or in Xcode-Instrument, but crash on debugging,why?

I have an App,use Metal-api, it worked well at Xcode12, but when I upgrade Xcode13.0,things changed, it always crash at newFunctionWithName.

How do I get my metal library:

  • My app is multiple-render-backend, so my shader is .glsl, use glslangValidator turn it to .metal
  • get metallib,refrence : Building a Library with Metal's Command-Line Tools,
  • use dispatch_data_create to load metallib, and call newLibraryWithData to get MTLLibrary, then call newFunctionWithNameto get MTLFunction , crash here.

Because it's my company's code,so SORRY, I can't share the code or screenshot.

The same code, worked on Xcode11 and Xcode12,but crash at Xcode13.0 when use Xcode to debug.

Xcode13.0: crash at debug, but successfully run on independent or in Xcode-Instrument.

I have no clue, what should I do to solve this problem on Xcode13.0, or it's the bug on Xcode13.0? @Apple

ps: (that problem above occurred on x86_64-mac,macOS 11.5)

Accepted Reply

Hi BenjaminLee,

When launching your application via Xcode, a the app is subject to a few environment changes that Xcode does in order to help you test your application. The debugger is connected to the program, the Metal Debug and Validation layers may be enabled, there might even be instrumentation that halts the app if a memory problem is detected.

If you can share what the platform error message you are obtaining is, we might be able to help you narrow down the cause. If this is not possible, I would recommend to start disabling debugging capabilities in the Xcode scheme to make your app's environment more closely resemble a standalone launch. That way you can narrow down which component is triggering the crash.

  • Hello, apple engineer: Firstly, thanks for your reply. I solved this problem yesterday, the truly reason is the command param "-MO" of "xcrun -sdk macosx metallib", it's deprecated since Xcode13.0(this isn't stated in release note,luckly in document of metal-lib). The details you can see above that I replied to David(user-account r2d3).

    I wanna describe the detailed situation that I have went through, maybe can help others: when I keep "-MO" like before, and then use Xcode13.0 to debug/release my Application, it crashed at newFunctionWithName, with error tip" EXC_BAD_ACCESS (code=2, address=0x700001d9fff8)",the address can be different every time. When I run application not via Xcode, such as via double click, or viaMetal Instrument, it won't crash. Lastly, I still have two question, I still don't know the meaning of "-MO", and why "-frecord-sources"still cause crash. Best wishes, @apple
  • I run "xcrun -sdk macosx metal --help  | grep MO", and get "Embed sources and driver options into output",what does it mean?

  • Hi. If we can retrieve a crash report of the issue from the latest Xcode we will better be able to investigate and help diagnose the issue. Please see "Create a Crash Report While Debugging" in this article for how to do that. If you can retrieve a crash report I suggest sharing it in a Feedback Assistant report and share the report ID here.

Add a Comment

Replies

Hello Benjamin,

the workaround I found is to disable GPU Frame Capture.

Menu Product | Scheme | Edit Scheme. under the Options tab, set GPU Frame Capture to disabled

Regards

David

Post not yet marked as solved Up vote reply of r2d3 Down vote reply of r2d3
  • Hello David:

    I have confirmed, your workaround solution worked for me , then it won't crash when debug via Xcode13.0! Unluckly,my leader hopes me to find the truly reason, because we manage project through CMake,it won't be convenient that click Xcode-option every time.But, thanks for your help so much anyway! So, I spent whole day to narrow down the real issue, **finally, I found the real problem** is the command param of generating metallib file. Xcode13.0 deprecate the option '-MO',if I keep this option, the crash will come. By the way , I found another thing,Apple says that Xcode13.0 add a new option "-frecord-sources", it also crash, I don't know why, so I didn't use it.

    you can search "MO" in this web page for more information: Generating and Loading a Metal Library Symbol File (ps: Markdown grammar doesn't work?emm..) Best wishes, Benjamin

  • oh, I want to choose you as finally answer, but I click mistakenly.....

Add a Comment

Hi BenjaminLee,

When launching your application via Xcode, a the app is subject to a few environment changes that Xcode does in order to help you test your application. The debugger is connected to the program, the Metal Debug and Validation layers may be enabled, there might even be instrumentation that halts the app if a memory problem is detected.

If you can share what the platform error message you are obtaining is, we might be able to help you narrow down the cause. If this is not possible, I would recommend to start disabling debugging capabilities in the Xcode scheme to make your app's environment more closely resemble a standalone launch. That way you can narrow down which component is triggering the crash.

  • Hello, apple engineer: Firstly, thanks for your reply. I solved this problem yesterday, the truly reason is the command param "-MO" of "xcrun -sdk macosx metallib", it's deprecated since Xcode13.0(this isn't stated in release note,luckly in document of metal-lib). The details you can see above that I replied to David(user-account r2d3).

    I wanna describe the detailed situation that I have went through, maybe can help others: when I keep "-MO" like before, and then use Xcode13.0 to debug/release my Application, it crashed at newFunctionWithName, with error tip" EXC_BAD_ACCESS (code=2, address=0x700001d9fff8)",the address can be different every time. When I run application not via Xcode, such as via double click, or viaMetal Instrument, it won't crash. Lastly, I still have two question, I still don't know the meaning of "-MO", and why "-frecord-sources"still cause crash. Best wishes, @apple
  • I run "xcrun -sdk macosx metal --help  | grep MO", and get "Embed sources and driver options into output",what does it mean?

  • Hi. If we can retrieve a crash report of the issue from the latest Xcode we will better be able to investigate and help diagnose the issue. Please see "Create a Crash Report While Debugging" in this article for how to do that. If you can retrieve a crash report I suggest sharing it in a Feedback Assistant report and share the report ID here.

Add a Comment

How did you finally solve the crash after enabling GPU Frame Capture. I'm currently having the same problem

  • Hi. Are you able to retrieve the crash log? Please see "Create a Crash Report While Debugging" in this article if it only occurs while debugging your application. If you can file a Feedback Assistant Report (and share the Feedback ID here) with the crash and as much details as possible (what you're doing, and/or minimal reproducing sample) we can better investigate the issue.

  • I have submit feedback to developer tool, feedback id is  FB9921296 MTLLibraryDataWithArchive::readFunctionSourceArchiveMetadata is real crash point.

  • i did a test.

    download

    OfficialExample

    run

    xcrun --sdk iphoneos metal -miphoneos-version-min=11.0 -gline-tables-only -std=ios-metal2.0 -c -frecord-sources my_mac_path/UsingARenderPipelineToRenderPrimitives/Renderer/AAPLShaders.metal -o destAirPath/AAPLShaders.air

    run

    xcrun --sdk iphoneos metal -frecord-sources destAirPath/AAPLShaders.air -o destMetalLib/AAPLShaders.metallib

    add the metallib to project, and load the library with newLibraryWithFile, reference

    Offical Article

    if i enable metal gpu frame capture, it must be crash while execute newFunctionWIthName on xcode 13.0

    if remove -gline-tables-only and -frecord-sources, regenerate metallib, run, it's ok.

Add a Comment

have any solution?@Graphics and Games Engineer