Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using andriod app (IP webcam) as ip camera. i'm running below code in separate thread. because if i run in main thread it crashes the program.

C++
VideoCapture cap; Mat img;
    cap.open("http://192.168.0.101:8080/video?x.mjpeg");
    while(waitKey(33)!=27)
    {
        try{
            cap>>img;
            cout<<"Thread active"<<endl;
            if(img.empty())
            {
             cout<<"camera Closed"<<endl;
             break;
            }
             imshow("Video",img);
          } catch(...{}    
    }


everything works fine. even if i turn off camera(close andriod app) it prints "Camera closed" in Console. The problem occurs when i turn off wifi on my andriod device. the moment i turn off wifi directly(having app still running) thread freezes, even though its in try catch block!

i have a button_click event in my form and i'm callingcap.release(); in it. if i click this button then, follow error is displayed in visual studio (no error from opencv)

Java
HEAP[Test.exe]: HEAP: Free Heap block 6797780 modified at 67977d4 after it was freed Windows has triggered a breakpoint in Test.exe.

   This may be due to a corruption of the heap, which indicates a bug in Test.exe or any of the DLLs it has loaded.

   This may also be due to the user pressing F12 while Test.exe has focus.

   The output window may have more diagnostic information.


Have anybody come across this error?
Visual Studio debugger stops at cap.release(); line

Is there a way to overcome this issue?

Thanks & Regards

P.S: I'm using Visual Studio 2013 with opencv 3.0 [C++/Cli (winforms)]

What I have tried:

Crash occurs with cap.~VideoCapture(); in button_clickEvent. But no crash on img.release();
Posted
Updated 4-Jul-16 6:34am
Comments
KarstenK 22-Jun-16 8:30am    
Sounds like the problem is in the WiFi data fetch and it kills the app. I would try a watchdog thread which checks the life your camera thread and restarts it when needed.
Prakash1206 24-Jun-16 11:39am    
Hi KarstenK
Thanks for your valuable answer, it sounds like a solution to this problem.
didn't knew about watchdog thread, but i can make out when thread it dead.. i used an integer and kept incrementing it until thread was dead (i turned off wifi)
now the problem is, if i use thread->Abort(); [an attempt to restart thread] it crashes! [error message is same as shown in question]

do u know any other method to overcome this headache?

Thanks

1 solution

If you read and understand the error message it told you the truth: you worked on barbaged memory.

Such textes are the golden trail for finding the problems. Learn to Google after such error textes!!!

You cant "restart" a thread, because it is a "Zombie". Free the objects and reate new instances of all objects!!! (re-write the code if necessary)

Please read and try to understand C dynamic memory allocation. It sounds silly, but it is how it works. Follow some of the links and bookmark it. In some months you may understand it. ;-)
 
Share this answer
 
Comments
Prakash1206 6-Jul-16 23:16pm    
@KarstenK, sorry for delay in replying.

Thanks for your valuable answer.
when i try to free objects in that thread, it again crashes.
for ex: cap.release(); this causes crash. so any safe way to release objects?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900