Unsolved Falling into hardfault for unknown reason (no problem in debug mode)
-
Greetings everyone!
I encounter a strange problem.
My Qt App is getting data packs from a device via QSerialPort.
I store them in a global massive than when the last package is received I parse the whole massive.
After that I send a command to my device so it can continue a cycle but my App than crashes down. The strange thing about this is that if I do the same thing within a debug mode - everything works fine.
Here is this part of code from a slot:case ADC_CONT_1SEC: if(len.istd != 7) { memcpy(UART_RECEIVE_BUFFER + adc_call_command_counter, receiveBuffer, len.istd); adc_global_counter++; adc_call_command_counter += len.istd; } else if(len.istd == 7) { adc_call_command_counter = 0; for(int i = 0; i < adc_global_counter; i++) { len.cstd[1] = UART_RECEIVE_BUFFER[temp_counter + 1]; len.cstd[0] = UART_RECEIVE_BUFFER[temp_counter + 2]; temp_counter += len.istd; data_temp.cstd[1] = UART_RECEIVE_BUFFER[temp_counter - 3]; data_temp.cstd[0] = UART_RECEIVE_BUFFER[temp_counter - 2]; new_data_last = data_temp.istd[0]; number_of_new_data = (len.istd - 8) / 2; for (int n = 0; n < number_of_new_data; n++) { data_temp.cstd[1] = UART_RECEIVE_BUFFER[(temp_counter - len.istd) + n*2 + 5]; data_temp.cstd[0] = UART_RECEIVE_BUFFER[(temp_counter - len.istd) + n*2 + 6]; if(data_temp.istd[0] != 0) { ADC_DATA_BUFFER[adc_call_command_counter] = lowpass_filter(median_filter(data_temp.istd[0])); X_DATA_BUFFER[adc_call_command_counter] = (new_data_last - number_of_new_data) + n; adc_call_command_counter++; } } } clear_graph(); paint_curve(); ui->data_lcdnumber->display(QString::number(adc_call_command_counter)); adc_call_command_counter = 0; adc_global_counter = 0; COM->write(dataTransmit, 7); while(!(COM->waitForBytesWritten(-1))); } break;
-
@IRBaboon uninitialized variables and dangling pointers are the most common source for such problems.
If you can, run your app in valgrind. or use address sanitizer. these tools are really good in catching such problems.
Regards