ERR_INVALID_HANDLE on createStream() on Linux

When I call createSound() on Linux, it returns ERR_INVALID_HANDLE. Windows and Android work fine. I am using 12.7 version of FMOD.

My code:

    public static Sound LoadStreamedSound(string path)
	{
	    var buffer = FileLoader.LoadFileAsBuffer(path);
		// Internal FMOD pointer points to this memory, so we don't want it to go anywhere.
		var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

		var info = new FMOD.CREATESOUNDEXINFO();
		info.length = (uint)buffer.Length;
		info.cbsize = Marshal.SizeOf(info);

		var r = Native.createStream(
				buffer,
				FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESTREAM,
				ref info,
				out FMOD.Sound newSound
		);
		Console.WriteLine("LOAD RESULTS:" + r); // ERR_INVALID_HANDLE
		return new Sound(newSound, buffer, handle);
	}

Tested some more – and this behavior only happens if I initialize FMOD Studio (which wortks fine by itself). If I just initialize Core library, everything works as intended.

This is how I initialize:

			FMOD.INITFLAGS coreInitFlags = FMOD.INITFLAGS.CHANNEL_LOWPASS | FMOD.INITFLAGS.CHANNEL_DISTANCEFILTER;
			FMOD.Studio.INITFLAGS studioInitFlags = FMOD.Studio.INITFLAGS.NORMAL;

			var r = FMOD.Studio.System.create(out StudioSystem.Native);
			Console.WriteLine("STUDIO CREATE: " + r);

			r = StudioSystem.Native.getCoreSystem(out CoreSystem.Native);
			Console.WriteLine("CORE SYSTEM: " + r);

			// This also will init core system. 
			StudioSystem.Native.initialize(maxChannels, studioInitFlags, coreInitFlags, (IntPtr)0);

Can you try the logging version of FMOD instead, you should get some information output on the TTY as to what is going wrong.

Tried the logger library. This is what it outputted in the console (along with some dotnet stuff). There isn’t anything out of ordinary, it seems. I see some thread permission errors, tho. Running with sudo fixes them, but my game crashes anyway with same error.

[LOG] System::create : Header version = 2.01.07. Current version = 2.01.07.
STUDIO CREATE: OK
fmodstudioL |
CORE SYSTEM: OK
fmodstudioL |
[LOG] Manager::init : maxchannels = 256 studioflags = 00000000 flags 00000300 extradriverdata (nil).
[LOG] SystemI::init : Initialize version=20107 (113487), maxchannels=256, flags=0x00020300
[LOG] SystemI::setOutputInternal : Setting output to ‘FMOD PulseAudio Output’
[LOG] OutputPulseAudio::registerLib : Loaded PulseAudio version 13.99.0.
[LOG] OutputPulseAudio::enumOutput : Found output device NAME:alsa_output.pci-0000_00_05.0.analog-stereo DESC:Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] OutputPulseAudio::enumInput : Found input device NAME:alsa_output.pci-0000_00_05.0.analog-stereo.monitor DESC:Monitor of Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] OutputPulseAudio::enumInput : Found input device NAME:alsa_input.pci-0000_00_05.0.analog-stereo DESC:Built-in Audio Analog Stereo CHANNELS:2 RATE:44100.
[LOG] Thread::initThread : Init FMOD stream thread. Affinity: 0x8000000000000003, Priority: 0xFFFF7FFB, Stack Size: 98304, Semaphore: No, Sleep Time: 10, Looping: Yes.
[WRN] FMOD_OS_Thread_Callback : Cannot set real-time thread priorities due to insufficient privileges
[LOG] Thread::initThread : Init FMOD mixer thread. Affinity: 0x8000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: Yes, Sleep Time: 0, Looping: Yes.
[WRN] FMOD_OS_Thread_Callback : Cannot set real-time thread priorities due to insufficient privileges
[LOG] AsyncManager::init : manager 0xd635f8 isAsync 1 updatePeriod 0.02
[LOG] Thread::initThread : Init FMOD Studio update thread. Affinity: 0x8000000000000002, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[WRN] OutputPulseAudio::streamUnderflowCallback : Buffer underrun detected in PulseAudio.
[LOG] OutputPulseAudio::streamUnderflowCallback : Increasing buffer size - new block count = 5.
[WRN] FMOD_OS_Thread_Callback : Cannot set real-time thread priorities due to insufficient privileges
[LOG] AsyncManager::init : done
[LOG] PlaybackSystem::init :
[LOG] Thread::initThread : Init FMOD Studio sample load thread. Affinity: 0x8000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[WRN] FMOD_OS_Thread_Callback : Cannot set real-time thread priorities due to insufficient privileges
[LOG] PlaybackSystem::init : done
[LOG] Thread::initThread : Init FMOD Studio bank load thread. Affinity: 0x8000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[WRN] FMOD_OS_Thread_Callback : Cannot set real-time thread priorities due to insufficient privileges
[LOG] Manager::init : done.
fmodL |
fmodstudioL |
fmodL |
fmodL |
fmodL |
PLAY RESULTS:ERR_INVALID_HANDLE | FMOD.Channel
fmodL |
fmodL |
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at ChaiFoxes.FMODAudio.Channel…ctor(Sound sound, Channel channel) in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Shared\Channel.cs:line 402
at ChaiFoxes.FMODAudio.Sound.Play(ChannelGroup group, Boolean paused) in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Shared\Sound.cs:line 255
at ChaiFoxes.FMODAudio.Sound.Play(Boolean paused) in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Shared\Sound.cs:line 244
at ChaiFoxes.FMODAudio.Demos.Scenes.CoreDemoScene.Enter() in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos\Scenes\CoreDemoScene.cs:line 40
at ChaiFoxes.FMODAudio.Demos.Scenes.SceneController.ChangeScene(Scene scene) in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos\Scenes\SceneController.cs:line 22
at ChaiFoxes.FMODAudio.Demos.Scenes.DemoSelectorScene.<>c.b__3_2() in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos\Scenes\DemoSelectorScene.cs:line 32
at ChaiFoxes.FMODAudio.Demos.UI.Button.Update() in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos\UI\Button.cs:line 54
at ChaiFoxes.FMODAudio.Demos.UI.UIController.Update() in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos\UI\UIController.cs:line 27
at ChaiFoxes.FMODAudio.Demos.Game1.Update(GameTime gameTime) in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos\Game1.cs:line 106
at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.SdlGamePlatform.RunLoop()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at ChaiFoxes.FMODAudio.Demos.DesktopGL.Program.Main() in D:_Projects\ChaiFoxes.FMODAudio\ChaiFoxes.FMODAudio.Demos\ChaiFoxes.FMODAudio.Demos.DesktopGL\Program.cs:line 11
Aborted (core dumped)

According to your output I see:
PLAY RESULTS:ERR_INVALID_HANDLE | FMOD.Channel

However I don’t see any
LOAD RESULTS:

Also, in the log I don’t see any Sounds being loaded by FMOD, is it possible the load isn’t being called at all?

That’s because I don’t output them. Load results are OK. Besides, it works on both Windows and Android. I’ll doublecheck when I’ll get home.

Regardless of the LOAD RESULTS, there should also be logging from FMOD when you create a sound which appears to be missing unless you snipped it out of the log provided?

A year and a half later, I am finally returning to this problem. : D

Yes, it is indeed missing. The sound load logs appear when I use core-only mode - then everything works fine.
I have updated to the latest version of FMOD, the problem still persists.

My current logs:

Loading libfmodstudioL.so
[LOG] System::create                           : Header version = 2.02.08. Current version = 2.02.08.
+STUDIO: OK
Loading libfmodstudioL.so
+CORE: OK
Loading libfmodstudioL.so
[LOG] Manager::init                            : maxchannels = 256 studioflags = 00000000 flags 00000000 extradriverdata (nil).
[LOG] SystemI::init                            : Initialize version=20208 (126901), maxchannels=256, flags=0x00020000
[LOG] SystemI::setOutputInternal               : Setting output to 'FMOD PulseAudio Output'
[LOG] OutputPulseAudio::registerLib            : Loaded PulseAudio version 15.99.0.
[LOG] PulseAudio_EnumOutputCallback            : Found output device NAME:alsa_output.pci-0000_00_05.0.analog-stereo DESC:Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] PulseAudio_EnumInputCallback             : Found input device NAME:alsa_output.pci-0000_00_05.0.analog-stereo.monitor DESC:Monitor of Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] PulseAudio_EnumInputCallback             : Found input device NAME:alsa_input.pci-0000_00_05.0.analog-stereo DESC:Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] Thread::initThread                       : Init FMOD stream thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFB, Stack Size: 98304, Semaphore: No, Sleep Time: 10, Looping: Yes.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
[LOG] Thread::initThread                       : Init FMOD mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
[LOG] AsyncManager::init                       : manager 0x556c0f7f4df8 isAsync 1 updatePeriod 0.02
[LOG] Thread::initThread                       : Init FMOD Studio update thread. Affinity: 0x4000000000000002, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
[LOG] AsyncManager::init                       : done
[LOG] PlaybackSystem::init                     : 
[LOG] Thread::initThread                       : Init FMOD Studio sample load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
[LOG] PlaybackSystem::init                     : done
[LOG] Thread::initThread                       : Init FMOD Studio bank load thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFD, Stack Size: 98304, Semaphore: No, Sleep Time: 1, Looping: No.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
[LOG] Manager::init                            : done.
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
+SOUND LOAD RESULT: ERR_INVALID_HANDLE
Loading libfmodL.so
Loading libfmodL.so
+SOUND PLAY RESULT: ERR_INVALID_HANDLE
Loading libfmodL.so
Loading libfmodL.so

And here are the logs in core-only mode, when everything is working as expected:

Loading libfmodL.so
Loading libfmodL.so
[LOG] SystemI::init                            : Initialize version=20208 (126901), maxchannels=256, flags=0x00000000
[LOG] SystemI::setOutputInternal               : Setting output to 'FMOD PulseAudio Output'
[LOG] OutputPulseAudio::registerLib            : Loaded PulseAudio version 15.99.0.
[LOG] PulseAudio_EnumOutputCallback            : Found output device NAME:alsa_output.pci-0000_00_05.0.analog-stereo DESC:Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] PulseAudio_EnumInputCallback             : Found input device NAME:alsa_output.pci-0000_00_05.0.analog-stereo.monitor DESC:Monitor of Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] PulseAudio_EnumInputCallback             : Found input device NAME:alsa_input.pci-0000_00_05.0.analog-stereo DESC:Built-in Audio Analog Stereo CHANNELS:2 RATE:48000.
[LOG] Thread::initThread                       : Init FMOD stream thread. Affinity: 0x4000000000000003, Priority: 0xFFFF7FFB, Stack Size: 98304, Semaphore: No, Sleep Time: 10, Looping: Yes.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
[LOG] Thread::initThread                       : Init FMOD mixer thread. Affinity: 0x4000000000000001, Priority: 0xFFFF7FFA, Stack Size: 81920, Semaphore: No, Sleep Time: 0, Looping: Yes.
[LOG] FMOD_OS_Thread_Callback                  : Cannot set real-time thread priorities due to insufficient privileges
Loading libfmodL.so
Loading libfmodL.so
[LOG] SystemI::createSoundInternal             : Create data=0x7fa1ec061928, mode=0x00000880
[LOG] SystemI::createSoundInternal             : exinfo->cbsize             = 224
[LOG] SystemI::createSoundInternal             : exinfo->length             = 15263
[LOG] SystemI::createSoundInternal             : Stream: name='(null)', format=2, channels=2, frequency=44100, lengthbytes=15263, lengthpcm=88200, pcmblocksize=0, loopstart=0, loopend=0, mode=0x00000000, channelmask=0x00000000, channelorder=0, peakvolume=0.000000.
+SOUND LOAD RESULT: OK
Loading libfmodL.so
Loading libfmodL.so
+SOUND PLAY RESULT: OK
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so
Loading libfmodL.so

Also here’s the source code in question.

The place where I load the sound.

The inside of the method.

Initialization.

UPDATE: It seems I have found the solution? Or at least a fix that seems to do the job.

If I initialize Core system before the Studio system, both seem to work. I wasn’t initializing Core system at all in Studio mode, as far am I am aware, Studio system also inits Core system - and this seems to be the case on all other platforms.

FMOD.Factory.System_Create(out CoreSystem.Native);
FMOD.Studio.System.create(out StudioSystem.Native);

Could somebody from FMOD comment on this? Am I missing something here?

There is a requirement when using C# to call into the Core API before calling FMOD.Studio.System.create. This is due to a limitation with dependency loading in the C# runtime.
Any call into the Core API would satisfy this criteria. In our Unity integration for example we call FMOD.Memory.GetStats as an innocuous and relatively low overhead way to meet this requirement. To confirm this is the issues can you please try calling FMOD.Memory.GetStats and see if that gives you the same result?

Yep. I replaced create with FMOD.Memory.GetStats(out var currentallocated, out var maxallocated); and got the same result. Thanks for the explanation.

1 Like