Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash #156

Open
jjsarton opened this issue Sep 7, 2022 · 4 comments
Open

Crash #156

jjsarton opened this issue Sep 7, 2022 · 4 comments

Comments

@jjsarton
Copy link

jjsarton commented Sep 7, 2022

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
Copy link
Author

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.

@BenBE
Copy link
Collaborator

BenBE commented Sep 14, 2022

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.

@jjsarton
Copy link
Author

@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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants