resonance-audio / resonance-audio-unity-sdk

Resonance Audio SDK for Unity
https://resonance-audio.github.io/resonance-audio/develop/unity/getting-started
Other
297 stars 38 forks source link

ResonanceAudioListener crashes Unity when platform is set to iOS #7

Closed Jmcm16 closed 6 years ago

Jmcm16 commented 6 years ago

Discovered the problem continually when trying to add a ResonanceAudioListener Component to the Main Camera with standard Unity Audio Listener as per instructions on migrating to Resonance Audio from GvrAudio in an iPhone app I'm currently developing. Problem seems to be related to the iOS platform.

Crash occurs:

Steps to reproduce component crash:

  1. Create a new project, load in Resonance Audio, and set Spacializer Plugin and Ambisonic Plugin to Resonance in Audio Settings.
  2. Set the build settings to iOS.
  3. Attempt to add the ResonanceAudioListener script to the Main Camera object (should have a standard Unity Audio Listener by default.) Unity should promptly crash.

Steps to reproduce scene crash:

  1. Create a new project, load in Resonance Audio, and set Spacializer Plugin and Ambisonic Plugin to Resonance in Audio Settings.
  2. Set the build settings to iOS.
  3. Attempt to load the "ResonanceAudioDemo" scene from the Resonance Demos folder. Unity should promptly crash.

Steps to reproduce platform switch crash:

  1. Create a new project, load in Resonance Audio, and set Spacializer Plugin and Ambisonic Plugin to Resonance in Audio Settings.
  2. Load the "ResonanceAudioDemo" scene from the Resonance Demos folder. Unity should not crash this time.
  3. Attempt to switch build platforms from PC/Mac/Linux to iOS. Unity should promptly crash.

EDIT: Working on a Mid-2015 MacBook Pro. Crash happens on any version of Unity 2017.

mauskopf commented 6 years ago

Thanks for the detailed bug report. We’re looking into it and will update this thread shortly!

anokta commented 6 years ago

Hi,

I can't seem to reproduce the crash on a Mac machine, in any of the cases you have mentioned, with or without GVR Unity SDK imported in a project on top of Resonance Audio SDK - tested in Unity 2017.1.0f3.

Is there anything additionally required in your repro steps than creating a new vanilla project and following the steps? If not, it would be helpful to see the Unity editor log/stack trace when the crash occurs, assuming you can still reproduce the issue. See the related Unity manual for how to get them.

In the meantime, one thing you can try out is to comment out line 83 of ResonanceAudioListener.cs to see if the crash still occurs: // ResonanceAudio.UpdateAudioListener(this);

ilmarioranen commented 6 years ago

I'm having the exact same problem, though I didn't add the component to camera, but a separate gameobject which is in the same prefab as the camera. The hierarchy doesnt seem to matter though, just adding the component crashes the editor, and returning to the scene after the crash does the same - and repeats it as long as it takes before I manage to reset the scene to previous version.

Using: Editor OS: Mac OS 10.12.6 Build platform: iOS Unity version: Unity 2017 2.0p3 (patch release from just a few days ago, previous patch release seemed to have same problem). I have the latest GVR SDK for Unity v1.110.0 and the latest (only) Resonance audio Unity SDK (1.0.0).

In the scene I first tried to add the component there were few gameObjects related to playing 4k 360 video (using EasyMovieTexture), but this problem doesn't seem to be related to scene/objects.

I tried commenting this line as suggested, and indeed it stopped the crash: // ResonanceAudio.UpdateAudioListener(this);

ilmarioranen commented 6 years ago

I uncommented this line again: ResonanceAudio.UpdateAudioListener(this);

And commented these 2 lines under ResonanceAudio-class: public static void UpdateAudioListener(ResonanceAudioListener listener) { occlusionMaskValue = listener.occlusionMask.value; //SetListenerGain(ConvertAmplitudeFromDb(listener.globalGainDb)); //SetListenerStereoSpeakerMode(listener.stereoSpeakerModeEnabled); }

This also avoids the crash. Note: I have not added any AudioSource in the prefabs or scene at this point.

I tried to pinpoint the issue better by adding a zero-check in ConvertAmplitudeFromDb(), but it crashes with it again:

/// Converts given |db| value to its amplitude equivalent where 'dB = 20 log10(amplitude)'. public static float ConvertAmplitudeFromDb(float db) { if (db == 0) { Debug.LogError ("ConvertAmplitudeFromDb() db is zero"); return 0f; }
return Mathf.Pow(10.0f, 0.05f
db); }

Based on the many comments in the class relating to "has to be in Unity main thread", could it be connected to multithreading of the editor?

anokta commented 6 years ago

Hi Ilmari,

Thanks for the clarification and further testing! We've tracked down the root cause. The issue is caused by duplicate function definitions between the Resonance Audio SDK and the audio components in the GVR Unity SDK. FYI, for reference, this is a similar problem that we have investigated previously in googlevr/gvr-unity-sdk#665.

As an immediate workaround, replacing the following lines in ResonanceAudio.cs#L391 and GvrAudio.cs#L385 as the line below should resolve the crashes in the Editor: #if !UNITY_EDITOR && UNITY_IOS

Overall, it is strongly recommended to remove the audio related assets from the GVR Unity SDK when using together with the Resonance Audio SDK. Please see the corresponding section in the "Upgrading existing projects from Google VR audio components" guide for further information.

Also note that, this step will be handled automatically during the Unity package import process in the upcoming release.

ilmarioranen commented 6 years ago

@anokta ok, thanks!

Overall, it is strongly recommended to remove the audio related assets from the GVR Unity SDK when using together with the Resonance Audio SDK. Please see the corresponding section in the "Upgrading existing projects from Google VR audio components" guide for further information.

This seems to link to a cool but restricted Google-guru-only-version of the docs :) I assume you ment the version targeted for mere mortals: https://developers.google.com/resonance-audio/develop/unity/getting-started

It doesn't yet mention removing the assets, just removing the components from the gameobject

EDIT: Seems like you fixed the link already before my smartypants-comment.

anokta commented 6 years ago

Oops, my bad! :) The link should be fixed now with the updated documentation in the previous comment.

In short, you should remove all the GvrAudio assets (including the audioplugin files in the Plugins folder) from the GVR Unity SDK.

Cheers

Jmcm16 commented 6 years ago

@ilmarioranen @mauskopf Thanks for responding to the bug report.

@anokta Thanks for the immediate work-around. Replacing the line and removing GvrAudio related files worked.

anokta commented 6 years ago

Fixed in v1.1.0.