Cycling74 / rnbo.unity.audioplugin

RNBO Adapter for Unity's Native Audio Plugin
MIT License
40 stars 8 forks source link

NotSupportedException error when running on Android #12

Closed janklug closed 1 year ago

janklug commented 1 year ago

Hey, I planted the export from the test-orbs example into an existing Unity Project, with plugin exports compiled for the Mac editor and for Android. I imported and configured the plugin for ARM64 / Load on startup, and attached the OrbPlayer example script to a GameObject.

In the editor this plays fine. Compiling for Android also works; but running it doesn't - the sound does not appear on my Oculus 2.

In the adb debug output, I see that the TestOrbsHandle() is instantiated (I added a Debug.Log message to it), but then this error appears:

NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we're attempting to marshal is: TestOrbsHandle::<RegisterParameterEventDelegate>b__120_0 04-24 12:56:27.472 20480 20499 E Unity : at TestOrbsHandle.RegisterParameterEventDelegate () [0x00000] in <00000000000000000000000000000000>:0 04-24 12:56:27.472 20480 20499 E Unity : at TestOrbsHandle.RegisterIfNeeded () [0x00000] in <00000000000000000000000000000000>:0 04-24 12:56:27.472 20480 20499 E Unity : at TestOrbsHandle..ctor () [0x00000] in <00000000000000000000000000000000>:0 04-24 12:56:27.472 20480 20499 E Unity : at OrbPlayer.Start () [0x00000] in <00000000000000000000000000000000>:0 04-24 12:56:27.472 20480 20499 E Unity :

From then on, the terminal is flooded with this error: NullReferenceException: Object reference not set to an instance of an object. 04-24 12:56:27.891 20480 20499 E Unity : at OrbPlayer.Update () [0x00000] in <00000000000000000000000000000000>:0

Any idea what is (not) happening?

Thanks, Jan

janklug commented 1 year ago

Same problem when I changed the RNBODrumkit sample scene into an XR version and tried it on the Oculus 2:

NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we're attempting to marshal is: QuantizedBuffersHandle::<RegisterParameterEventDelegate>b__116_0 04-24 15:24:52.305 6559 6577 E Unity : at QuantizedBuffersHandle.RegisterParameterEventDelegate () [0x00000] in <00000000000000000000000000000000>:0 04-24 15:24:52.305 6559 6577 E Unity : at QuantizedBuffersHandle.RegisterIfNeeded () [0x00000] in <00000000000000000000000000000000>:0 04-24 15:24:52.305 6559 6577 E Unity : at QuantizedBuffersHelper.Update () [0x00000] in <00000000000000000000000000000000>:0 04-24 15:24:52.305 6559 6577 E Unity : 04-24 15:24:52.318 6559 6577 E Unity : NullReferenceException: Object reference not set to an instance of an object. 04-24 15:24:52.318 6559 6577 E Unity : at OrbPlayer.Update () [0x00000] in <00000000000000000000000000000000>:0

When I disable the 'Cool Objects' in the example scene and add a TestOrbs plugin to the Audio Mixer directly it works, and there are no error messages.. J

x37v commented 1 year ago

Okay HMM, I've only tested in the audio mixer so I'll have to look further into this

x37v commented 1 year ago

Adding this for future reference, maybe just for myself: https://forum.unity.com/threads/il2cpp-does-not-support-marshaling-delegates-that-point-to-instance-methods-to-native-code.1046143/

Maybe i just need to make these functions static

I wonder if in the mean time, you can use the Mono scripting backend on the Quest @janklug ?

janklug commented 1 year ago

Hey Alex, thanks for looking into this. I switched to Mono; could compile and run. This switch however created constant audio artefacts (like a fax machine) which reacted to head movement. Interesting.. but not as intended!

The debug produced this error: DllNotFoundException: TestOrbs assembly:<unknown assembly> type:<unknown type> member:(null) 04-24 17:03:08.702 12086 12109 E Unity : at (wrapper managed-to-native) TestOrbsHandle.RNBOInstanceCreate(int&) 04-24 17:03:08.702 12086 12109 E Unity : at TestOrbsHandle..ctor () [0x0001b] in /Users/janklug/Developer/rnbo.unity.audioplugin/build/TestOrbs/Assets/Scripts/TestOrbsHelper.cs:211 04-24 17:03:08.702 12086 12109 E Unity : at OrbPlayer.Start () [0x00001] in /Users/janklug/Projects/Chantalla/Current_Unity/VR22_v47/Assets/Scripts/OrbPlayer.cs:12 04-24 17:03:08.702 12086 12109 E Unity : 04-24 17:03:08.702 12086 12109 E Unity : (Filename: /Users/janklug/Developer/rnbo.unity.audioplugin/build/TestOrbs/Assets/Scripts/TestOrbsHelper.cs Line: 211)

and then later a stream of these: NullReferenceException: Object reference not set to an instance of an object 04-24 17:03:10.366 12086 12109 E Unity : at OrbPlayer.Update () [0x00001] in /Users/janklug/Projects/Chantalla/Current_Unity/VR22_v47/Assets/Scripts/OrbPlayer.cs:17

J

x37v commented 1 year ago

interesting! thanks for the debug output @janklug .. I'll look into it on the system I have with me today and see if I can figure it out

janklug commented 1 year ago

I switched to Mono; could compile and run.

That was my existing project. The VR-transformed RNBODrumkit sample scene I couldn't compile with Mono as the OpenXR plugin only likes arm64...

x37v commented 1 year ago

luckily, I am able to reproduce this with the desktop build (macOS) if I switch to the IL2CPP back-end, debugging here should be much nicer

x37v commented 1 year ago

@janklug I just pushed some changes to the main branch. Can you pull those and give this another try?

janklug commented 1 year ago

Wow @x37v , that was quick! It works; sounds great and produces no errors. Thank you very much!

x37v commented 1 year ago

wonderful @janklug ! thanks for verifying it