Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
SEHException was unhandled

rickst13
Registered User
Quote
2013-10-03 07:15:34

I have this function in my CSharp XNAgame:

public static ISound PlaySound(ISoundSource soundSource, bool loop = false)
{
return engine.Play2D(soundSource, loop, false, false);
}


I pass in a sound source any time I play a sound effect. Usually, everything is fine, but occasionally, the "return engine.Play2D(soundSource, loop, false, false);" throws an exception, and I cannot figure out what is going on.

SEHException was unhandled
{"External component has thrown an exception."}
Error Code: -2147467259


niko
Moderator
Quote
2013-10-04 06:08:44

Difficult to say what the problem might be here, it could be anything. Are you doing something unusual with the engine, or is there any specific time where this happens? Maybe you are freeing some resources of the engine, which still need to be there, and it crashes because if that.
However, any more details on how you are using irrklang would help. :)


rickst13
Registered User
Quote
2013-10-04 08:39:35

I am still trying to see if there is something that I can do that will reliably cause it to happen, but have had no luck so far.

I am not doing anything too fancy with irrKlang (v 1.4 - .Net 4).

It is a small game that has a static class with an ISoundSource for each game sound.

public static class Sounds
{
public static ISoundSource Spawn;
public static ISoundSource Jump;
public static ISoundSource DoubleJump;
}


When the game starts, all of the ISoundSources get initialized from .wav files.
Sounds.Spawn            = AudioManager.GetSoundSourceFromFile("spawn.wav");
Sounds.Jump = AudioManager.GetSoundSourceFromFile("jump.wav");
Sounds.DoubleJump = AudioManager.GetSoundSourceFromFile("doubleJump.wav");


public static ISoundSource GetSoundSourceFromFile(string path)
{
return engine.AddSoundSourceFromFile("Content\\sounds\\" + path);
}

I have a playerstate machine that calls certain sounds by passing in an ISoundSource.

public void JumpStart()
{
Velocity.Y = -JumpImpulse;
animationManager.Trigger("jump");

AudioManager.PlaySound(Sounds.Jump);
}


public static ISound PlaySound(ISoundSource soundSource, bool loop = false)
{
return engine.Play2D(soundSource, loop, false, false); //This is where the SEHException occurs
}


When it crashes, it crashes playing a sound that will have played fine many times before the crash happens.

I have reproducred on 2/2 computers that I have tried it on.


niko
Moderator
Quote
2013-10-04 09:45:14

This looks all very normal and should work usually. Very strange.
Are you maybe using an old irrklang version?


rickst13
Registered User
Quote
2013-10-06 18:20:04

I am using 1.4.0b.

I've done a lot of additional testing this weekend, but still haven't figured out what is causing it. It isn't one one particular sound either. It seems to happen with multiple sounds.

On top of that, there are times where it doesn't throw an exception but instead hangs for up to 2 seconds on engine.Play2D. (like it is stuck in a loop for a while).


niko
Moderator
Quote
2013-10-06 21:44:09

Difficult to say what this could be. Did you try using maybe the engine.Play2D call wich takes a file name instead of a sound source as first parameter? Getting the sound source manually first isn't really necessary. Who knows, maybe this is a workaround already.


rickst13
Registered User
Quote
2013-10-06 23:23:14

Will using the file name load it from disk each time or not? That is what I was trying to avoid.


rickst13
Registered User
Quote
2013-10-07 03:43:15

Hmmm, it is happening with the string version of Play2D as well. It never seems to happen right away. I'll just turn the game on and go to an area with a sound that fires every second, and come back later and it will have hit the SEHException.

I have definitely used irrKlang on past projects and never had this error, but I think those used earlier versions of irrKlang (1.0.3861.18767). I am going to try to use that instead to see if it fixes the issue.


rickst13
Registered User
Quote
2013-10-07 06:38:00

After going back to 1.0.3861.18767, I have not gotten it to crash or slow down yet.

Edit: Nevermind, it was too good to be true. Just hit the exception again.


rickst13
Registered User
Quote
2013-10-08 00:42:42

Alright, I just wrote a small program that repeats a sound over and over. I'll see if this causes the exception.

using System;
using System.Collections.Generic;
using IrrKlang;

namespace IrrKlangNet4Test
{
class Program
{
static ISoundEngine engine = new ISoundEngine();

static void Main(string[] args)
{
string path = "playerDeath.wav";

ISoundSource sound = engine.AddSoundSourceFromFile(path);

Console.WriteLine("Press any key to exit.");

int i = 1;
while (!Console.KeyAvailable)
{
Console.WriteLine("Playing Sound. Try: " + i);
engine.Play2D(sound, false, false, false);
System.Threading.Thread.Sleep(2000);
++i;
}
}
}
}



rickst13
Registered User
Quote
2013-10-08 17:07:18

Is it possible that the SEHException would have happened if there were ISounds that didn't have their Dispose() called on them?

I added this to my Update():

(soundEffects is a List of all of my playing ISounds)

for (int i = soundEffects.Count - 1; i >= 0; --i)
{
ISound iS = soundEffects[i];

if (iS != null && iS.Finished)
{
StopSound(iS);
}
else if (iS == null)
{
soundEffects.Remove(iS);
}
}


And then here is StopSound
public static void StopSound(ISound sound)
{
if (sound != null)
{
sound.Stop();
soundEffects.Remove(sound);
sound.Dispose();
sound = null;
}
}


I ran the game all night without a single crash. This seems to have done the trick.


niko
Moderator
Quote
2013-10-09 08:32:42

Hm, not sure what you are doing now, are you now calling dispose or not so that it works?


rickst13
Registered User
Quote
2013-10-09 18:45:20

Now, I am making sure every sound is getting disposed when it is done playing. It is working!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internati?nal" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact