Jump to content

  • Log In with Google      Sign In   
  • Create Account


[C++]Strange issue related to multithreading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 30 July 2012 - 10:31 AM

Hello,

Firstly, I'd like to say sorry if this is wrong forum, as issue might be related to Visual Studio.

I am using Win8 x64, Visual Studio 2012, DirectX 11 with feature level 10.0. I have 2 threads: main thread and rendering thread. Main thread initializes window, DirectX and starts rendering thread. Rendering thread is simple:
while(true) {
    for(auto &entity : renderList) {
	    //...
    }
    present();
}
While all resource loading is handled by main thread.

When I run the program it works fine, however when I attach Visual Studio's Graphics Debugger calling IASetIndexBuffer causes crash with similar debug output:
D3D11 CORRUPTION: ID3D11DeviceContext::IASetIndexBuffer: First parameter is corrupt. [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1]
First-chance exception at 0x77037945 (KernelBase.dll) in FxdTmStpTest.exe: 0x0000087D (parameters: 0x00000000, 0x04EEDB64, 0x04EECF9C).
Unhandled exception at 0x77037945 (KernelBase.dll) in FxdTmStpTest.exe: 0x0000087D (parameters: 0x00000000, 0x04EEDB64, 0x04EECF9C).
I suspect it happens because I create that index buffer on other thread than it's used at.

This issue happens on Debug x86, Debug x64 builds, however Release x64 build has no issues (I am unable to try Release x86 because of unaligned SIMD data).

If anyone has any clues what's wrong please let me know. Thank you in advance.

Sponsor:

#2 Hassanbasil   Members   -  Reputation: 192

Like
0Likes
Like

Posted 30 July 2012 - 05:50 PM

I also do some multithreaded loading and the graphics debugger crashes on it, perhaps a bug in the debugger itself, looks like it doesn't support multithreading

#3 Tordin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 31 July 2012 - 04:07 AM

the debuglayer allways work for me when i am using multithreading.

when it comes to multithreading, make sure you never let more than one thread read/write at the same time.
Even if this sounds like "that would never happen", assume it will!

that might not fix your problem, but it´s a start to work with.

it could aswell be that you have created some of your buffer wrong, or that you are trying to use them in a invalid way.
"There will be major features. none to be thought of yet"

#4 Hodgman   Moderators   -  Reputation: 28780

Like
0Likes
Like

Posted 31 July 2012 - 05:06 AM

How do you synchronise and transfer data between your two threads?

#5 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 31 July 2012 - 06:32 AM

I am unsure if I need any synchronization between ID3D11Device and ID3D11DeviceContext as they're on different threads. Right now I have no synchronization between them, could that be an issue? I thought DirectX synchronizes it automatically, since there is flag related to singlethreading (D3D11_CREATE_DEVICE_SINGLETHREADED), which I'm not using.

As for data between threads, I use concurrency::concurrent_vector from <concurrent_vector.h>.
Roughly my code looks like this:
// Scene class's field
concurrency::concurrent_vector<Entity*> entities;

// Scene::createEntity(). This is executed on Main Thread (thread1)
Entity *entity = new Entity();
entity->indexBuffer = DirectX::createIndexBuffer(...);
entity->vertexBuffer = DirectX::createVertexBuffer(...);
entities.push_back(entity);

// This is executed on Rendering Thread (thread2)
for(auto &entity : entities) {
	// any entities here will have index and vertex buffer created
	// unless they're not actually created right away and I have to wait till some event
}

Note: As I said in original post, it crashes only when I'm using Visual Studio's Graphical Debugger. Running it normally or in Debug mode doesn't cause any crashes or warning in the output.

Edited by Ripiz, 31 July 2012 - 06:37 AM.


#6 JohnnyCode   Members   -  Reputation: 207

Like
0Likes
Like

Posted 01 August 2012 - 07:53 PM

if you have main thread that alters data that render thread uses, BE AWARE. google "lock" key word. In other words, change memory of thread A only in thread A. Else you will have to synchronize.

#7 Hodgman   Moderators   -  Reputation: 28780

Like
0Likes
Like

Posted 01 August 2012 - 08:54 PM

I've not used concurrent_vector, but assuming you're not editing the entities after creation, that looks safe. I'm stumped.
How does the "unless they're not actually created right away and I have to wait till some event" bit work?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS