ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Chart Dialog Crashes After Calling CImageMapHandler_destroy()
Posted by Fabio on Jan-08-2016 06:00
Hello,

We have a Qt 5.5 project with ChartDirector 6.0 that has a chart dialog, which is a mix of the examples xyzoomscroll and realtimezoomscroll. The dialog displays real-time line charts (as the one in realtimezoomscroll) and real-time scatter charts (as the one in xyzoomscroll).

The application works as expected for an hour or so, and after that it crashes. The Qt debugger reports the following messages:

RaiseException
chartdir60!CImageMapHandler_destroy

Some of the relevant messages in this forum suggest commenting out the calls to setImageMap() and getHTMLImageMap() to determine whether or not the problem is with the image map. I commented out the only call to those functions in the original updateImageMap() of the examples. However, after running the application, it crashes again after one hour, reporting the same above-mentioned exception. Also, the class has seven arrays holding the data series, each with a number of samples of ten thousand. I understand that in such a case, the image map can consume a lot of resources.

We will greatly appreciate any help to debug this issue,

Fabio

  Re: Chart Dialog Crashes After Calling CImageMapHandler_destroy()
Posted by Peter Kwan on Jan-09-2016 03:21
Hi Fabio,

From experience, the name in the debugger report is not reliable for released mode
code. It is possible the crash location is not related to CImageMapHandler_destroy.

When the code crash, the debugger will try to determine the crashed function using the
memory address of the crash site. This works if there are debugging symbols in the DLL.
As ChartDirector DLL is "release mode", there is no debugging symbol, and the only
symbols are those of the public API. So the debugger ends up showing the symbol of the
nearest API before the crash site, which can be very far away from the crash location
and may not be related to the crash.

To confirm if CImageMapHandler_destroy is the cause of the problem, one method is to
open the "chartdir.h" header file, find the method that calls
"CImageMapHandler_destroy" (there is only one line that calls this method), and insert
an assert statement in front, like "assert(false);". In this way, if your code causes this
method to be used, it should stop at the assert statement. If your code do not use
image map at all, it should not cause this method to be used. (The
CImageMapHandler_destroy is never called within "chartdir60.dll". It only purposes is to
act as the API to be called by code outside the DLL.)

For C++, the crash can be many causes, most of them are due to memory corruption.
The most common ones are invalid pointers (dangling pointers, uninitialized pointers),
using memory that are already freed, writing to memory that are out of bounds (eg. an
array is allocated for 24 elements but the 25th element is  accessed), text strings that
are not null terminated, out of memory (due to memory leak, memory fragmentation or
allocating an exceptionally large memory block due to mistake), etc.. For multi-threaded
code, memory corruption due to threading issue is also possible.

Another complication in C++ is that the cause of the problem may not be related to the
crash site. For example, if some code corrupts the memory of an object, the crash will
occur only when the object is later used by other code, which may not be related to the
code causing the corruption.

For your case, as a first step, you may consider to add the "assert" statement above (to
confirm if the issue is related to the image map). You may also try to isolated the
charting code as much as possible. For example, you may use hard coded data for
everything (eg. instead of using c->addTitle(myTitle); use c->addTitle("abcd");). When
the code runs, try to monitor the memory usage to see if there is any memory leak. This
may help to determine how the problem occurs.

Regards
Peter Kwan

  Re: Chart Dialog Crashes After Calling CImageMapHandler_destroy()
Posted by Fabio on Jan-09-2016 06:02
Hi Peter,

Thank you for your prompt and insightful answer.

Since the application displays real-time charts, for a couple of them I have to update the view port control [in drawFullChart()] with a new set of data. I was missing to delete the old mini chart causing a memory leak. The solution was to add:

// Set the chart image to the view port control
delete viewPort->getChart();     // Added to solve memory leak
viewPort->setChart(miniXyChart);

You may consider this issue as resolved.

Best regards,

Fabio