ASSERT does not work when calling CDC SelectObject () - what can I try?

I am working on a multi-threaded win32 MFC application. We visualize the map and display it on a panel in the user interface along with personalized objects on top. It is slow for rendering (~ 800 ms), which occurs in the user interface thread.

I am trying to move the rendering to my own stream so that the menu still remains while the other rendering can still work in the background. The Draw thread will constantly play its own CDC. The user interface thread will invoke the redraw function, which blocks the mutex and takes the last snapshot CBitmapand draws it using the user interface CDC. Each place where the Draw CDC thread is used is locked by the mutex.

What I see is a thread creating a new CBitmapone through CreatCompatibleBitmapand then trying to select a new object CBitmapin the Draw stream CDC.

this->m_canvas.CreateCompatibleDC(&compatibleDC);
this->m_bitmap = new CBitmap();
this->m_bitmap->CreateCompatibleBitmap(&compatibleDC, m_width, m_height);

m_oldBitmap = this->m_canvas.SelectObject(m_bitmap);

At this point in CGdiObject :: FromHandle () there is an ASSERT debugging error.

CGdiObject* PASCAL CGdiObject::FromHandle(HGDIOBJ h)
{
    CHandleMap* pMap = afxMapHGDIOBJ(TRUE); //create map if not exist
    ASSERT(pMap != NULL);
    CGdiObject* pObject = (CGdiObject*)pMap->FromHandle(h);
    ASSERT(pObject == NULL || pObject->m_hObject == h);
    return pObject;
}

ASSERT , m_hObject . , MFC , CBitmap, - CBitmap, .

? , FromHandle ? , CDC Draw, ? - , , / ?

+3
1

Golden. - .

, . GDI . .

, , , CBitmap , .

, CBitmap, CBitmap .

+2

Source: https://habr.com/ru/post/1720302/


All Articles