Merge pull request #25510 from Kumataro:fix25497

highgui: wayland: support imshow() without pre-calling namedWindow()
This commit is contained in:
Alexander Smorkalov 2024-05-02 14:41:14 +03:00 committed by GitHub
commit ce642e994d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2460,11 +2460,17 @@ CV_IMPL void cvSetMouseCallback(const char *window_name, CvMouseCallback on_mous
}
CV_IMPL void cvShowImage(const char *name, const CvArr *arr) {
auto cv_core = CvWlCore::getInstance();
auto window = cv_core.get_window(name);
// see https://github.com/opencv/opencv/issues/25497
/*
* To reuse the result of getInstance() repeatedly looks like better efficient implementation.
* However, it defined as static shared_ptr member variable in CvWlCore.
* If it reaches out of scope, cv_wl_core::~cv_wl_core() is called and all windows will be destroyed.
* For workaround, avoid it.
*/
auto window = CvWlCore::getInstance().get_window(name);
if (!window) {
cv_core.create_window(name, cv::WINDOW_AUTOSIZE);
if (!(window = cv_core.get_window(name)))
CvWlCore::getInstance().create_window(name, cv::WINDOW_AUTOSIZE);
if (!(window = CvWlCore::getInstance().get_window(name)))
CV_Error_(StsNoMem, ("Failed to create window: %s", name));
}