Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
C InvalidOperationException crash after calling Play2D twice

henry_wrage
Registered User
Quote
2014-01-05 20:20:41

I get a InvalidOperationException after calling Play2D a 2nd time:

henry
irrSoundEngine = new ISoundEngine(); 
irrSound = irrSoundEngine.Play2D("song1.mp3", true, false, StreamMode.NoStreaming);
irrSound.setSoundStopEventReceiver(this);

...wait for StopEventCause.SoundFinishedPlaying event

irrSoundEngine.RemoveSoundSource("song1.mp3");
irrSound.setSoundStopEventReceiver(null);
irrSound.Dispose();
irrSound = null;

irrSoundEngine = new ISoundEngine();

...here InvalidOperationException:
irrSound = irrSoundEngine.Play2D("song1.mp3", true, false, StreamMode.NoStreaming);


any help?


niko
Moderator
Quote
2014-01-06 09:23:03

Not sure why this happens, but is there any reason why you are using two instances of ISoundEngine? You usually only need one, and you can reuse it as long as you want. Maybe this might be a reason for your problem.


henry_wrage
Registered User
Quote
2014-01-06 10:02:29

oh sorry, no, I pasted this line accidentially. Its a global:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IrrKlang;
using System.IO;
using System.Windows.Forms;
using System.Collections;
using System.Net;

namespace myprojekt
{
class AudioPlayer : ISoundStopEventReceiver
{
protected IrrKlang.ISoundEngine irrSoundEngine;
protected IrrKlang.ISound irrSound;

public AudioPlayer()
{
irrSoundEngine = new ISoundEngine();
}...



henry
Guest
Quote
2014-01-06 11:11:29

I tried to preload both files with irrSoundEngine.AddSoundSourceFromFile. no fix.

I isolated my audio class in a new small VS2010 C project. no fix.


henry
Guest
Quote
2014-01-06 12:03:28

when I call Next() from outside of my sound class: AudioPlayer.Next(); than it works. But when Next() is called from the OnSoundStopped() event my app crashes.


public void Next()
{
DisposeSound();
PlayNextFile();
}
public void DisposeSound()
{
if (irrSound == null)
return;
irrSoundEngine.RemoveSoundSource(CurrentTrackPlaying.FileName);
irrSound.setSoundStopEventReceiver(null);
irrSound.Dispose();
irrSound = null;
}
public void OnSoundStopped(ISound sound, StopEventCause reason, object userData)
{
if (reason == StopEventCause.SoundFinishedPlaying)
Next();
}



henry
Guest
Quote
2014-01-06 13:21:44

I tried to use a different ISound object to play the second file. no fix.

Maybe this helps:

Die Laufzeit hat einen schwerwiegenden Fehler entdeckt. Fehleradresse: "0x67e6d2c6" in Thread "0x2618". Fehlercode: 0xc0000005. Bei diesem Fehler könnte es sich um ein Problem in der CLR oder in den unsicheren oder nicht verifizierbaren Teilen des Benutzercodes handeln. Übliche Ursachen dieses Bugs sind Marshallerfehler für COM-Interop oder PInvoke, die den Stapel beschädigen können.


henry_wrage
Registered User
Quote
2014-01-06 17:24:56

here is the code to reproduce the crash. all I do is call
PlayTest.Play("\\\\server\\music\\file1.mp3");
It will crash in OnSoundStopped().
But not if I call Next() before file1 finished playing.
Sorry but this must be a bug no?

using IrrKlang;


namespace PlayTest
{
class AudioPlayer : ISoundStopEventReceiver
{
public IrrKlang.ISoundEngine irrSoundEngine;
public IrrKlang.ISound irrSound;

public AudioPlayer()
{
irrSoundEngine = new ISoundEngine();
}
public void Play(string f)
{
irrSound = irrSoundEngine.Play2D(f,false); // play a sound
irrSound.setSoundStopEventReceiver(this);
}
public void Next()
{
irrSound.Stop();
DisposeSound();
irrSoundEngine.Play2D("\\\\server\\music\\file2.mp3", false);
}
public void DisposeSound()
{
if (irrSound == null)
return;
irrSound.Dispose();
}
public void OnSoundStopped(ISound sound, StopEventCause reason, object userData)
{
if (reason == StopEventCause.SoundFinishedPlaying)
{
sound.Dispose();
// InvalidOperationException:
irrSoundEngine.Play2D("\\\\server\\music\\file2.mp3", false);
}
}
}
}



niko
Moderator
Quote
2014-01-06 21:12:46

Did you try not calling Dispose()?


henry_wrage
Registered User
Quote
2014-01-07 16:06:16

Of course. s. above code.


niko
Moderator
Quote
2014-01-08 08:13:01

I think the problem occurrs because OnSoundStopped will occurr in a different thread, and this somehow might cause some race condition. You could try running irrklang in single threaded mode, and see if this fixes the problem. If so this might be the problem.
Quick workaround: Don't use the sound stopped event receiver, but test the ISound if the sound stopped by querying it via Finished


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (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