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. Stack Overflow, why?
QtWS25 Last Chance

Stack Overflow, why?

Scheduled Pinned Locked Moved Solved General and Desktop
overflow
7 Posts 4 Posters 3.6k 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.
  • R Offline
    R Offline
    robro
    wrote on last edited by
    #1

    Hello,

    I have a bug causing a stack overflow, but I have absolutely no clue what the problem could be.

    Basically I am sending messages to a CAN interface and if I do it quickly I get a stack overflow.
    If I wait some milliseconds before calling the function again the program runs fine.

    This is the code where the debugger stops:

    bool transmitMessage(int NodeNumber, const int &var1, const int &var2)
    {
         quint32 Id = getID(NodeNumber);
    
         QByteArray ba;
         ba.resize(8);
         ba[0] = (qint8) var1;
         ba[1] = (qint8) (var1>> 8);
         ba[2] = (qint8) (var1>> 16);
         ba[3] = (qint8) (var1>> 24);
         ba[4] = var2;
         ba[5] = (qint8) (var2>> 8);
         ba[6] = (qint8) (var2>> 16);
         ba[7] = (qint8) (var2>> 24);
    
         bool success = writeCanMessage(cobId,ba);
         QTimer timer;
         timer.setSingleShot(true);
         QEventLoop loop;
         connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
         timer.start(100); 
         loop.exec();
    
         return success; //<- here the debugger stops!
    }
    
    bool writeCanMessage(quint32 identifier, QByteArray payload)
    {
        QCanBusFrame frame;
        frame.setFrameId(identifier);
        frame.setPayload(payload);
        return (ptrCanBus->writeFrame(frame)); //pointer to QCanBusDevice
    }
    

    Error message: Exception in thread 12 at 0x755f13b8, code 0x0c00000fd: stack_overflow, flags=0x0 (first chance).

    What could be the reason or how can I find the error?

    Thank you very much! :-)

    aha_1980A 1 Reply Last reply
    0
    • R robro

      Hello,

      I have a bug causing a stack overflow, but I have absolutely no clue what the problem could be.

      Basically I am sending messages to a CAN interface and if I do it quickly I get a stack overflow.
      If I wait some milliseconds before calling the function again the program runs fine.

      This is the code where the debugger stops:

      bool transmitMessage(int NodeNumber, const int &var1, const int &var2)
      {
           quint32 Id = getID(NodeNumber);
      
           QByteArray ba;
           ba.resize(8);
           ba[0] = (qint8) var1;
           ba[1] = (qint8) (var1>> 8);
           ba[2] = (qint8) (var1>> 16);
           ba[3] = (qint8) (var1>> 24);
           ba[4] = var2;
           ba[5] = (qint8) (var2>> 8);
           ba[6] = (qint8) (var2>> 16);
           ba[7] = (qint8) (var2>> 24);
      
           bool success = writeCanMessage(cobId,ba);
           QTimer timer;
           timer.setSingleShot(true);
           QEventLoop loop;
           connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
           timer.start(100); 
           loop.exec();
      
           return success; //<- here the debugger stops!
      }
      
      bool writeCanMessage(quint32 identifier, QByteArray payload)
      {
          QCanBusFrame frame;
          frame.setFrameId(identifier);
          frame.setPayload(payload);
          return (ptrCanBus->writeFrame(frame)); //pointer to QCanBusDevice
      }
      

      Error message: Exception in thread 12 at 0x755f13b8, code 0x0c00000fd: stack_overflow, flags=0x0 (first chance).

      What could be the reason or how can I find the error?

      Thank you very much! :-)

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @robro said in Stack Overflow, why?:

      timer.setSingleShot(true);
      QEventLoop loop;
      connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
      timer.start(100);

      Why do you create a local event loop? You are asking for trouble here.

      Btw, which CAN plugin do you use? And which Qt version, on which platform and which compiler?

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • R Offline
        R Offline
        robro
        wrote on last edited by robro
        #3

        Thanks for the answer.
        Basically I thought the event loop is a good way to make a break.
        If I send the Can messages without a delay they are to quick for the receiving Can-Bus participant.

        I use the PeakCan plugin provided by / with Qt 5.9.1 with MSVC2017 x64 on Win 10.

        Edit:
        The 100 ms are unnecessary long.
        Still I have no clue why there is a stack overflow as I only call the function again after the previous has returned.

        aha_1980A 1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          When dealing with stack overflow it's usually useful to look at at the stack trace, it will be very long but you should notice a repeating pattern that can signal where the problem is

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          5
          • R robro

            Thanks for the answer.
            Basically I thought the event loop is a good way to make a break.
            If I send the Can messages without a delay they are to quick for the receiving Can-Bus participant.

            I use the PeakCan plugin provided by / with Qt 5.9.1 with MSVC2017 x64 on Win 10.

            Edit:
            The 100 ms are unnecessary long.
            Still I have no clue why there is a stack overflow as I only call the function again after the previous has returned.

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @robro

            I guess the problem is, that the Peak plugin in background also relies on the event loop, so maybe things sum up very quickly. Would be indeed interesting to see the stacktrace @VRonin mentioned.

            But for solving this: if delaying the transmit is your goal, why not simply send the messages from a timer slot?

            Qt has to stay free or it will die.

            1 Reply Last reply
            4
            • R Offline
              R Offline
              robro
              wrote on last edited by robro
              #6

              Thank you very much!

              I have not found out the reason for the overflow.

              If someone is interested in analyzing the problem you find attached a stack log and a backtrace which might be helpful.
              File1 File2

              As a solution I will use the suggested timer slot :-)

              S 1 Reply Last reply
              0
              • R robro

                Thank you very much!

                I have not found out the reason for the overflow.

                If someone is interested in analyzing the problem you find attached a stack log and a backtrace which might be helpful.
                File1 File2

                As a solution I will use the suggested timer slot :-)

                S Offline
                S Offline
                seyed
                wrote on last edited by
                #7

                @robro , your files removed. What was the problem? can you share your experience?

                1 Reply Last reply
                0

                • Login

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