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. Issue with threading and opencv
Forum Updated to NodeBB v4.3 + New Features

Issue with threading and opencv

Scheduled Pinned Locked Moved Solved General and Desktop
41 Posts 3 Posters 9.2k Views 1 Watching
  • 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.
  • K Kira
    13 Jun 2019, 12:02

    @jsulm : I thought this is the stack trace after crash

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 13 Jun 2019, 12:03 last edited by
    #21

    @Kira said in Issue with threading and opencv:

    this is the stack trace after crash

    no, it isn't

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    K 1 Reply Last reply 13 Jun 2019, 12:06
    0
    • J jsulm
      13 Jun 2019, 12:03

      @Kira said in Issue with threading and opencv:

      this is the stack trace after crash

      no, it isn't

      K Offline
      K Offline
      Kira
      wrote on 13 Jun 2019, 12:06 last edited by
      #22

      @jsulm : This is the only thing which i see after crash with exception triggered.
      Is there any other way to do so

      J 1 Reply Last reply 13 Jun 2019, 12:11
      0
      • K Kira
        13 Jun 2019, 12:06

        @jsulm : This is the only thing which i see after crash with exception triggered.
        Is there any other way to do so

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 13 Jun 2019, 12:11 last edited by
        #23

        @Kira In QtCreator if you start with debugger you will have a stack trace

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply 13 Jun 2019, 12:19
        0
        • J jsulm
          13 Jun 2019, 12:11

          @Kira In QtCreator if you start with debugger you will have a stack trace

          K Offline
          K Offline
          Kira
          wrote on 13 Jun 2019, 12:19 last edited by
          #24

          @jsulm : Are you referring to this:
          0_1560428382736_ecc1a67e-9ef8-4aad-ab64-76c3ed8f112e-image.png
          Please let me know in case of any issues

          J 1 Reply Last reply 13 Jun 2019, 12:39
          0
          • K Kira
            13 Jun 2019, 12:19

            @jsulm : Are you referring to this:
            0_1560428382736_ecc1a67e-9ef8-4aad-ab64-76c3ed8f112e-image.png
            Please let me know in case of any issues

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 13 Jun 2019, 12:39 last edited by
            #25

            @Kira Yes. Now you need to go from top to bottom until you hit first source code file from your project and check it at the line mentioned in the stack trace.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply 14 Jun 2019, 10:03
            1
            • J jsulm
              13 Jun 2019, 12:39

              @Kira Yes. Now you need to go from top to bottom until you hit first source code file from your project and check it at the line mentioned in the stack trace.

              K Offline
              K Offline
              Kira
              wrote on 14 Jun 2019, 10:03 last edited by
              #26

              @jsulm : I tried doing it but the error is expected to come after thread running >150 times which is making the debugging process very difficult.
              I have also sample test case on github can you please go through it for any possible issues.
              https://github.com/HackersSpirit/ImageProcessor

              J J 2 Replies Last reply 14 Jun 2019, 10:04
              0
              • K Kira
                14 Jun 2019, 10:03

                @jsulm : I tried doing it but the error is expected to come after thread running >150 times which is making the debugging process very difficult.
                I have also sample test case on github can you please go through it for any possible issues.
                https://github.com/HackersSpirit/ImageProcessor

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 14 Jun 2019, 10:04 last edited by
                #27

                @Kira said in Issue with threading and opencv:

                150 times

                you can tell a breakpoint to be ignored for a certain amount of time

                0_1560506679424_0eaace31-88f0-4376-8417-f745494c6433-image.png


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • K Kira
                  14 Jun 2019, 10:03

                  @jsulm : I tried doing it but the error is expected to come after thread running >150 times which is making the debugging process very difficult.
                  I have also sample test case on github can you please go through it for any possible issues.
                  https://github.com/HackersSpirit/ImageProcessor

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 14 Jun 2019, 10:07 last edited by
                  #28

                  @Kira I actually suggested to go through the stack trace after crash from top to bottom. No break points needed for that.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  K 1 Reply Last reply 14 Jun 2019, 10:14
                  2
                  • J jsulm
                    14 Jun 2019, 10:07

                    @Kira I actually suggested to go through the stack trace after crash from top to bottom. No break points needed for that.

                    K Offline
                    K Offline
                    Kira
                    wrote on 14 Jun 2019, 10:14 last edited by Kira
                    #29

                    @jsulm :
                    @Kira said in Issue with threading and opencv:

                    @jsulm : Are you referring to this:
                    0_1560428382736_ecc1a67e-9ef8-4aad-ab64-76c3ed8f112e-image.png
                    Please let me know in case of any issues

                    This is the stack trace which i get posted earlier referring from line no 1. It does not point to line of code where program has a break.
                    But line 16 and 17 point to the line of the code.
                    Should i refer those line for particular cause of the program to break
                    Please do let me know if i getting something wrong

                    J 1 Reply Last reply 14 Jun 2019, 10:18
                    0
                    • K Kira
                      14 Jun 2019, 10:14

                      @jsulm :
                      @Kira said in Issue with threading and opencv:

                      @jsulm : Are you referring to this:
                      0_1560428382736_ecc1a67e-9ef8-4aad-ab64-76c3ed8f112e-image.png
                      Please let me know in case of any issues

                      This is the stack trace which i get posted earlier referring from line no 1. It does not point to line of code where program has a break.
                      But line 16 and 17 point to the line of the code.
                      Should i refer those line for particular cause of the program to break
                      Please do let me know if i getting something wrong

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 14 Jun 2019, 10:18 last edited by
                      #30

                      @Kira Check your code in that source code at line 16 and 17.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      K 1 Reply Last reply 14 Jun 2019, 10:34
                      1
                      • J jsulm
                        14 Jun 2019, 10:18

                        @Kira Check your code in that source code at line 16 and 17.

                        K Offline
                        K Offline
                        Kira
                        wrote on 14 Jun 2019, 10:34 last edited by
                        #31

                        @jsulm :
                        Line 16 is pointing to following line in bold:
                        void ImageMapping::requestReWorkNew()
                        {
                        cout<<"Inside requestRework Newwwwwwwwww"<<endl;
                        const int sleep = 50;
                        int queueSize = queueImageName.size();
                        cout<<"Queue size Request Rework New: "<<queueSize<<endl;
                        if(queueImageName.size()!=0){
                        //Get the current image number from the list of images
                        mutex.lock();
                        _working = true;
                        _abort = false;
                        mutex.unlock();
                        cout<<"Emiting resume work"<<endl;
                        emit resumeWork();
                        }else{
                        cout<<"Signalling retrying"<<endl;

                            emit retrying();
                        }
                        

                        }

                        This function is basically a slot triggered by following signal:
                        connect(imageMapping, SIGNAL(finished()), imageMapping, SLOT(requestReWorkNew()));
                        connect(imageMapping, SIGNAL(retrying()),imageMapping,SLOT(requestReWorkNew()));

                        J J 2 Replies Last reply 14 Jun 2019, 10:37
                        0
                        • K Kira
                          14 Jun 2019, 10:34

                          @jsulm :
                          Line 16 is pointing to following line in bold:
                          void ImageMapping::requestReWorkNew()
                          {
                          cout<<"Inside requestRework Newwwwwwwwww"<<endl;
                          const int sleep = 50;
                          int queueSize = queueImageName.size();
                          cout<<"Queue size Request Rework New: "<<queueSize<<endl;
                          if(queueImageName.size()!=0){
                          //Get the current image number from the list of images
                          mutex.lock();
                          _working = true;
                          _abort = false;
                          mutex.unlock();
                          cout<<"Emiting resume work"<<endl;
                          emit resumeWork();
                          }else{
                          cout<<"Signalling retrying"<<endl;

                              emit retrying();
                          }
                          

                          }

                          This function is basically a slot triggered by following signal:
                          connect(imageMapping, SIGNAL(finished()), imageMapping, SLOT(requestReWorkNew()));
                          connect(imageMapping, SIGNAL(retrying()),imageMapping,SLOT(requestReWorkNew()));

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 14 Jun 2019, 10:37 last edited by
                          #32

                          @Kira Are you sure this is the line? The actual line is mentioned in the "Line" column in the stack trace. So, it would be 2129.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          K 1 Reply Last reply 14 Jun 2019, 10:49
                          0
                          • K Kira
                            14 Jun 2019, 10:34

                            @jsulm :
                            Line 16 is pointing to following line in bold:
                            void ImageMapping::requestReWorkNew()
                            {
                            cout<<"Inside requestRework Newwwwwwwwww"<<endl;
                            const int sleep = 50;
                            int queueSize = queueImageName.size();
                            cout<<"Queue size Request Rework New: "<<queueSize<<endl;
                            if(queueImageName.size()!=0){
                            //Get the current image number from the list of images
                            mutex.lock();
                            _working = true;
                            _abort = false;
                            mutex.unlock();
                            cout<<"Emiting resume work"<<endl;
                            emit resumeWork();
                            }else{
                            cout<<"Signalling retrying"<<endl;

                                emit retrying();
                            }
                            

                            }

                            This function is basically a slot triggered by following signal:
                            connect(imageMapping, SIGNAL(finished()), imageMapping, SLOT(requestReWorkNew()));
                            connect(imageMapping, SIGNAL(retrying()),imageMapping,SLOT(requestReWorkNew()));

                            J Offline
                            J Offline
                            J.Hilk
                            Moderators
                            wrote on 14 Jun 2019, 10:45 last edited by
                            #33

                            @Kira you can double click on the line (in QtCreator) of the stack trace and it will open the file at the correct line


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            1 Reply Last reply
                            0
                            • J jsulm
                              14 Jun 2019, 10:37

                              @Kira Are you sure this is the line? The actual line is mentioned in the "Line" column in the stack trace. So, it would be 2129.

                              K Offline
                              K Offline
                              Kira
                              wrote on 14 Jun 2019, 10:49 last edited by Kira
                              #34

                              @jsulm : Actually i have recreated the issue.the program i am referring now is from github. I have cross checked the line which I highlighted is the same. If u want i can repost the image

                              K 1 Reply Last reply 14 Jun 2019, 11:40
                              0
                              • K Kira
                                14 Jun 2019, 10:49

                                @jsulm : Actually i have recreated the issue.the program i am referring now is from github. I have cross checked the line which I highlighted is the same. If u want i can repost the image

                                K Offline
                                K Offline
                                Kira
                                wrote on 14 Jun 2019, 11:40 last edited by
                                #35

                                @J-Hilk @jsulm : guys have you gone through the code at github do you see any issue with the threading logic? :)

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  Kira
                                  wrote on 17 Jun 2019, 06:09 last edited by
                                  #36

                                  @J-Hilk @jsulm : Hello guys sorry for the late update i was working on the issue.
                                  Would like to share the update.
                                  I trimmed down the issue further by first commenting out all the cout statements as the logs which
                                  was coming pointed to the ostream file of the cout.
                                  So the call stack pointed out to the opencv file stating unable to save the image.
                                  So i commented the save function to find any thing else was causing the issue. What i found that my program was still breaking and the call stack pointed to the thread function.
                                  I placed a counter for the signal and slot of the thread and it was found that it executed 666 times approx before breaking.

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    Kira
                                    wrote on 17 Jun 2019, 08:03 last edited by
                                    #37

                                    @J-Hilk
                                    @jsulm :Guys thanks for your support i finally figured where exactly the problem was:
                                    There was issue with the logic which was used for implementation. As you can see the code on github.
                                    Instead of requesting the task in the dowork function every time a signal is raised and an slot is called to execute the task.
                                    This led to the calling of so many signals and slots within a given time that it caused the stack to overflow.
                                    The issue will be resolved by removing the signal slot loop. This issue was top priority, a big learning curve for my future implementations in dealing with signal and slot mechanism.

                                    Thanks for your support.
                                    Just one last question which i would like to be answered which triggered with this implementation.

                                    1. Is there any limitation of how much slots can reside at a given time on a stack?
                                      As per my observation at a given time 666 approx signal/slots calls were made after which the program crashed.
                                    2. Is the slot entry is cleared or maintained on the stack after the execution and can be increase the size of stack or transfer it to heap?

                                    Regards

                                    J 1 Reply Last reply 17 Jun 2019, 08:07
                                    0
                                    • K Kira
                                      17 Jun 2019, 08:03

                                      @J-Hilk
                                      @jsulm :Guys thanks for your support i finally figured where exactly the problem was:
                                      There was issue with the logic which was used for implementation. As you can see the code on github.
                                      Instead of requesting the task in the dowork function every time a signal is raised and an slot is called to execute the task.
                                      This led to the calling of so many signals and slots within a given time that it caused the stack to overflow.
                                      The issue will be resolved by removing the signal slot loop. This issue was top priority, a big learning curve for my future implementations in dealing with signal and slot mechanism.

                                      Thanks for your support.
                                      Just one last question which i would like to be answered which triggered with this implementation.

                                      1. Is there any limitation of how much slots can reside at a given time on a stack?
                                        As per my observation at a given time 666 approx signal/slots calls were made after which the program crashed.
                                      2. Is the slot entry is cleared or maintained on the stack after the execution and can be increase the size of stack or transfer it to heap?

                                      Regards

                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 17 Jun 2019, 08:07 last edited by
                                      #38

                                      @Kira 1. Sure but I guess it depends on many factors. You should not rely on it and avoid flooding the signal queue
                                      2. Not sure I understand the question. Which slot entry do you mean? Slots are not put into the signal queue. And the stack is automatically cleared when a function/method (which a slot is) finishes, nothing Qt specific.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      K 1 Reply Last reply 17 Jun 2019, 08:13
                                      0
                                      • J jsulm
                                        17 Jun 2019, 08:07

                                        @Kira 1. Sure but I guess it depends on many factors. You should not rely on it and avoid flooding the signal queue
                                        2. Not sure I understand the question. Which slot entry do you mean? Slots are not put into the signal queue. And the stack is automatically cleared when a function/method (which a slot is) finishes, nothing Qt specific.

                                        K Offline
                                        K Offline
                                        Kira
                                        wrote on 17 Jun 2019, 08:13 last edited by
                                        #39

                                        @jsulm

                                        @jsulm said in Issue with threading and opencv:

                                        @Kira 1. Sure but I guess it depends on many factors. You should not rely on it and avoid flooding the signal queue
                                        2. Not sure I understand the question. Which slot entry do you mean? Slots are not put into the signal queue. And the stack is automatically cleared when a function/method (which a slot is) finishes, nothing Qt specific.

                                        1. Sorry if not understood i will just try to clear :). Actually i my assumption due to the implementation logic there were so many signals generated that caused the stacks to overflow giving error at different points.
                                          For example sometime i got error at saveImage function. while sometimes at calling the slot etc.
                                          I still need to clarify my assumptions using different test cases but probably this should be the cause why the program crashed.
                                        J 1 Reply Last reply 17 Jun 2019, 08:32
                                        0
                                        • K Kira
                                          17 Jun 2019, 08:13

                                          @jsulm

                                          @jsulm said in Issue with threading and opencv:

                                          @Kira 1. Sure but I guess it depends on many factors. You should not rely on it and avoid flooding the signal queue
                                          2. Not sure I understand the question. Which slot entry do you mean? Slots are not put into the signal queue. And the stack is automatically cleared when a function/method (which a slot is) finishes, nothing Qt specific.

                                          1. Sorry if not understood i will just try to clear :). Actually i my assumption due to the implementation logic there were so many signals generated that caused the stacks to overflow giving error at different points.
                                            For example sometime i got error at saveImage function. while sometimes at calling the slot etc.
                                            I still need to clarify my assumptions using different test cases but probably this should be the cause why the program crashed.
                                          J Offline
                                          J Offline
                                          J.Hilk
                                          Moderators
                                          wrote on 17 Jun 2019, 08:32 last edited by
                                          #40

                                          @Kira said in Issue with threading and opencv:

                                          1. Sorry if not understood i will just try to clear :). Actually i my assumption due to the implementation logic there were so many signals generated that caused the stacks to overflow giving error at different points.
                                            For example sometime i got error at saveImage function. while sometimes at calling the slot etc.
                                            I still need to clarify my assumptions using different test cases but probably this should be the cause why the program crashed.

                                          Hi, great that you managed to work it out thumbsUp

                                          Sadly I'm quite a but under time pressure and was unable to take a closer look on your uploaded project :(

                                          To your question.
                                          The (default)stack limit is highly OS depended but In most cases, the max stack size of the main thread is significantly large, that you won't run into issues, even in highly recursive functions.
                                          IIRC, than on an ordinary desktop PCs, the call stack for Windows defaults to 1mb, 8mb for Linux, and 8-64mb for OSX

                                          For 2ndary threads, that can be quite different for macOS, that's reduced to 512 kbyte


                                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                          Q: What's that?
                                          A: It's blue light.
                                          Q: What does it do?
                                          A: It turns blue.

                                          1 Reply Last reply
                                          1

                                          30/41

                                          14 Jun 2019, 10:18

                                          • Login

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