Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
C++: EventReceiver causes Access Violation

borsti
Registered User
Quote
2012-12-30 22:30:36

Hello,

I am currently experimenting with the irrKlang library. Sadly I am not that comfortable with C++...

My Problems:
1. I am trying to drop() the given Sound in the OnSoundStopped Function but it returns an ACCESS VIOLATION during runtime

2. I get an ACCESS VIOLATION when dropping the ISoundEngine at the end of the program

3. None of the possibilities for pausing/resuming works for my. I tried "mySound->setlsPaused(false)", "mySound->pause()" and many more possibilities. Which is the correct one?

Here my Test Code:
main.cpp:
include <iostream>
include <irrKlang.h>
include <tinythread.h>
include <windows.h>
include <string>
include "SongEndReceiver.h"

using namespace irrklang;
using namespace tthread;

ISoundEngine* engine = createIrrKlangDevice();
ISound* snd;

void TestThread(void * aArg)
{
while(1) {
std::cout << "Current Position: " << snd.getPlayPosition() << '\n';
Sleep(1000);
}
}

int main(int argc, const char** argv)
{
if(!engine)
return 0;
snd = engine->play2D("getout.ogg", false, false, true);
SongEndReceiver* endReceiver = new SongEndReceiver();
snd->setSoundStopEventReceiver(endReceiver);
//endReceiver->drop(); // This is not available in the class?!

std::cout << "\nHello World!\n";

char i = 0;

thread t(TestThread, 0);

while(i != 'q')
{
std::cout << "Press 'q' to quit.\n";
std::cin >> i;
}
engine->drop(); //Causes Access Violation
t.join();
return 0;
}


SongEndReceiver.h:
include <irrKlang.h>
include <iostream>

using namespace irrklang;

class SongEndReceiver : public irrklang::ISoundStopEventReceiver
{
public:
virtual void OnSoundStopped (irrklang::ISound* sound, irrklang::E_STOP_EVENT_CAUSE reason, void* userData)
{
// called when the sound has ended playing
std::cout << "sound has ended\n";
sound->drop();
}
};


Thank you very much!
Best wishes for 2013!

Greetings from Germany,
Sebastian

//edit: typo corrected


erik
Registered User
Quote
2013-01-02 10:29:37

irrKlang is supposed to be used from the same thread it was created in. I think your problems are simply caused by the thread you are creating, and calling irrklang in there.


Create reply:


Posted by: (you are not logged in)


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