문제

I am using the function below to process an image in real time. The function is called every 10 seconds using a timer.

The problem is that I get an assertion failure , and can't figure out the exact problem. I tried CImage::ReleaseDC() and DeleteDC() for the ImageDC but no luck.

Any ideas ?

LRESULT CAutodetectDialog::AutoscanPatterns(WPARAM, LPARAM)
{
    HWND hwnd = ::FindWindow(NULL, windowTitle);

    if (hwnd != NULL)    
        for (int i=0; i<N_NUMBERS; i++)
        {        
            CImage image;
            image.Create(dbParams.width, dbParams.height, 24);

            CImageDC imageDC(image);
            ::SetWindowOrgEx(imageDC, db.topLeft.x, dbParams.topLeft.y + i * dbParams.height, NULL);
            ::PrintWindow(hwnd, imageDC, PW_CLIENTONLY);

            // Process the image - processing takes < 1 sec
            // and the image parameter is not being changed
            SaveImagePatterns(&image);                
        }            //   <-------------  This line fails , must be the destructor 
                     // of CImage : atlimage.h Line 884,  m_hDC == 0
                     // m_hDC is not NULL in the code

        return 0;
}


// Process the image - processing takes < 1 sec
// and the image parameter is not changed
void CAutodetectDialog::SaveImagePatterns(const CImage* image)
{
.........
}

This is the code that fails in atlimage.h :

inline HBITMAP CImage::Detach() throw()
{
    HBITMAP hBitmap;

    ATLASSUME( m_hBitmap != NULL );
    ATLASSUME( m_hDC == NULL );             // <------ This guy

    hBitmap = m_hBitmap;
...


...
return( hBitmap );
}

UPDATE : After commenting out the call to function SaveImagePatterns() , the assertion failure did not happen. So the problem must be in that function, despite the CImage param passed as const.

도움이 되었습니까?

해결책

This looks suspicious:

SaveImagePatterns(&image);

Since image is a local variable, depending on what SaveImagePatterns does with it, this can cause an issue since the image object is destroyed as soon as that block is exited.

다른 팁

Did you call any image->GetDC() by yourself in SaveImagePatterns?

Mind that image->GetDC() need to be paired with image->ReleaseDC().

So that m_hDC will be NULL.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top