From 9537a909f7fbcca5e9596846e29cae5e7eb1c86a Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Fri, 8 Oct 2021 04:07:04 +0200 Subject: [PATCH] Merge pull request #20801 from JonasVautherin:fix-gst-error-handling * Fix gst error handling * Use the return value instead of the error, which gives no guarantee of being NULL in case of error * Test err pointer before accessing it * Remove unreachable code * videoio(gstreamer): restore check in writer code Co-authored-by: Alexander Alekhin --- modules/videoio/src/cap_gstreamer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/videoio/src/cap_gstreamer.cpp b/modules/videoio/src/cap_gstreamer.cpp index d839069..dd6387d 100644 --- a/modules/videoio/src/cap_gstreamer.cpp +++ b/modules/videoio/src/cap_gstreamer.cpp @@ -761,7 +761,7 @@ bool GStreamerCapture::open(const String &filename_) } else { - CV_WARN("Error opening file: " << filename << " (" << err->message << ")"); + CV_WARN("Error opening file: " << filename << " (" << (err ? err->message : "") << ")"); return false; } } @@ -769,9 +769,9 @@ bool GStreamerCapture::open(const String &filename_) { GSafePtr err; uridecodebin.attach(gst_parse_launch(filename, err.getRef())); - if (err) + if (!uridecodebin) { - CV_WARN("Error opening bin: " << err->message); + CV_WARN("Error opening bin: " << (err ? err->message : "")); return false; } manualpipeline = true; @@ -1979,7 +1979,7 @@ void handleMessage(GstElement * pipeline) gst_message_parse_error(msg, err.getRef(), debug.getRef()); GSafePtr name; name.attach(gst_element_get_name(GST_MESSAGE_SRC (msg))); CV_WARN("Embedded video playback halted; module " << name.get() << - " reported: " << err->message); + " reported: " << (err ? err->message : "")); CV_LOG_DEBUG(NULL, "GStreamer debug: " << debug.get()); gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL); -- 2.7.4