ValveSoftware / steam-audio

Steam Audio
https://valvesoftware.github.io/steam-audio/
Apache License 2.0
2.28k stars 159 forks source link

[ Unity / SteamAudioSource.cs ] System.InvalidOperationException: Handle is not initialized. #369

Open AlmazowFaradey opened 1 month ago

AlmazowFaradey commented 1 month ago

System Information Please provide the following information about your system:

Issue Description SteamAudio does not create sound properly in any way, it does not reflect off the walls, is not calculated, is not muted in case of obstacles (Does not work at all), but when debugging starts in the visual studio, instantly (When the game is not even included in the Editor), debugging immediately stops in the SteamAudioSource file.CS and raises an exception stating that "Handle is not initialized".

Detailed error: System.InvalidOperationException: Handle is not initialized. at System.Runtime.InteropServices.GCHandle.Free () [0x00034] in :0 at SteamAudio.SteamAudioSource.Finalize () [0x00000] in E:\Path-To-Project\Project_Name\Assets\Plugins\SteamAudio\Scripts\Runtime\SteamAudioSource.cs:230

Steps To Reproduce Steps to reproduce the behavior:

  1. Install SteamAudio using .unitypackage;
  2. Specify the use of SteamAudio in the Unity settings;
  3. Open regular scripts in the Unity project in Visual Studio (I have version 2022);
  4. Start debugging the project in Visual Studio;
  5. Run debugging from Visual Studio as a session in Unity;
  6. See the error as "Handle is not initialize"

image

achandak commented 1 month ago

Hi @AlmazowFaradey - I am not able to reproduce this issue on our end. I created a standalone project in Unity 2022.3.14 and imported latest version of Steam Audio.

Let me know if there is a standalone minimal repro you are able to share.

jackyyang09 commented 1 week ago

I can't confirm if SteamAudio is broken like in AlmazowFaradey's case in my own project, but I've managed to reproduce the debugging issue in a separate smaller project.

On my side, I used Unity 2022.3.39f1 using URP with the latest version of Steam Audio (4.5.3). I also use Visual Studio 2022.

Steps to Reproduce

  1. Enable Steam Audio in the Project Settings.
  2. In the current scene (SampleScene.unity), create a new GameObject.
  3. Add an AudioSource and attach a SteamAudioSource component
  4. Create a new Monobehaviour class "Test.cs"
  5. Open the class in Visual Studio and attach the debugger
  6. Enable debugging in Unity when prompted
  7. Enter Play Mode in Unity
  8. Unity will begin "Reloading Domain" and immediately get caught by an exception in the debugger image

I've found that this issue can be avoided by turning on the debugger during runtime well after Unity has entered Play Mode

I've encountered this issue on two computers, one running Windows 10 and another running Windows 11.

I can provide the full project if needed, but creating a new project using Unity's 2D URP template should be sufficient for reproducing the issue.

lakulish commented 1 week ago

@jackyyang09 This issue was fixed in the following commit: https://github.com/ValveSoftware/steam-audio/commit/c565da273e045566c440b57de323260e6932c8ab. You can get the latest version of SteamAudioSource.cs, which should resolve the issue.

This will, of course, be part of the next official release of Steam Audio.