steam-audio icon indicating copy to clipboard operation
steam-audio copied to clipboard

audioplugin_phonon.dll access violation 4.0.3

Open gwenvis opened this issue 3 years ago • 11 comments

Unity, both in editor and standalone can often crash when the SteamAudioSource performs its Awake phase. I've been having this issue for a while now, but I've found no fixes for this as of yet. This can happen any time, like when an audio source is dynamically created but also when a new scene is loaded.

I've compiled the audioplugin_phonon.dll from source so I could get the exact location where the exception occurred with the pbd files, and it always seems to come from the method iplSourceRetain(IPLSource source)

image

Crashed thread stack trace:

0x00007FFE8E10ABB9 (audioplugin_phonon) iplUnitySetHRTF
0x00007FFE8E10AF75 (audioplugin_phonon) iplUnitySetHRTF
0x00007FFE5953B041 (UnityPlayer) UnityAudioEffect_InternalSetFloatParameterCallback
0x00007FFE59F1425E (UnityPlayer) FMOD::DSP::setParameter
0x00007FFE59555FB5 (UnityPlayer) AudioSource::SetSpatializerFloat
0x00007FFE595A012E (UnityPlayer) AudioSource_CUSTOM_SetSpatializerFloat
0x0000013A16EE7564 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.AudioSource:SetSpatializerFloat (UnityEngine.AudioSource,int,single)
0x0000013A16EE780B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\Plugins\SteamAudio\Scripts\Runtime\UnityAudioEngineSource.cs:79] SteamAudio.UnityAudioEngineSource:SetSpatializerIntPtr (intptr,int&) 
0x0000013A16EE731B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\Plugins\SteamAudio\Scripts\Runtime\UnityAudioEngineSource.cs:56] SteamAudio.UnityAudioEngineSource:UpdateParameters (SteamAudio.SteamAudioSource) 
0x0000013A16EE636E (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\Plugins\SteamAudio\Scripts\Runtime\SteamAudioSource.cs:167] SteamAudio.SteamAudioSource:Awake () 
0x00000137CA633870 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FFE6CD1F1E0 (mono-2.0-bdwgc) mono_get_runtime_build_info
0x00007FFE6CCA2AC2 (mono-2.0-bdwgc) mono_perfcounters_init
0x00007FFE6CCABB1F (mono-2.0-bdwgc) mono_runtime_invoke
0x00007FFE592DD23D (UnityPlayer) scripting_method_invoke
0x00007FFE592D9A4C (UnityPlayer) ScriptingInvocation::Invoke
0x00007FFE592D9B1E (UnityPlayer) ScriptingInvocation::InvokeChecked
0x00007FFE5930A8E5 (UnityPlayer) SerializableManagedRef::CallMethod
0x00007FFE592B95D8 (UnityPlayer) MonoBehaviour::CallAwake
0x00007FFE592B87AD (UnityPlayer) MonoBehaviour::AddToManager
0x00007FFE592B8B43 (UnityPlayer) MonoBehaviour::AwakeFromLoad
0x00007FFE5932F00E (UnityPlayer) AwakeFromLoadQueue::AwakeFromLoadAllQueues
0x00007FFE589AD8D8 (UnityPlayer) GameObject::ActivateAwakeRecursively
0x00007FFE589B452F (UnityPlayer) GameObject::SetSelfActive
0x00007FFE59407195 (UnityPlayer) GameObject_CUSTOM_SetActive
0x00000137D5F385B9 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GameObject:SetActive (UnityEngine.GameObject,bool)
0x00000137D63F2C8B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Library\PackageCache\com.svermeulen.extenject@54b95b22c5\Runtime\Providers\PrefabCreators\PrefabInstantiator.cs:108] Zenject.PrefabInstantiator/<>c__DisplayClass15_0:<Instantiate>b__0 () 
0x00000137D5F77BCE (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Library\PackageCache\com.svermeulen.extenject@54b95b22c5\Runtime\Providers\IProviderExtensions.cs:35] Zenject.IProviderExtensions:GetAllInstances (Zenject.IProvider,Zenject.InjectContext,System.Collections.Generic.List`1<Zenject.TypeValuePair>,System.Collections.Generic.List`1<object>) 
0x0000013A05ED532B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Library\PackageCache\com.svermeulen.extenject@54b95b22c5\Runtime\Providers\IProviderExtensions.cs:85] Zenject.IProviderExtensions:GetInstance (Zenject.IProvider,Zenject.InjectContext,System.Collections.Generic.List`1<Zenject.TypeValuePair>) 
0x0000013A2FC354BB (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Library\PackageCache\com.svermeulen.extenject@54b95b22c5\Runtime\Factories\PlaceholderFactoryBase.cs:32] Zenject.PlaceholderFactoryBase`1<TValue_REF>:CreateInternal (System.Collections.Generic.List`1<Zenject.TypeValuePair>) 
0x0000013A2FC3542B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Library\PackageCache\com.svermeulen.extenject@54b95b22c5\Runtime\Factories\PlaceholderFactory.cs:20] Zenject.PlaceholderFactory`1<TValue_REF>:Create () 
0x0000013A2FC35142 (Mono JIT Code) Recon.Services.Pooling.ObjectPoolService`1<T_REF>:CreateNewItem ()
0x0000013A796D6053 (Mono JIT Code) Recon.Services.Pooling.ObjectPoolService`1<T_REF>:Get (UnityEngine.Vector3,System.Action`1<T_REF>)
0x0000013A7973BFFB (Mono JIT Code) Recon.SCPs.BouncyBall:RpcLogic___PlayBounceSound ()
0x0000013A7973BF0B (Mono JIT Code) Recon.SCPs.BouncyBall:RpcReader___PlayBounceSound (FishNet.Serializing.PooledReader,FishNet.Transporting.Channel)
0x0000013A2B6A4C0B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Managing\Client\ClientManager.cs:316] FishNet.Managing.Client.ClientManager:ParseReceived (FishNet.Transporting.ClientReceivedDataArgs) 
0x0000013A2B6A3C93 (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Managing\Client\ClientManager.cs:222] FishNet.Managing.Client.ClientManager:Transport_OnClientReceivedData (FishNet.Transporting.ClientReceivedDataArgs) 
0x0000013A2B6A3C2F (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Plugins\FishySteamworks\FishySteamworks.cs:308] FishySteamworks.FishySteamworks:HandleClientReceivedDataArgs (FishNet.Transporting.ClientReceivedDataArgs) 
0x0000013A05EDD7FC (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Plugins\FishySteamworks\Core\ClientSocket.cs:184] FishySteamworks.Client.ClientSocket:IterateIncoming () 
0x0000013A05EDD55B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Plugins\FishySteamworks\FishySteamworks.cs:279] FishySteamworks.FishySteamworks:IterateIncoming (bool) 
0x0000013A05EDD4B8 (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Managing\Transporting\TransportManager.cs:318] FishNet.Managing.Transporting.TransportManager:IterateIncoming (bool) 
0x0000013A05EDD263 (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Managing\Timing\TimeManager.cs:838] FishNet.Managing.Timing.TimeManager:TryIterateData (bool) 
0x0000013A05EDCE73 (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Managing\Timing\TimeManager.cs:633] FishNet.Managing.Timing.TimeManager:IncreaseTick () 
0x0000013A05EDCCB3 (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Managing\Timing\TimeManager.cs:352] FishNet.Managing.Timing.TimeManager:TickUpdate () 
0x0000013A05EDCA9B (Mono JIT Code) [C:\Users\Stepe\Documents\development\recontainment\Assets\FishNet\Runtime\Transporting\NetworkReaderLoop.cs:29] FishNet.Transporting.NetworkReaderLoop:Update () 
0x00000137D5F33F00 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FFE6CD1F1E0 (mono-2.0-bdwgc) mono_get_runtime_build_info
0x00007FFE6CCA2AC2 (mono-2.0-bdwgc) mono_perfcounters_init
0x00007FFE6CCABB1F (mono-2.0-bdwgc) mono_runtime_invoke
0x00007FFE592DD23D (UnityPlayer) scripting_method_invoke
0x00007FFE592D9A4C (UnityPlayer) ScriptingInvocation::Invoke
0x00007FFE592B96F3 (UnityPlayer) MonoBehaviour::CallMethodIfAvailable
0x00007FFE592B97CF (UnityPlayer) MonoBehaviour::CallUpdateMethod
0x00007FFE58BD78C0 (UnityPlayer) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x00007FFE58BDE8AD (UnityPlayer) BehaviourManager::Update
0x00007FFE58EBFF2E (UnityPlayer) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
0x00007FFE58EAB06E (UnityPlayer) ExecutePlayerLoop
0x00007FFE58EAB13F (UnityPlayer) ExecutePlayerLoop
0x00007FFE58EB1072 (UnityPlayer) PlayerLoop
0x00007FFE588D565A (UnityPlayer) PerformMainLoop
0x00007FFE588D34EB (UnityPlayer) MainMessageLoop
0x00007FFE588D8E3B (UnityPlayer) UnityMainImpl
0x00007FFE588D9DFB (UnityPlayer) UnityMain
0x00007FF6AB4F11F2 (SCPArchive) __scrt_common_main_seh
0x00007FFEBF127034 (KERNEL32) BaseThreadInitThunk
0x00007FFEC0282651 (ntdll) RtlUserThreadStart

Here the dump, log and pbd files: crash.zip

gwenvis avatar Feb 18 '22 22:02 gwenvis

My knowledge of C++ is unfortunately very limited, but it seems to have something to do with this implementation:

    case SIMULATION_OUTPUTS_PTR_LOW:
#if defined(IPL_CPU_X86) || defined(IPL_CPU_ARMV7)
        setSource(state, reinterpret_cast<IPLSource>(*reinterpret_cast<uint32_t*>(&value)));
#else
        effect->simulationSourceTemp = static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&value));
#endif
        break;
    case SIMULATION_OUTPUTS_PTR_HIGH:
#if defined(IPL_CPU_X64) || defined(IPL_CPU_ARMV8)
        effect->simulationSourceTemp = (static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&value)) << 32) | effect->simulationSourceTemp;
        setSource(state, reinterpret_cast<IPLSource>(effect->simulationSourceTemp));
#endif

And then specifically the SIMULATION_OUTPUTS_PTR_HIGH case. I exclusively build for 64-bit. The iplSourceRetain method retrieves an IPLSource with address pointer of 0x0000013a7f7fffff. I have 0 clue if that's a valid address.

gwenvis avatar Feb 19 '22 13:02 gwenvis

@stepperman - Thanks for reporting. We tried to repro this issue but with no success. Any of the following will help towards a repro:

  • Are you able to share a standalone project we can use for repro?
  • What does your Steam Audio Source component looks like?
  • When does typically the crash happen? Creating an Audio Source with Steam Audio Source component on it? Switching scenes?

achandak avatar Feb 21 '22 21:02 achandak

we've got the same issue with 4.0.3 - it happens on scene load initialization

glemeshko-bsg avatar Feb 22 '22 14:02 glemeshko-bsg

@achandak reproducing this issue is extremely hard, it happens at complete random moments and can happen when the scene initialises (like @glemeshko-bsg mentioned) or when a new steam audio source is created. Audio Sources in my project always have a Steam Audio Source attached with the Spatialize checkbox on. The settings of the Steam Audio Source also seem to have no effect on reducing this crash.

I'll create a project that abuses loading scenes and creating a lot of audio sources to try and repro this issue. I'll upload that soon.

Update: I couldn't figure out a repro unfortunately. I've tried making something that continuously switches scene and creates audio sources but it creates too much memory (without freeing) them to properly test that for a long time.

gwenvis avatar Feb 23 '22 13:02 gwenvis

I moved most of the initialization from Awake to Start in SteamAudioSource.cs. I'm not sure if it works - but the crashes seem to have disappeared. I still get the occasional editor crash, but that's to be expected of Unity 😝.

My Start() and Awake() methods look like this now.

private void Awake()
{
    mSimulator = SteamAudioManager.Simulator;

    var settings = SteamAudioManager.GetSimulationSettings(false);
    mSource = new Source(SteamAudioManager.Simulator, settings);
    mAudioEngineSource = AudioEngineSource.Create(SteamAudioSettings.Singleton.audioEngine);

    if (mAudioEngineSource != null)
    {
        mAudioEngineSource.Initialize(gameObject);
    }
}

private void Start()
{
    if (mAudioEngineSource != null)
    {
        mAudioEngineSource.UpdateParameters(this);
    }

    mAudioSource = GetComponent<AudioSource>();

    mThis = GCHandle.Alloc(this);

    if (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity &&
        distanceAttenuation &&
        distanceAttenuationInput == DistanceAttenuationInput.CurveDriven &&
        reflections &&
        useDistanceCurveForReflections)
    {
        mAttenuationData.rolloffMode = mAudioSource.rolloffMode;
        mAttenuationData.minDistance = mAudioSource.minDistance;
        mAttenuationData.maxDistance = mAudioSource.maxDistance;
        mAttenuationData.curve = mAudioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff);

        mCurveAttenuationModel.type = DistanceAttenuationModelType.Callback;
        mCurveAttenuationModel.callback = EvaluateDistanceCurve;
        mCurveAttenuationModel.userData = GCHandle.ToIntPtr(mThis);
        mCurveAttenuationModel.dirty = Bool.False;
    }
}

Oh, and because OnDestroy might be called when the object never activates, I changed the OnDestroy() method to this:

private void OnDestroy()
{
    if (mAudioEngineSource != null)
    {
        mAudioEngineSource.Destroy();
    }

    if(mThis.IsAllocated) mThis.Free();
}

I'm not sure if this is anything to go by for fixing this issue - if not, this issue can be closed.

gwenvis avatar Mar 23 '22 15:03 gwenvis

So I want to post an update: ever since applying the changes above I've had 0 crashes. I suspect there being something wrong with the order of execution in the native library somewhere.

gwenvis avatar Apr 19 '22 11:04 gwenvis

I am going to try this, I am having the same issue. Thanks for sharing.

aflatau avatar Apr 20 '22 21:04 aflatau

Unfortunately, the suggested fix listed here doesn't prevent crashes for us.

Is there some order of initialization that must be enforced to prevent this crash? It'd be nice for a developer to let us know so we can implement checks to ensure the initialization order is correct.

CodeHatchling avatar May 21 '22 15:05 CodeHatchling

I think this is potentially the same issue as I had here: https://github.com/ValveSoftware/steam-audio/issues/190

It seemed to work for me once I set the IPL_SIMULATIONFLAGS_REFLECTIONS flag, but I'm not familiar with how the Unity stuff is set up.

Aceeri avatar May 27 '22 23:05 Aceeri

To this day I've had 0 crashes when applying this fix, only a few rare ones in the editor. Whereas before it crashed about 30% of the time both in standalone and editor.
I tried reverting my changes and the crashes came back immediately so I'm kind of disappointed to hear this doesn't fix the issue!

I thought initially it had to do something with the audio thread trying to access data that doesn't yet exist (or something) though that doesn't really make sense. Alas I don't know enough about the code to make a real educated guess, though I deed peep around a little and saw nothing out of the ordinary.

I also found it impossible to replicate in a small project, for some reason it only happens in the bigger ones?? idk

gwenvis avatar Jun 16 '22 11:06 gwenvis

We've just released Steam Audio 4.1.0, which includes various crash fixes: https://github.com/ValveSoftware/steam-audio/releases/tag/v4.1.0.

Try it out and let us know if these crashes persist in the new version.

lakulish avatar Jul 05 '22 20:07 lakulish

Closing pending feedback.

kisak-valve avatar Aug 19 '22 18:08 kisak-valve