Solved

A MDI app, CScrollView, in OnDraw works fine in debug, nothing displayed in release! WHY???

Posted on 2000-02-16
15
400 Views
Last Modified: 2013-11-20
Hi,

I have this application (MDI)... In it are views (CScrollView) that are
displayed using overloading of OnDraw.

In OnDraw I display a bunch of thumbnails contained in a STL set
(ie. set<string>, where string is filename)...
Each thumbnail get a RECT and tools are activated whenever
user click inside a rect...

In DEBUG, I see everything displayed and the tools match the picture
seclected...

BUT in release NOTHING is displayed! Yet, the RECT is set because
I can select an image (tools adjusted)! It's just that it doesn't
get displayed!!!!!!! Any idea why? And how to fit it?

What could be missing in release that is there in debug???

here is the code of the DrawBitmap function used to display the
image. Any hints as to what is going wrong will be appreciated ;-)

void CMyView::DrawBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, int xDest, int yDest, int width, int height, bool selected )
{
       // Get logical coordinates
       BITMAP bm;
       ::GetObject( hBitmap, sizeof( bm ), &bm );
       CPoint size( bm.bmWidth, bm.bmHeight );
       pDC->DPtoLP(&size);

       CPoint org(0,0);
       pDC->DPtoLP(&org);

       // Create a memory DC compatible with the destination DC
       CDC memDC;
       memDC.CreateCompatibleDC( pDC );
       memDC.SetMapMode( pDC->GetMapMode() );
       
       //memDC.SelectObject( &bitmap );
       HBITMAP hBmOld = (HBITMAP)::SelectObject( memDC.m_hDC, hBitmap );
       
       
       // Select and realize the palette
       if( hPal && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
       {
               SelectPalette( pDC->GetSafeHdc(), hPal, FALSE );
               pDC->RealizePalette();
       }
         ::SetStretchBltMode(memDC.m_hDC, COLORONCOLOR);
         //pDC->StretchBlt(xDest, yDest, width, height, &memDC, 0,0, bm.bmWidth, bm.bmHeight, SRCCOPY );
       //not stretched but cropped
         pDC->BitBlt(xDest, yDest, width, height /*size.x, size.y*/, &memDC, 0,0 /*org.x, org.y,*/, (selected) ? SRCINVERT:SRCCOPY);

       ::SelectObject( memDC.m_hDC, hBmOld );
}

What's going on in there ?????????

Thanks!
0
Comment
Question by:aquila98
  • 9
  • 6
15 Comments
 
LVL 4

Expert Comment

by:abancroft
ID: 2532214
Can't see anything wrong, but try checking some function return values to see where things are going wrong.
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532332
Hmmmmmmmmm.

I narrow it down somewhat...

Its the HBITMAP that does not seems to be ok in
release! Here it is:
void CMyView::DrawBitmap( CDC *pDC, HBITMAP hBitmap, HPALETTE hPal, int xDest, int yDest, int width,
                int height, bool selected )
                {
                       // Get logical coordinates
                       BITMAP bm;
                       ::GetObject( hBitmap, sizeof( bm ), &bm );

the  bm.bmWidth, bm.bmHeight  are 1 in release and
are correct in debug!

Now this HBITMAP comes from this code:

CBitmap* pBitmap= NULL;
CPalette* pPalette= NULL;
GetBitmapAndPalette(theImage, &pBitmap, &pPalette, pDC);

and then of course CMyView::DrawBitmap(pDC,
(HBITMAP)*pBitmap...)

and

BOOL CMyView::GetBitmapAndPalette(XImage* pImage, CBitmap **bitmap, CPalette **pal, CDC* pDC)
{
      SECJpeg* dib= pImage->GetThumbnail();

      if (dib != NULL)
      {
            (*bitmap)= dib->MakeBitmap(pDC);
....

Now SECJpeg is a cless from ObjectiveToolkit (stingray's)
and this call to dib->MakeBitmap(pDC); works only
in debug! In release it does not! WHY?????????????

Further, if I put this code:
SECDib pp;
pp.CreateFromBitmap(pDC, (*bitmap));
pp.SaveImage("toto.bmp");

the file "toto.bmp" is ok in debug but of size 1k in release!

So this is the culprit :SECImage::MakeBitmap()
But why does it fail in release and not in debug????

Anyone familiar with stingray?

I used it (objective toolkit 6.02) because their classes
had a nice wrapper to jpg and bmp but it does not
work :(

Do you have any idea why the function fails in release?

thanks!
0
 
LVL 4

Expert Comment

by:abancroft
ID: 2532366
Before the call to GetBitmapAndPalette(), is there any way to verify that pImage is valid? Maybe it's been corrupted before the call.

Also, is there any way to check that pImage->GetThumbnail() is working correctly?

When I come across a bug like this, I usually try commenting out code (or replacing it with simpler code) until the problem goes away. That helps narrow down the bug some more.

Another approach is to generate an app (using AppWizard) and gradually introduce your problem code until the bug appears.
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532375
Sorry...

Might as well put in the code from MakeBitmap!
Here it is:

CBitmap* SECImage::MakeBitmap(CDC *pDC)
{
    ASSERT_VALID(pDC);

    CBitmap* pBitmap = new CBitmap();
      CBitmap* pBitmap2;
      CDC *pNewDC = new CDC();
      pNewDC->CreateCompatibleDC(pDC);
#ifdef WIN32
      pBitmap->CreateCompatibleBitmap(pDC,
            m_dwWidth, m_dwHeight);
#else
      pBitmap->CreateCompatibleBitmap(pDC,
            (int)m_dwWidth, (int)m_dwHeight);
#endif
      pBitmap2 = pNewDC->SelectObject(pBitmap);

#ifdef WIN32
    ::StretchDIBits(
            pNewDC->GetSafeHdc(),
            0,0,
            m_dwWidth, m_dwHeight,
            0,0,
            m_dwWidth, m_dwHeight,
            m_lpSrcBits,
            m_lpBMI, DIB_RGB_COLORS,
            SRCCOPY);
#else
    ::StretchDIBits(
            pNewDC->GetSafeHdc(),
            0,0,
            (int)m_dwWidth, (int)m_dwHeight,
            0,0,
            (int)m_dwWidth, (int)m_dwHeight,
            m_lpSrcBits,
            m_lpBMI, DIB_RGB_COLORS,
            SRCCOPY);
#endif            

      pBitmap2 = (CBitmap *)pNewDC->SelectObject(pBitmap2);
      pNewDC->DeleteDC();
      delete pNewDC;
      return pBitmap2;
    // return pBitmap;
   
}

Now why would this not work in release????????????
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532382
Yes, GetThumbnail works. If I save it in a file I see it ok.

So its really MakeBitmap that fails :(
0
 
LVL 4

Expert Comment

by:abancroft
ID: 2532383
How are you generating the device context you pass to all these functions?
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532397
No...

Its all being done in void CMyView::OnDraw(CDC* pDC)

So its the dc I get from the view some where...

Weird!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:abancroft
ID: 2532413
Hmmm...when a DC is created it has a 1x1 monochrome bitmap in it.

If this is the case when it's passed to OnDraw() (and I'm not 100% sure about this) then the call to CreateCompatibleBitmap() in SECImage::MakeBitmap() will create the same thing....

Try using the DC from GetDC() & passing it to MakeBitmap(). Call ReleaseDC() afterwards.
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532454
Yes... I read that somewhere about the 1X1 bitmap ;-)

Except, using GetDC() did not changed anything!

How could the DC from OnDraw() be corrupted in
release and not in debug? How can I test a valid DC???

If there a kind of
AFX_VALID_MANAGE_INSTANCE_OR_SOMETHING(dc)
function that would ensure I have a valid dc????

Thanks for your efforts ;-)
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532466
and yet...
i have this also being drawn in OnDraw()
pDC->TextOut(pt.left,
pt.bottom-1,pI->GetOriginalName().c_str());

and I see this filename correctly displayed in debug AND
release! So the DC seems to be corrupted ONLY in the
case of a CBitmap object????????
0
 
LVL 4

Expert Comment

by:abancroft
ID: 2532474
Then it's not the DC, but your XImage item.

Anyway to check it?
0
 
LVL 2

Author Comment

by:aquila98
ID: 2532517
the XImage must be good since I can get its
thumbnail (a SECJpeg*) and save to disk in a file
I can see if ok (acdsee displays it)...

so its back to MakeBitmap that somehow builds a
monochrome bitmap of size 1X1 from the DC
with a valid image.

This dc is good when I draw text but not when I
draw bitmaps.

Something happens to the dc (?) when the object
is a CBitmap and were in release that does not in debug!
But what?

Its getting hopeless?
0
 
LVL 4

Accepted Solution

by:
abancroft earned 70 total points
ID: 2532532
OK.

Try this, just before the call to MakeBitmap():
CBitmap bmpTest;
bmpTest.CreateBitmap(32, 32, 1, 24, NULL);
CBitmap *pBmpPrev = pDC->SelectObject(&bmpTest);
(*bitmap)= dib->MakeBitmap(pDC);
(void)pDC->SelectObject(pBmpPrev);


0
 
LVL 2

Author Comment

by:aquila98
ID: 2532598
>(

I did put in your code and it changed nothing...
But i decided to clean and rebuild all my app

and now I get finally an error in (you guessed it!)
LoadThumbnail....

Seems devstudio was mixed up and did not compiled
the project properly (it's in a dll)...

I think a VERIFY insterd of an ASSERT will ensure
the function is properly called both in debug and in release
and now that I have an error that makes sense I can go on
on my own ;-)

Thank you for your time ;-)



0
 
LVL 2

Author Comment

by:aquila98
ID: 2532603
oops! forgot to give you points ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
Get filename and folder into excel 7 69
ShiftLeft challenge 21 78
Message not shown 5 34
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now