• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
SamiHuutoniemi

Boost threaded application crashes

3 posts in this topic

Hello!

I have a problem with Boost threads. The program is a "for fun" program that draws the Mandelbrot set in DirectX 11. I want to use threads to be able to make use of a progress bar (or circle in this case), as it takes around 30-40 seconds to calculate the image at full HD on this computer. To calculate the image, I have a Mandelbrot class with a method "Calculate", which fires up 4 threads that split the calculation into 4 parts of the image. If I just instantiate an object of the Mandelbrot class, and call the Calculate-method, all works. However, I cannot use the progress circle this way. To do that, I want to fire up another thread, which has the Calculate method as starting point, and let the main thread go on with the progress circle business. This works sometimes, but most of the time, the application crashes and burns. Badly. Seems random when it crashes as well. Anybody have boost experience, perhaps in combination with DirectX 11?

I think I'm correct in that device context calls are not threadsafe, why I have arranged for a mutex to lock every time the device context is used. This should not be needed for the Direct3D Device, right?

If it crashes (which is most of the times I run it), only two of the calculate-threads terminate. The other two + the "CalcThread" do not finish. Any ideas?

Some code.

Dont worry about the making of progress circle objects. It's extremely inefficient. I know. But it should have nothing to do with the issue.
[source lang="cpp"]void MandelbrotMain::InitializeObjects() {
Shader* unlitTextureShader = new Shader(d3dEngine, UNLIT_TEXTURESHADER);
unlitTextureShader->Initialize();
shaders["UNLIT_TEXTURESHADER"] = unlitTextureShader;

pMandelbrot = new Mandelbrot(d3dEngine, shaders["UNLIT_TEXTURESHADER"]);
//pMandelbrot->Calculate();
boost::thread* t1 = new boost::thread(boost::bind(&Mandelbrot::Calculate, pMandelbrot));
OutputDebugString(L"CalcThread starting: "); OutputDebugStringA(ToString(t1->get_id()).c_str());
}

void MandelbrotMain::GameLoop() {
MSG msg;
while (true) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT) {
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {

/* RENDER THE SCENE */

d3dEngine->BeginScene(XMFLOAT4(0.0f, 0.0f, 0.0f, 0.0f));
Sprite* pSprite;

if (pMandelbrot->GetDone()) {
pSprite = pMandelbrot->GetSprite();
pSprite->ResetTransforms();
pSprite->Scale(700.0f, 400.0f, 1.0f);
pSprite->Render();
}
else {
if (pProgress) {
delete pProgress;
pProgress = 0;
}

pProgress = new Progress(d3dEngine, shaders["UNLIT_TEXTURESHADER"], pMandelbrot->GetPercentDone());
pSprite = pProgress->GetSprite();
pSprite->ResetTransforms();
pSprite->Scale(100.0f, 100.0f, 1.0f);
if (!pMandelbrot->GetDone()) {
pSprite->Render();
}
}


if (pProgress) {
delete pProgress;
pProgress = 0;
}


d3dEngine->EndScene();
/* END OF RENDERING */
}
}
}
[/source]
[source lang="cpp"]void Mandelbrot::Calculate() {
boost::thread t1(boost::bind(&Mandelbrot::CalculateMandelbrotRange, this, _1, _2), -1.0f, -0.50000001f);
OutputDebugString(L"\nThread 1 starting: "); OutputDebugStringA(ToString(t1.get_id()).c_str());
boost::thread t2(boost::bind(&Mandelbrot::CalculateMandelbrotRange, this, _1, _2), -0.5f, -0.00000001f);
OutputDebugString(L"\nThread 2 starting: "); OutputDebugStringA(ToString(t2.get_id()).c_str());
boost::thread t3(boost::bind(&Mandelbrot::CalculateMandelbrotRange, this, _1, _2), 0.0f, 0.49999999f);
OutputDebugString(L"\nThread 3 starting: "); OutputDebugStringA(ToString(t3.get_id()).c_str());
boost::thread t4(boost::bind(&Mandelbrot::CalculateMandelbrotRange, this, _1, _2), 0.5f, 0.99999999f);
OutputDebugString(L"\nThread 4 starting: "); OutputDebugStringA(ToString(t4.get_id()).c_str());
OutputDebugString(L"\n");

t1.join();
t2.join();
t3.join();
t4.join();

pSprite = new Sprite(pD3DEngine, pShader);
pSprite->Initialize(0, pixels, xw, yw, xw*16); //12 = 4 bytes per color, 3 colors (RGB), xw*12 is number of bytes per row

delete [] pixels;

OutputDebugString(L"Done, let's render\n");
done = true;
}
[/source] Edited by SamiHuutoniemi
0

Share this post


Link to post
Share on other sites
When you say 'crash' - what exactly is happenning? I.E. is it an access violation or what?

FWIW, it's not really worth doing your own threading for paralellism - it's simpler and more scaleable to use Intel Threaded Building Blocks or Microsoft Parallel Patterns Library.

Not that you have to of course - post more info and we'll try to help.
1

Share this post


Link to post
Share on other sites
I get an unhandled exception. It doesnt really give me much more information that this. I have only worked on this on my laptop. On my more powerful desktop, I have run it about 10 times in a row without crashes now. Starting to think it's just as simple as an "out of memory" issue. Could it be this?
1

Share this post


Link to post
Share on other sites
Hard to tell, but possible - paste the entirety of the message you get, please [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

An unhandled exception could be a real c++ exception, or more likely SEH reporting an access violation.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0