Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Falling into hardfault for unknown reason (no problem in debug mode)
Forum Updated to NodeBB v4.3 + New Features

Falling into hardfault for unknown reason (no problem in debug mode)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 229 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IRBaboon
    wrote on last edited by
    #1

    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;
    
    aha_1980A 1 Reply Last reply
    0
    • I IRBaboon

      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;
      
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      Qt has to stay free or it will die.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved