Page 1 of 1

ITChart Draw() Exceptions

Posted: Thu Apr 07, 2005 7:14 pm
by 9523585
I am calling the TChart Draw(DC, Left, Top, Right, Bottom: Integer) method and I see a range check error, sometimes. It is like I get 3 exceptions and then it draws properly. I saw a similar bug reported with printing, and wonder if this isn't a related issue.

Code: Select all

   CRect rect = get_window_rect();
   CDC *dc = parent->GetWindowDC();
   CDC memdc;
   memdc.CreateCompatibleDC(dc);
   if(cached_bmp == 0 ||
     (bmp_width != rect.Width() || bmp_height != rect.Height()))
   {
      if(cached_bmp)
      {
         cached_bmp->DeleteObject();
         delete cached_bmp;
      }
      cached_bmp = new CBitmap;
      bmp_width = rect.Width();
      bmp_height = rect.Height();
      cached_bmp->CreateCompatibleBitmap(dc,bmp_width,bmp_height);
   }
   CBitmap *old_bmp = memdc.SelectObject(cached_bmp);
   try
   {
      Draw(reinterpret_cast<long>(memdc.m_hDC),0,0,rect.Width(),rect.Height());
   }
   catch(COleDispatchException *e)
   {
      if(cached_bmp)
      {
         cached_bmp->DeleteObject();
         delete cached_bmp;
         cached_bmp = 0;
      }
      e->Delete();
      trace("TChart::draw() catch(COleDispatchException)");
   }
   catch(COleException *e)
   {
      if(cached_bmp)
      {
         cached_bmp->DeleteObject();
         delete cached_bmp;
         cached_bmp = 0;
      }
      e->Delete();
      trace("TChart::draw() catch(COleException)");
   }
   memdc.SelectObject(old_bmp);
   ReleaseDC(&memdc);
   ReleaseDC(dc);

Posted: Thu Apr 14, 2005 8:36 pm
by Pep
Hi,

I've tried to reproduce the problem here using the Draw() method, but it does not give me any error using the latest v7.03. Which TeeChart Pro version are you using ? Also, could you please post an example into the news://steema.net/steema.public.attachments newsgroup with which I can reproduce the problem "as is" here ?

Posted: Thu Apr 21, 2005 8:31 pm
by 9523585
Hi Josep,

I am using the latest version. I have sent a project to the attachments group per your request. It is a dialog app that loads a .tee file. All you have to do is resize the dialog to see the exceptions.

GL

Posted: Fri Apr 22, 2005 3:05 pm
by narcis
Hi TMECHAM,

I've tested the application you sent and it works fine here for me.

Which Visual C++, operating system, graphic card, ... are you using? Can you run this application in another machine to see if it works there?

Posted: Fri Apr 22, 2005 4:23 pm
by 9523585
I have reproduced it on both of my development machines:

PC#1 - WinXP SP2, VC++.Net 2003, NVIDIA GeForce FX 5200

PC #2 - W2K SP4, VC++.Net 2002, Matrox G450 DualHead

I see the exceptions on load about 1 in 4.

When I resize the dialog I see them every repaint event.

I'm catching the exceptions and just dumping them out to the debug console ...

First-chance exception at 0x7c81eb33 in tchart_test.exe: Microsoft C++ exception: COleDispatchException @ 0x0012ee78.
CTchart1::draw() catch(COleDispatchException)
First-chance exception at 0x7c81eb33 in tchart_test.exe: 0x0EEDFADE: 0xeedfade.
First-chance exception at 0x7c81eb33 in tchart_test.exe: Microsoft C++ exception: COleDispatchException @ 0x0012ee78.
CTchart1::draw() catch(COleDispatchException)
First-chance exception at 0x7c81eb33 in tchart_test.exe: 0x0EEDFADE: 0xeedfade.

Posted: Fri May 20, 2005 7:25 pm
by 9523585
I'm still seeing this with the latest version. Is there anything else I can do to help squash this bug?

Thanks

Posted: Mon May 23, 2005 10:05 am
by Pep
Hi,

I've been reviewing the sample you sent us, and I think it's not a problem related with the Chart, if you comment the following line :
the_chart.ShowWindow(SW_HIDE);
it works fine. I think the problem is related on how you're creating the bmp.

Posted: Tue May 24, 2005 3:30 pm
by 9523585
I've resubmitted another project to the attachments group. I have simplified my code so that the problem should be easier to see. I have created 2 windows, one that has the chart and another that calls the Draw method of the chart. I am drawing into the same DC that gets passed into the Draw method and my draw code always works, so I know the DC and Bitmap associated with it are valid. The question is why is the chart throwing an exception from the Draw method a majority of the time?

With my old example, when you comment out the ShowWindow(SW_HIDE) code, the draw code that generated the exception was never being called because the paint rect was 0.

I hope this new code will help.

Thanks,
Tyler