We are using Chartdir Version 126.96.36.199 with Qt 5.9.2, and on rare occasions we get an application crash with the lines:
DoubleArray chan_y_array = DoubleArray(p_chan_y_values->data(), p_chan_y_values->length());
DataSet* p_y_data_set = p_linelayer_y->addDataSet(chan_y_array, channel_color_line_style);// <-access violation on reading from memory in this line, 6 stack frames inside chartdir60.dll
where p_chan_y_values is a QVector<double>* with 2 values. All I get is an Exception on accessing a memory area I don't have access to from the application's code.
The crash happens in productive code, it's hard to reproduce. All I have at the moment is a 700MB crash dump file with which I can't read every memory location, but at least it doesn't look like exhausted or corruped memory.
Any idea how to track the root cause of this error?
Re: Crash in chartdir60.dll on adding a dataset to a line layer
Is the program multi-threading? From experience, in many case, these sort of issues can be due to race conditions in GUI programs. The key things to note in a GUI program is:
(a) All GUI elements (controls, widgets, etc) must run in the GUI thread (the thread that creates the GUI element). It is usually the main thread.
(b) All events (mouse events, keyboard events, etc) occurs in the GUI thread.
(c) That means any code that uses the GUI, and code that runs in event or signal handlers, must not access variables or objects created in another thread unless probably synchronized (with mutex, etc).
For your case, if p_chan_y_values is created in another thread, but the charting code is running in an event handler (such as in response to a button click or GUI timer or mouse or keyboard action), and there is no mutex or any synchronization between the threads for p_chart_y_values, this can cause this type of issues.
For debugging, try to modify the code as follows:
// This is a dummy line to verify that p_linelayer_y is not pointing to invalid memory.
// Copy the data to stack variables. This is to check the vector is valid.
double *data = p_chan_y_values->data();
std::vector temp(data, data + p_chan_y_values->length());
int lineColor = channel_color_line_style;
// Check the data values to for any other abnormal things
bool isValid = true;
for (int i = 0; isValid && (i < (int)temp.size()); ++i)
isValid = (i < 2) && ((temp[i] == Chart::NoValue) || ((temp[i] < 1E20) && (temp[i] > -1E20)));