This is probably a noob question, but so far I'm having no luck.
I'm currently using Irrlicht in combination with Boost, CEGUI, and libpq++ (a PostgreSQL database connector). Here is a screenshot of the test program:

By clicking connect, a void function is called with a try/catch block:
- cpp Code: Select all
void connectionOpen()
{
try
{
pqxx::connection c("user=xxxx password=xxxx dbname=xxxx hostaddr=xxx.xxx.xxx.xxx port=xxxx");
pqxx::work w(c);
if (c.is_open() != true)
{
std::cout << "Connection isn't open!" << std::endl;
}
else
{
std::cout << "Connection is open!" << std::endl;
}
pqxx::result r = w.exec("SELECT * FROM demo");
w.commit();
std::cout << r[0][0].name() << std::endl;
}
catch (std::exception const& f)
{
std::cout << f.what() << std::endl;
}
}
While the server is turned on, this is not a problem. It retrieves data from the server almost instantly. Others I've sent the app to have had similar results.
However, when the server isn't running, the rendering quits entirely and Windows says the application has stopped responding. After 4-5 seconds or so, it will come back and write to the Debug window saying that it could not find a connection.
My question is: Is there a way to continue to render frames in Irrlicht while waiting for responses in outside tasks?
I've tried 3 different things:
1) Putting the Irrlicht rendering into its own thread and sleeping others.
2) Rendering frames through the Boost I/O service after a timer has expired.
3) Checking for updates inside of the While loop.
The results from the first two have been: crashing, rendering one frame and then stopping, or switching between 2 frames repeatedly in an endless loop.
The third has simply not detected the changes, or it will quit rendering and then write to the Debug window after the connectionOpen() is finished.
Here is the current render code (from the third attempt):
- cpp Code: Select all
void renderLoop()
{
do
{
if (connecting == true)
{
std::cout << "This is connecting!" << std::endl;
t.connectionThread.sleep(xt);
}
else
{
std::cout << "This isn't connecting." << std::endl;
}
renderFrame();
if(elapsed < frame)
{
boost::this_thread::sleep(boost::posix_time::millisec((frame - elapsed)));
}
else
{
boost::this_thread::sleep(boost::posix_time::millisec(6));
}
}
while (stopEngine == false && device->run());
device->drop();
}
- cpp Code: Select all
void renderFrame()
{
if (device->isWindowMinimized() != true || device->isWindowFocused() == true)
{
// Timer function beginning.
start = device->getTimer()->getTime();
// Begin the Irrlicht scene.
driver->beginScene(true, true, SColor(255,255,255,255));
// Draw all Irrlicht assets.
smgr->drawAll();
guienv->drawAll();
// Draw all Crazy Eddie's GUI assets.
CEGUI::System::getSingleton().renderGUI();
// End the scene. Rinse and repeat.
driver->endScene();
// Get the "must stop" state (thread-safe)
engineStopMutex.lock();
stopEngine=engineStop;
engineStopMutex.unlock();
// Timer function end.
end = device->getTimer()->getTime();
elapsed = end-start;
}
}
Any help would be greatly appreciated... Definitely stuck on this one.
