c++ - ASSERT fails on CDC SelectObject() call - What can I try? -
I am working on a multi-threaded Win32 MFC application. We are providing a map and displaying it in a user's pane with custom-render objects at the top of the user interface. This user interface is going on the thread (~ 800 ms) is slow to render.
I am trying to move on my own thread to the rendering so that the menu can still be sharp, while others may still be rendering in the background. The draw thread will continuously render using the CDC. The UI thread will call a radra function, which locks the Mute X, and takes the last snapshot of cbtmap
and pulls it using the UI's CDC
each location Where the thread's cd
C is used, it is locked by Mute X.
What I see is that thread through a new CBitmap
CreatCompatibleBitmap
, and then in the CDC
of draw threads Attempting to select the new CBITmap
object.
this - & gt; M_canvas.CreateCompatibleDC (& compatibleDC); This- & gt; M_bitmap = new CBitmap (); This- & gt; M_bitmap-> CreateCompatibleBitmap (& amp; Compatible DC, m_width, m_height); M_oldbitmap = this- & gt; M_canvas.SelectObject (m_bitmap);
At this point, debug ASSERT failure in CGdiObject :: FromHandle () is a failure.
CGDObject * Pascal CGdiObject :: FromHandle (HGDIOBJ) {Chandelmark * PAMP = FXIDHMID (TRUE); // Create map if not in existence ASSERT (pMap! = NULL); CGDObject * Pobbz = (CGDObject *) PMP-> Handle (h); Acetate (pobacty == faucet || Pobject-> M_Object == H); Return punch; }
The second ASSERT
is failing because the m_hObject
handle does not match the passage. Actually, MFC is taking over, and doing a lookup to get the CBITMAP
object that was not in any way matched with the CBITmap
that just created I went.
Is this voice familiar to anyone? Can the cause of the FromHandle
method to return the wrong object? Is there a fundamental flaw with the way to create a CDC
for the draw thread, and then it is being used more and more? Is there any way I can help debug / fix this problem?
Mapping between gold handle and objects is inside.
In a multi-threaded environment, because Windows is owned by Threads, MFC Thread keeps floating and permanent window handle maps in local storage. This is true for other handlaps like GDI objects and device references. The window handles the thread in local storage, ensuring security for use by multiple threads simultaneously.
So basically, store the handle, then to manipulate the thread again, create a CBITap from the handle.
My mistake was in UI thread, which used to build my CBITMAP, and then access to the CBITMAP object from both threads.
Comments
Post a Comment