Placeholder-Software / Dissonance

Unity Voice Chat Asset
70 stars 5 forks source link

[Bug] MS HRTF Spatializer does not work well with Dissonance (UWP, HoloLens)? #91

Closed bockelie93 closed 6 years ago

bockelie93 commented 6 years ago

Context

MS HRTF Spatializer is a plugin you use for spatialized sound for UWP. When I use it together with Dissonance, I do get an access violation exception when I start my HoloLens (or local machine) application.

It works fine if I choose to exclude either MS HRTF Spatializer or Dissonance, but together I get the exception.

Expected Behavior

The application should run without any problems.

Actual Behavior

There's an access violation exception on start up.

Steps to Reproduce

  1. Enable MS HRTF Spatializer (Edit -> Project Settings -> Audio -> Spatilizer Plugin)
  2. Add Dissonance (no need to add it to scene)
  3. Build for the UWP platform
  4. Deploy Release x86 Local Machine / Device (if you have a HoloLens) through Visual Studio.
  5. You should get a break point.

Your Environment

bockelie93 commented 6 years ago

When not using a spatializer plugin Dissonance will automatically apply basic spatialization itself, this interferes with native spatialization plugins and must be disabled when using one.

From how I understand the documentation, if I want to use MS HRTF Spatializer, I have to disable 'Dissonance's automatically applied basic spatialzation'? How exactly would I do that?

martindevans commented 6 years ago

The spatialization which Dissonance does is automatically turned off if the spatialize checkbox on the AudioSource is checked. So simply swapping to the SpatializedPlaybackPrefab will disable the built in spatialization (see line 156 of Assets/Plugins/Dissonance/Core/Audio/Playback/VoicePlayback.cs for where this happens).

I'm just about to try to reproduce this. Just to check I've understood this correctly - simply adding Dissonance to the project and enabling the MSHRTF spatializer will cause the crash? i.e. Neither of them actually need to be active in the scene?

bockelie93 commented 6 years ago

I'm just about to try to reproduce this. Just to check I've understood this correctly - simply adding Dissonance to the project and enabling the MSHRTF spatializer will cause the crash? i.e. Neither of them actually need to be active in the scene?

Yes, that's correct.

martindevans commented 6 years ago

I do get an exception but it's slightly different to the one you saw (it has more detail than a violation exception thankfully):

// Build_UnityEngine.AudioModule_0.cpp Line 5577

// System.String UnityEngine.AudioSettings::GetSpatializerPluginName()
extern "C"  String_t* AudioSettings_GetSpatializerPluginName_m698617843 (RuntimeObject * __this /* static, unused */, const RuntimeMethod* method)
{
    typedef String_t* (*AudioSettings_GetSpatializerPluginName_m698617843_ftn) ();
    static AudioSettings_GetSpatializerPluginName_m698617843_ftn _il2cpp_icall_func;
    if (!_il2cpp_icall_func)
    _il2cpp_icall_func = (AudioSettings_GetSpatializerPluginName_m698617843_ftn)il2cpp_codegen_resolve_icall ("UnityEngine.AudioSettings::GetSpatializerPluginName()");
    String_t* retVal = _il2cpp_icall_func(); // <-- EXCEPTION ON THIS LINE
    return retVal;
}

Stack:

GameAssembly.dll!AudioSettings_GetSpatializerPluginName_m698617843(Il2CppObject * __this, const MethodInfo * method) Line 5583
GameAssembly.dll!AudioExtensionManager_RegisterBuiltinDefinitions_m771911993(Il2CppObject * __this, const MethodInfo * method) Line 5315
GameAssembly.dll!AudioExtensionManager_Update_m3727859914(Il2CppObject * __this, const MethodInfo * method) Line 4978
GameAssembly.dll!AudioSettings_InvokeOnAudioManagerUpdate_m667489537(Il2CppObject * __this, const MethodInfo * method) Line 5728
GameAssembly.dll!RuntimeInvoker_Void_t1841601450(void(*)() methodPointer, const MethodInfo * methodMetadata, void * obj, void * * args) Line 42989
GameAssembly.dll!il2cpp::vm::Runtime::Invoke(const MethodInfo * method, void * obj, void * * params, Il2CppException * * exc) Line 463
GameAssembly.dll!il2cpp_runtime_invoke(const MethodInfo * method, void * obj, void * * params, Il2CppException * * exc) Line 956
UnityPlayer.dll!07729149()
// Remove many lines of unknown UnityPlayer.dll symbols

Exception:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. occurred

It looks like this is being called as part of the initial setup of audio plugins. Although I have no idea what could be causing the problem and why no one else using a hololens has ever encountered it, we have quite a few people using Dissonance+hololens. I'll have to do some investigation...

bockelie93 commented 6 years ago

Are you using .NET backend?

martindevans commented 6 years ago

I stuck with the defaults:

untitled

What are you using?

bockelie93 commented 6 years ago

I am using .NET backend.

martindevans commented 6 years ago

IL2CPP

I found this thread regarding the error I get with IL2CPP. My testing crashes with IL2CPP (as per my last comment) in Debug configuration. It loads fine on the master configuration.

.Net x86

With this configuration I get an unidentified exception which the debugger can't handle. That's not entirely unexpected - when there's something that causes an access violation it could also cause almost any other bizarre behaviour you can think of.

I also tested this configuration with the OculusSpatializer with the same crash.

I tested it with no spatializer and it didn't initially crash. However I tried adding an audio source playing through a mixer with the Dissonance Echo Cancellation attached (to try and make sure it's actually loading the plugin) and that does crash (same unidentified exception).

.NET x64

With this configuration it seems to load perfectly (I tried several of the x86 tests in x64, all were fine). Unfortunately I believe hololens is x86, so this isn't an option?


I'm going to need to do some more research into this. It works perfectly on PC with any of the above configurations so I need to investigate what's different with the Hololens platform to cause a crash like this.

bockelie93 commented 6 years ago

Yes, it has to be x86.

I tested it with no spatializer and it didn't initially crash. However I tried adding an audio source playing through a mixer with the Dissonance Echo Cancellation attached (to try and make sure it's actually loading the plugin) and that does crash (same unidentified exception).

I can confirm this, experience it earlier today.

martindevans commented 6 years ago

I've passed on my repro project to Unity. I'm pretty sure the IL2CPP is a Unity issue - the calling convention being used is defined by some macros (supplied by Unity) in the Audio plugin project. The issue with the .NET backend is less clear (since the debugger can't even tell me what it is). But if there's an issue with calling conventions that could also cause almost any issue (interpreting misaligned stack as the stack, using the wrong instruction pointer restored from the stack) which could easily cause a subsequent access violation exception as you're getting.

As a workaround The only thing I can really think of is not using the spatializer (therefore audio plugins won't be forced to be loaded) and don't use the Dissonance AEC filter (also ensuring it doesn't get loaded). The Dissonance preprocessing (critical for Dissonance to work) is included in the same DLL, so deleting it isn't an option. You could also try renaming the DLL (Unity knows it's an audio plugin, because the name is prefixed with AudioPlugin) - you'd need to change all the DllImports in Dissonance to reference the new name (and obviously AEC would not work).

martindevans commented 6 years ago

Unity issue: https://fogbugz.unity3d.com/default.asp?1028151_94fmv154sdg2cu8e

yacuzo commented 6 years ago

I also get this if I try to run the UWP solution on local machine (as a normal UWP Win10 app), instead of on the emulator or the real device.

martindevans commented 6 years ago

@yacuzo Which backend are you using (.Net or IL2CPP)?

yacuzo commented 6 years ago

.Net 4.6, which is standard for HoloLens.

martindevans commented 6 years ago

A reply from Unity on the issue linked above:

We have been able to reproduce this bug and have sent it for resolution with our developers.

martindevans commented 6 years ago

Unity got back to me again, confirming that this is a problem with calling conventions being mismatched - it looks like the native audio plugin library supplied by Unity has changed (to fix the mismatch) since I compiled the plugins against it.

I'll download an updated copy and try to recompile the plugins tomorrow :)

martindevans commented 6 years ago

I've just recompiled the plugins and that seems to have fixed the issue. Before we release this to the store I'd appreciate it if someone could test this in a real world application. If anyone who previously had this issue would like to test it please email me (martin@placeholder-software.co.uk) your invoice number (proof of purchase) and I'll email you back a modified build of Dissonance.

bockelie93 commented 6 years ago

I have sent an email.

bockelie93 commented 6 years ago

I got the Access Violation Error again. Both when running it on the HoloLens and as a UWP Window 10 application.

  1. Upgraded Dissonance to 6.2.0.
  2. Imported the plugin you sent me.
  3. Enabled the MS HRTF Spatializer plugin under audio.
  4. Still no Dissonance in the scene.
  5. Built for UWP, with .NET backend.
  6. Ran it on device (HoloLens) / local machine with debugging.
  7. Access violation.

Without the MS HRTF Spatializer, it worked, but then I don't get spatialized sound on the HoloLens.

@martindevans Did it work for you when choosing release/x86/local machine?

martindevans commented 6 years ago

I'll try it again with release/x86/local machine tomorrow - I did check that but maybe I accidentally used the wrong plugins in my test or something :/

Could you also confirm that you're using the right plugins - we've had a lot of issues with Unity failing to properly extract plugins from unitypackages. Once you've run a build just run this (in powershell) in the directory with the AudioPluginDissonance.dll:

(get-filehash .\AudioPluginDissonance.dll).Hash -eq "326711AFEC8212671056FEB07E874F97DB99FE3BDAC0F313419FEF69B063D245"

This should return true.

martindevans commented 6 years ago

I just checked this out. I created two projects, one using 6.2.0 and one using the patched DLLs I sent you (it looks like some non-critical resources were missing from the unitypackage I sent you, sorry about that). The 6.2.0 version crashes (access violation) and the new version does not.

So I'm hoping this is a problem with you using the wrong plugins for your test. Please double check what DLLs were in your test build (with the hash I mentioned above).

bockelie93 commented 6 years ago

(get-filehash .\AudioPluginDissonance.dll).Hash -eq "326711AFEC8212671056FEB07E874F97DB99FE3BDAC0F313419FEF69B063D245" did not give a match.

I deleted the Plugin/Dissonance folder, then reimported the unity package you sent me. It seems like it did not contain the AudioPluginDissonance.dll or any of other files under Plugin/Dissonance/Plugins.

martindevans commented 6 years ago

I'm not sure what's gone wrong there. I've sent you an email with just the two DLLs files in a zip, that way we can be certain that you've got the right thing!

bockelie93 commented 6 years ago

It works once I had the 2 DLLs.

Thanks for the hard work! 🥇

martindevans commented 6 years ago

Fantastic, thanks for testing that. :+1:

Assuming nothing else comes up I'll aim to do a 6.2.1 release early next week.

HyperLethalVector commented 6 years ago

Hi,

Did you end up getting the two to 'play well' together?

I'm coming up with similar problems!

bockelie93 commented 6 years ago

Yes, it works well.

Since it is still marked as awaiting release, you probably don't have the updated plugin.

HyperLethalVector commented 6 years ago

I have the updated version, but still experience the same error, so I've mailed the guy above to try and get his built version!

martindevans commented 6 years ago

Hi HyperLethalVector,

It's not released to the asset store yet, we've been delayed getting this release out while trying to test out the iOS fix for #80. Send me an email (martin@placeholder-software.co.uk) with your invoice number and I'll send you back an updated build :)

HyperLethalVector commented 6 years ago

Hi,

I've already sent you a mail with the invoice number. Thanks for getting back to me :)

martindevans commented 6 years ago

I see it. I'll have to delay sending you back the fixed build for a few hours I'm afraid, I'm not at my PC with access to the build right now.

HyperLethalVector commented 6 years ago

It's fine! In the land of Japan it's almost midnight. And it's not super-duper crucial,

I'll just go to sleep :)

Thanks for the super fast response!

martindevans commented 6 years ago

I've just submitted 6.2.1 to the asset store, it should be available within a week (depending on review times). That should completely fix this issue.

If anyone wants a copy before it's on the store email me you invoice number (martin@placeholder-software.co.uk) and I can send you back that build.

martindevans commented 6 years ago

Dissonance 6.2.1 just went live, a very quick turn around from the asset store review team ^_^