Multithreading and IrrKlang

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
lzr
Posts: 5
Joined: Fri Mar 02, 2007 2:55 am
Contact:

Multithreading and IrrKlang

Post by lzr »

Ok, so I'm using IrrKlang as the sound engine for my game, and everytime I load something, I load on a seperate thread, while the main thread has a loading animation. Anyways, for some reason. Whenever I try to call one of IrrKlang's functions from a different thread that originally created the engine, nothing happens. Is this a bug, or am I just doing something wrong.
My Site: http://lzr.cc
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

That's interesting, but I don't see a reason why it should not work, unless your are not doing two calls to irrKlang at the same time. If you don't and it still doesn't work, try the other driver (winmm), it could behave differently.
But I'll try it out and fix it if I find a bug never thought of using irrKlang that way.
lzr
Posts: 5
Joined: Fri Mar 02, 2007 2:55 am
Contact:

Post by lzr »

Thanks. I'm not really quite sure how to switch to the winmm driver, but I'm curious to know if it can actually fix it.

Just try the following code to see for yourself that there's a problem:

Code: Select all

#include <windows.h>
#include <iostream>
#include <conio.h>
#include <IrrKlang.h>

using namespace irr::audio;
using namespace std;

#pragma comment(lib, "irrKlang.lib")

ISoundEngine* engine;

DWORD WINAPI StartThread(LPVOID iValue)
{
	engine->play2D("song.mp3");
	getch();

	return 0;
}
int main()
{
	HANDLE hThread;
	DWORD dwThreadID;

	ISoundEngine* engine = createIrrKlangDevice();

	if (!engine)
	{
		cout<<"Error creating IrrKlang device"<<endl;
		return 1;
	}

	hThread = CreateThread(NULL, 0, StartThread, NULL, 0, &dwThreadID);

	if(hThread == NULL)
	{
		DWORD dwError = GetLastError();
		cout<<"Error: "<<dwError<<endl;
		return 1;
	}

	WaitForSingleObject(hThread, INFINITE);

	engine->drop();

	return 0;
}
My Site: http://lzr.cc
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Thanks for the code, going to try it out and fix it.
lzr
Posts: 5
Joined: Fri Mar 02, 2007 2:55 am
Contact:

Post by lzr »

Thanks for trying it out. Did you get an error as well? If so, how soon can I expect (if at all) this to be fixed?

Thanks again for the awesome sound engine.
My Site: http://lzr.cc
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

I had no time until now, but I'm going to look at it in the next few days and try to push out a bug fix release if possible.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Hm, this works for me. (Apart from in your example code, the line creating the device should have been 'engine = createIrrKlangDevice(); ', without the ISoundEngine*)
What OS are you using? Are you using the latest version of irrKlang (0.6)?
Post Reply