Multithreading and IrrKlang
Multithreading and IrrKlang
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
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.
But I'll try it out and fix it if I find a bug never thought of using irrKlang that way.
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:
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
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.
Thanks again for the awesome sound engine.
My Site: http://lzr.cc