backscrub icon indicating copy to clipboard operation
backscrub copied to clipboard

Crash

Open jjsarton opened this issue 3 years ago • 4 comments

If we call backscrub with the debug mode set to 2 and the size of the camera stream or the size of the output stream is to small, eg. 160x90 which is a resolution supported by my webcam, this will happen. The problem is that the size of the mask has always a width of 166px x 166px (default model). 166pc is greater as 90px and we get an error.

jjsarton avatar Sep 07 '22 13:09 jjsarton

I have found why backscrub don't terminate with a crash while debug level > 1. The imshow window is opened before the main loop code, while we process the first pass, some openvc functions are called and not handled correctly on program exit. A simple way is to delay the end of backscrub.

If the 'q' key is pressed, we remember this quit = true; we don't set running to false, but set pbk to nullprt. At the end of the for loop we check if quit is set and if we entered at least 3 time the loop (a variable count which is increased if quit is true and count is less than 3.

With these simple modifications, I don't have any more crashes at termination.

jjsarton avatar Sep 13 '22 09:09 jjsarton

This sounds like a classic race condition. And this being said I absolutely don't like the approach of the fix you suggested. ;-) Instead proper synchronization should be used instead.

BenBE avatar Sep 14 '22 21:09 BenBE

@BenBe, I agree this is not the best approach. The backscrub own thread sync work as far I was able to check this, as expected. The problem seem to be related to cv::imshow() Apparently thread are spanned by cv::imshow(), there are not protected enough.

We perform the following:

while(running) {
   process_data()
   send_data_to_imshow() // here we call cv:Mat functions inside of imshow() and we will possibly crash
  running = false
  return 0
}

We don't have the possibility to check if displaying within imshow() was finished.

jjsarton avatar Sep 15 '22 11:09 jjsarton

I have found a simple solution which seem to work well. We need to include #include and if q is pressed to call std::raise(SIGTERM); With this, the opencv signal handler will terminate without some crash.

jjsarton avatar Sep 15 '22 14:09 jjsarton