<div dir="ltr"><div dir="ltr"><div>Thank you Nirbheek and Nicolas,</div><div><br></div><div>The unloading of our DLL (according to comments found in the code provided by MATLAB) is done when the user calls the command 'imaqreset' in the MATLAB Command Window. As such, the user can use that command anytime, for a number of reasons (for instance, after registering another IMAQ adaptor).</div><div><br></div><div>The good news is that somehow GStreamer remains initialized, so during the next loading/initialization of our DDL the call to gst_is_initialized() returns true and as a result we don't call gst_init_check() again.</div><div dir="ltr"><br></div><div>Originally, I thought the issue came after the MATLAB command 'imaqreset' (thus after the unloading our DLL), but it turns out that even if I don't do the 'imaqreset' command, I still get the issue after around 15 seconds.</div><div><br></div><div>Thankfully, I have identified the source of that issue. In our DLL, we added a custom log function for GStreamer as indicated previously (ref. gst_debug_add_log_function(VisionAdaptor::printGstLog, NULL, NULL);). The issue seems to occur when that function is called.</div><div><br></div><div>Here's the scenario observed:</div><div>- 'imaqreset'</div><div>- Try to stream a video feed but use the wrong IP address for the rtpsrc</div><div>- We first detect a timeout in the pipeline state change</div><div>- Then, after around 15 seconds, our custom log function gets called and display the error messages</div><div>- 'imaqreset'</div><div>- <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Try again to stream a video feed but use the wrong IP address for the rtpsrc</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">- We detect a timeout in the pipeline state change</span><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">- Then, after around 15 seconds, MATLAB crashes with an access violation (<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><unknown-module>+00000000, as indicated previously</span>)</span><br></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">However, if I don't use a custom log function, I don't get any access violation anymore.</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Note that I have observed a similar behavior with our Linux library, which uses GStreamer v1.8.3 on Ubuntu.</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">So for now, our fix is to not use a custom log function.</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">As a final comment, I am very (very) pleased with the MSVC-built libraries. Thanks to that, our DLL now works perfectly within MATLAB.</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Thank you again for all your help.</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">MarcG</span></span></span></div><div><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---------- Forwarded message ----------<br>From: Nicolas Dufresne <<a href="mailto:nicolas@ndufresne.ca" target="_blank">nicolas@ndufresne.ca</a>><br>To: Discussion of the development of and with GStreamer <<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a>><br>Cc: <br>Bcc: <br>Date: Wed, 13 Mar 2019 12:02:50 -0400<br>Subject: Re: Random access violation (seg. fault) when calling GStreamer functions from MATLAB context in Windows<br>Le mercredi 13 mars 2019 à 12:22 +0530, Nirbheek Chauhan a écrit :<br>
> On Wed, Mar 13, 2019 at 2:56 AM Marc Gelinas <<a href="mailto:mgelinas@kinova.ca" target="_blank">mgelinas@kinova.ca</a>> wrote:<br>
> > After confirming that I was able to stream my video feed with gst-launch (using the same pipeline), the issue was "fixed" when I tried again to stream from my DLL. The issue never came back.<br>
> > <br>
> <br>
> This was probably because of the gst registry being out of date, you<br>
> must've done something that triggered an update.<br>
> <br>
> > Unfortunately, I still have the following issue:<br>
> > <br>
> > ISSUE: A few seconds after MATLAB unloads my DLL, sometimes it crashes with the following backtrace:<br>
> > Stack Trace (from fault):<br>
> > [  0] 0x00000000d32924c0                                   <unknown-module>+00000000<br>
> > [  1] 0x000007fec1104bf3    C:\gstreamer\1.0\x86_64\bin\gstreamer-1.0-0.dll+00347123 gst_value_init_and_copy+00333927<br>
> > [  2] 0x000007fec110418d    C:\gstreamer\1.0\x86_64\bin\gstreamer-1.0-0.dll+00344461 gst_value_init_and_copy+00331265<br>
> > [  3] 0x000007fec1637a88      C:\gstreamer\1.0\x86_64\bin\gstrtsp-1.0-0.dll+00031368 gst_rtsp_message_steal_body+00026102<br>
> > [  4] 0x000007fec1eb3032 C:\gstreamer\1.0\x86_64\lib\gstreamer-1.0\gstrtsp.dll+00012338 gst_plugin_rtsp_register+00007882<br>
> > [  5] 0x000007fec1ec4db8 C:\gstreamer\1.0\x86_64\lib\gstreamer-1.0\gstrtsp.dll+00085432 gst_plugin_rtsp_register+00080976<br>
> > [  6] 0x000007fec1ebe50c C:\gstreamer\1.0\x86_64\lib\gstreamer-1.0\gstrtsp.dll+00058636 gst_plugin_rtsp_register+00054180<br>
> > [  7] 0x000007fec1eb8c82 C:\gstreamer\1.0\x86_64\lib\gstreamer-1.0\gstrtsp.dll+00035970 gst_plugin_rtsp_register+00031514<br>
> > [  8] 0x000007fec1ec0af1 C:\gstreamer\1.0\x86_64\lib\gstreamer-1.0\gstrtsp.dll+00068337 gst_plugin_rtsp_register+00063881<br>
> > [  9] 0x000007fec1ecccaf C:\gstreamer\1.0\x86_64\lib\gstreamer-1.0\gstrtsp.dll+00117935 gst_plugin_rtsp_register+00113479<br>
> > [ 10] 0x000007fec115320c    C:\gstreamer\1.0\x86_64\bin\gstreamer-1.0-0.dll+00668172 gst_value_init_and_copy+00654976<br>
> > [ 11] 0x000007feb3d8b0f4         C:\gstreamer\1.0\x86_64\bin\glib-2.0-0.dll+00438516 g_date_get_monday_week_of_year+00425260<br>
> > [ 12] 0x000007feb3d8a3f6         C:\gstreamer\1.0\x86_64\bin\glib-2.0-0.dll+00435190 g_date_get_monday_week_of_year+00421934<br>
> > [ 13] 0x000007feb3db32f7         C:\gstreamer\1.0\x86_64\bin\glib-2.0-0.dll+00602871 g_date_get_monday_week_of_year+00589615<br>
> > [ 14] 0x000007fec9b80369 C:\Program Files\MATLAB\R2018b\bin\win64\ucrtbase.DLL+00131945 o__strtoui64+00000089<br>
> > [ 15] 0x00000000773f59cd                   C:\windows\system32\kernel32.dll+00088525 BaseThreadInitThunk+00000013<br>
> > [ 16] 0x000000007755383d                      C:\windows\SYSTEM32\ntdll.dll+00342077 RtlUserThreadStart+00000029<br>
> > <br>
> > The crash seems to occur only if previously I had a failed attempt to stream a video feed. For instance, I specify a wrong IP address for the rtspsrc. Then, when I make MATLAB unload my DLL, the crash occurs after a few seconds. Do you have any idea what could be the root cause?<br>
> <br>
> I don't think it's safe to unload gstreamer DLLs; at least I don't<br>
> know of anyone who uses that. It may be possible to make that safe,<br>
> though. We'd be happy to accept reasonable patches for it.<br>
<br>
Unfortunatly, it is not. That's the reason why you cannot do gst_init()<br>
after gst_deinit(). In general, when GStreamer (or any GLib based)<br>
project is loaded in a plugin, we simply open our self module and lead<br>
it.<br>
<br>
  g_module_open (NULL, 0);<br>
<br>
> <br>
> > Also, do you know if the release of stable version 1.16 is still planned for this month?<br>
> > <br>
> <br>
> AFAIK, yes, unless there's some major release-blocking bug. The MSVC<br>
> builds are still 'beta', so issues in that will not block/delay the<br>
> release unless they're easy to fix.<br>
> <br>
> Cheers,<br>
> Nirbheek<br>
> _______________________________________________<br>
> gstreamer-devel mailing list<br>
> <a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br></blockquote></div></div></div>