Cabbage Logo
Back to Cabbage Site

CSound Unity IOS build failure

More findings:
I’m able to build Csound for iOS on my old Intel MacBook Pro with XCode 12.4, but the building doesn’t complete nicely on my M1 MacBook Pro with XCode 14.1 (it doesn’t create libcsound.a), with these logs:

Fatal Error Build iOS XCode 14.1.txt (1.8 MB)

An excerpt:

** BUILD SUCCEEDED **

+ lipo -create libcsound-device.a Release/libCsoundLib.a -output ../libcsound.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: libcsound-device.a (No such file or directory)

I tried removing i386 / arm7 archs from the devices, but the build still fails.
There are two xconfig files under the iOS folder:


This is now simulator.xconfig:

ONLY_ACTIVE_ARCH=YES
ARCHS = x86_64
VALID_ARCHS = x86_64
IPHONEOS_DEPLOYMENT_TARGET = 11.0
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
//DEBUGGING_SYMBOLS=NO
STRIP_INSTALLED_PRODUCT=YES
//DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
DEPLOYMENT_POSTPROCESSING=YES
USER_HEADER_SEARCH_PATHS=$(inherited) /usr/local/include
GCC_PREPROCESSOR_DEFINITIONS=$(inherited) IOS=1

And this is device.xconfig:

ONLY_ACTIVE_ARCH=YES
ARCHS =  arm64
VALID_ARCHS = arm64
IPHONEOS_DEPLOYMENT_TARGET = 11.0 
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
STRIP_INSTALLED_PRODUCT=YES
//DEBUGGING_SYMBOLS=NO
//DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
DEPLOYMENT_POSTPROCESSING=YES
GCC_PREPROCESSOR_DEFINITIONS=$(inherited) IOS=1

If I don’t modify the two files above I get those errors:

Errors
/Users/giovanni.bedetti/Downloads/csound-6.18.0/iOS/cs6iOS/Csound.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 6.1, but the range of supported deployment target versions is 11.0 to 16.1.99. (in target 'CsoundLib-static' from project 'Csound')

error: The i386 architecture is deprecated. You should update your ARCHS build setting to remove the i386 architecture. (in target 'CsoundLib-static' from project 'Csound')

warning: Run script build phase 'CMake Rules' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'CsoundLib-static' from project 'Csound')

/Users/giovanni.bedetti/Downloads/csound-6.18.0/iOS/cs6iOS/Csound.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 6.1, but the range of supported deployment target versions is 11.0 to 16.1.99. (in target 'ZERO_CHECK' from project 'Csound')

error: The i386 architecture is deprecated. You should update your ARCHS build setting to remove the i386 architecture. (in target 'ZERO_CHECK' from project 'Csound')

warning: Run script build phase 'CMake Rules' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'ZERO_CHECK' from project 'Csound')

**** BUILD FAILED ****

Not sure if I’m getting closer to discover something, but just wanted to flag this.
Will try again later this evening!

Great I wasn’t aware of that!
We can definitely get rid of the PostProcessBuild script then!
It is only useful for old XCodes atm :wink:

Incase my failures are useful - I also tried initialising Csound later, rather than in the Awake, I added a waiting co-routine for 5 secs and then started the initialisation, just incase there was some delay in getting the audio system setup in Unity, but I still got the same crash.

@giovannibedetti Using the supplied “build.sh” in the IOS folder it built without issue for me on an Intel OSX 12.5 / Xcode 13.4.1

1 Like

One thing I just noticed in the CMake output when building it here:

Building with 32-bit floats

I think it should be 64bit floats on iOS should it not? I think we should be enabling doubles. Modify the build.sh script so that -DUSE_DOUBLE=0 becomes -DUSE_DOUBLE=1 and see what happens. I would try myself but I need to run to class…

I was thinking about this too.
We have this also!

I will remove that too and see what happens

I compiled the “Csound iOS Swift Examples” (https://github.com/csound/csound/tree/master/iOS/Csound%20iOS%20Swift%20Examples) and installed to my iPad, the basic example & X/Y grid example both worked fine, so I’m assuming the built plugin is okay.

Yes the iOS library works pretty much everywhere as it is in the Csound release, I have some apps made using it that are still running on a very old iPad2 so it’s definitely something on the CsoundUnity side.
I pushed the changes about doubles but I still have the crash :confused:
The interesting thing is that if I run a development build from XCode it goes into a timeout and never starts :face_with_monocle:
Also if I enable the doubles in the build.sh script it fails :frowning:

Ok, so I guess 32bit floats is correct. Dang it, I thought that might have been the issue.

The only sample that runs without crashing is the Csound Test, that doesn’t output any audio but only lists the available opcodes and some other settings.
csoundOpcodes.txt (83.0 KB)

From the error logs it looks like the crash happens as soon as we try to output audio. If you add

outs(oscili:a(1, 300), oscili:a(1, 300))

I assume it will crash again?

In the Csound test sample there is no csd set at all, I could try to make it compile an orchestra maybe, but the Csound object creation is not happening when no csd is set.

Ah, right…

No wait it’s not true, just checked, the compilation fails (because the string is empty), but Csound is created and started.
Indeed in the first line of the log file above you can see:

CsoundUnity done init, compiledOk? False

So definitely sending an orchestra is an option

No crash but a memory allocation failure happening straight after the awake:

–Csound version 6.18 (float samples) Nov 30 2022

[commit: 2901a4a1f2961ac11cb92dacce87962d6f54002d]

libsndfile-1.0.29pre1

displays suppressed

memory allocate failure for -7988227072

Compiling orchestra!

instr 1
a1 oscili 1, 300, 1
outs a1, a1
endin

I’m waiting 5 seconds before compiling the orchestra. No crash but no sound.

Edit: Of course there is no crash since Csound is not running and performance is already ended because there was no score.
If I create an empty csd with no instruments and only a f0 3600 in the score section I have the crash:

<Cabbage> bounds(0, 0, 0, 0)
form caption(“Test”) size(700, 300), guiMode(“queue”), pluginId(“test”)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 1
nchnls = 2
0dbfs = 1
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 3600
</CsScore>
</CsoundSynthesizer>

The crash happens as soon as the initialization finishes, that is when Csound starts executing its cycles.

This should be the source of the memory allocate failure log:

I’m able to launch a basic scene in the iPad emulator from Xcode without any crashes using your ios-hotfix branch. But I’m getting no sound. At least I’m set up to help now.

[edit] now I’m getting a crash :rage:

1 Like

Great!
I haven’t tried running on the simulator (but it should work fine on M1 macs).
The issue is that no allocation of memory is happening, probably because of the size of MYFLT (it’s the first thing that can fail in kperf_nodebug, the calls to memset).
I will have some time to be on it again only on Sunday!
But keep us posted with your findings :wink:

Looks like it was crashing because I was trying to do a Debug.Log(). So no crash here but no sound either…

So it “appears” to be working fine for me in the emulator.

I just don’t hear any output. Maybe it’s my audio settings…

I just tested now with a non CsoundUnity scene with an AudioSource and I also hear nothing…

Maybe the simulator has no audio? Or it starts disabled?