AlexHarker / AHarker_Externals

A Set of 80+ Externals for a variety of tasks in MaxMSP.
BSD 3-Clause "New" or "Revised" License
68 stars 5 forks source link

Some externals crashing on macOS 11.3 and Apple M1 #15

Closed kylemcdonald closed 3 years ago

kylemcdonald commented 3 years ago

Steps to reproduce after installing Max 8 and Xcode:

  1. Clone https://github.com/AlexHarker/AHarker_Externals.git
  2. Download Max 8 SDK Version 8.0.3 https://cycling74.com/downloads/sdk and unzip. Copy the contents of source/ into AHarker_Externals/AH_Max_SDK
  3. Open and edit Config_AHarker_Externals.xcconfig and change MACOSX_DEPLOYMENT_TARGET = 11.3 and ARCHS = x86_64 and SKIP_INSTALL = NO and DSTROOT = $(SRCROOT)/../../build
  4. Open AH Externals.xcodeproj and Product>Build.
  5. You will see two errors in AH_VectorOps.h saying Constant expression evaluates to 9223372036854775808 which cannot be narrowed to type 'long long'. Click on the "Fix" button twice which will change line 387 to static const vSInt64 max_negative = {static_cast<long long>(0x8000000000000000), static_cast<long long>(0x8000000000000000)};
  6. Product>Clean Build Folder and Product>Build again.
  7. Open the AHarker_Externals/build folder and verify that the externals are present.
  8. Open Max and create a new patcher. Save the patcher in AHarker_Externals/build.
  9. Check that some externals work: create a [ macaddress ] object, patch it to [ print ] and bang it.
  10. Check that other externals crash: create a [ timeconvolve~ ] and Max crashes with MacOS reporting the error at the bottom of this post. I tested across a few different categories, here are a list of crashing externals:

And here are some working externals:

I was able to get [ macaddress ] to crash by adding a property double param; to typedef struct macaddress and then adding the line x->param = 1; inside macaddress_new(). Interestingly, if param is an int type (long, int etc) then it does not crash.

Process:               Max [2474]
Path:                  /Applications/Max.app/Contents/MacOS/Max
Identifier:            com.cycling74.Max
Version:               8.1.11 [17de540] (8.1.11)
Code Type:             X86-64 (Translated)
Parent Process:        ??? [1]
Responsible:           Max [2474]
User ID:               501

Date/Time:             2021-06-27 13:34:30.817 -0700
OS Version:            macOS 11.3 (20E232)
Report Version:        12
Anonymous UUID:        F597B9C8-DAE5-21C0-D355-0324D82A40CB

Sleep/Wake UUID:       A05788FB-3E5C-4DDA-A540-3809709E1573

Time Awake Since Boot: 2500000 seconds
Time Since Wake:       11000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  CrBrowserMain  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Illegal instruction: 4
Termination Reason:    Namespace SIGNAL, Code 0x4
Terminating Process:   exc handler [2474]

Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   partconvolve-                   0x0000000162553fe1 main + 1185 (partconvolve~.cpp:188)
1   com.cycling74.Max               0x0000000102cff06e external_bundleload + 1036
2   com.cycling74.Max               0x0000000102cfebc9 external_load + 135
3   com.cycling74.Max               0x0000000102e007b3 class_load + 301
4   com.cycling74.Max               0x0000000102e00837 class_findbyname_casefree + 118
5   com.cycling74.Max               0x0000000102ece4d5 jnewobj_enter + 421
6   com.cycling74.Max               0x0000000102dfedcb object_method_imp + 340
7   com.cycling74.Max               0x0000000102efff47 jpatchercontroller_entertext_imp + 493
8   com.cycling74.Max               0x0000000102f072e9 jpatchercontroller_entertext + 191
9   com.cycling74.Max               0x0000000102e3c790 TextfieldComponent::endEdit() + 590
10  com.cycling74.Max               0x0000000102e5a109 BoxComponent::endEdit() + 99
11  com.cycling74.Max               0x0000000102e3af94 TextfieldTextEditor::keyPressed(juce::KeyPress const&) + 834
12  com.cycling74.Max               0x000000010353e7d0 juce::ComponentPeer::handleKeyPress(juce::KeyPress const&) + 320
13  com.cycling74.Max               0x0000000103540eaf juce::NSViewComponentPeer::handleKeyEvent(NSEvent*, bool) + 847
14  com.cycling74.Max               0x00000001035410fd juce::NSViewComponentPeer::redirectKeyDown(NSEvent*) + 61
15  com.cycling74.Max               0x000000010353d130 juce::JuceNSViewClass::keyDown(objc_object*, objc_selector*, NSEvent*) + 304
16  com.apple.AppKit                0x00007fff22d4eee8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6482
17  com.apple.AppKit                0x00007fff22d4d376 -[NSWindow(NSEventRouting) sendEvent:] + 347
18  com.apple.AppKit                0x00007fff22d4c1f1 -[NSApplication(NSEvent) sendEvent:] + 3021
19  com.cycling74.Max               0x000000010305df9d swizzle_SendEvent(objc_object*, objc_selector*, NSEvent*) + 109
20  com.apple.AppKit                0x00007fff23024979 -[NSApplication _handleEvent:] + 65
21  com.apple.AppKit                0x00007fff22bb469e -[NSApplication run] + 623
22  org.chromium.ContentShell.framework 0x000000011426fa0c cef_time_delta + 2877996
23  org.chromium.ContentShell.framework 0x000000011426e7d3 cef_time_delta + 2873331
24  org.chromium.ContentShell.framework 0x000000011422bf7a cef_time_delta + 2600858
25  org.chromium.ContentShell.framework 0x00000001141fdf1e cef_time_delta + 2412350
26  org.chromium.ContentShell.framework 0x0000000113f2ad33 ChromeAppModeStart_v6 + 6537459
27  com.cycling74.Max               0x0000000103072b0e MaxCefEventLoopHandler::runMessageLoop() + 18
28  com.cycling74.Max               0x000000010344b3b5 juce::JUCEApplicationBase::main(int, char const**) + 245
29  libdyld.dylib                   0x00007fff203c1f3d start + 1
AlexHarker commented 3 years ago

Most likely the projects are set to enable AVX, which cannot be emulated by rosetta 2 and you are on an M1 Mac OR you are on a very old Mac without AVX. If you build them with SSE 4.2 instead they should run in either case.

I think there is something in the config that sets this.

AlexHarker commented 3 years ago

From your crash log I'm pretty sure you are on an M1 processor.

kylemcdonald commented 3 years ago

Amazing lead. This corresponds with what I was just noticing about some kind of datatype specific crashes. I am on an M1 Mac Mini. I will look into the SSE 4.2 flag.

AlexHarker commented 3 years ago

You might just be able to comment out:

CLANG_X86_VECTOR_INSTRUCTIONS = avx2

in the config file

kylemcdonald commented 3 years ago

That was it! I changed this line in the Config_AHarker_Externals.xcconfig file CLANG_X86_VECTOR_INSTRUCTIONS = sse4.2

Now it runs on my M1 Mac Mini. This patch will eventually run on another machine pre-M1 MacBook Pro, so I will look into which vector instruction set is supported by that machine and possibly re-build.

In case you're curious, it is for this piece https://vimeo.com/471300137 which will be showing in Brooklyn this month. We've been using partconvolve~ and timeconvolve~ since we made it in 2013, so every few years I am back to discover the latest Mac incompatibility 😂

Thanks for all your work & your help.

AlexHarker commented 3 years ago

Nice! For IR-type convolution I'd advise you to install HISSTools Impulse Response Toolbox from the package manager and then using multiconvolve~ instead - it's the same code under the hood. If there are specific reasons to use the separate externals fine, but for most people they just want the zero latency convolution you can now get in a simpler form.

kylemcdonald commented 3 years ago

Thank you! The reason I'm avoiding multiconvolve~ is basically that the sound was crafted by someone who is more of a Max expert than me, and I don't trust myself yet to replace this subpatch in a truly drop-in way. The day I can no longer recompile the externals, I will absolutely switch over :)

Screen Shot 2021-06-27 at 14 57 55
AlexHarker commented 3 years ago

I made that subpatch and I'm almost 100% sure that you can simply replace it with multiconvolve~ and connect whatever was connected to the right inlet to the leftmost inlet of multiconvolve~ (by default it'll just have one input).