exeldro / obs-source-record

GNU General Public License v2.0
338 stars 37 forks source link

Crashes on OBS Studio shutdown or scene collection change in case Source Record is applied twice on same scene/source #15

Open rse opened 3 years ago

rse commented 3 years ago

I'm experiencing crashes of OBS Studio on shutdown and when a scene collection is changed. Unfortunately, it is not really deterministic, but the crashes most of the time look like this:

Unhandled exception: c0000005
Date/Time: 2021-06-20, 00:49:55
Fault address: 7FFAB09F2DDF (c:\users\rse\prj\obs-studio-msg-filmstudio\dst\bin\64bit\w32-pthreads.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread 2544: (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
000000F3740FB2A0 00007FFAB09F2DDF 0000000000000000 0000020601ABED60 0000000000000008 00000206013EC4C0 w32-pthreads.dll!pthread_mutex_trylock+0x3f
000000F3740FB320 00007FFAB09F258B 0000000000000000 0000020601ABED60 0000020601ABED40 0000000000000008 w32-pthreads.dll!pthread_mutex_destroy+0x2b
000000F3740FB370 00007FFA78138D77 000000F300000000 00007FFA78150318 000000F3740FB3C8 00000206013EC4C0 obs.dll!scene_destroy+0x17
000000F3740FB3A0 00007FFA7810BBE7 0000000000000000 000000F3740FB7C0 0000020600F1CEA0 00000206013EC4C0 obs.dll!obs_source_destroy+0x1d7
000000F3740FB4A0 00007FFA7810FBE9 0000000000000000 0000020600F1CEA0 000002066B7F0A80 0000000000000000 obs.dll!obs_source_release+0x49
000000F3740FB4D0 00007FFA78115216 000000F3740F0001 0000020600F1CEA0 000002066B7F0A80 0000000000000000 obs.dll!obs_transition_clear+0xd6
000000F3740FB510 00007FFA7810BA85 000002066B7F0A80 000000F3740FB7C0 0000000000000000 000002066B7F0A80 obs.dll!obs_source_destroy+0x75
000000F3740FB610 00007FFA7810FBE9 0000020600F1CEA0 000002066B7ECA70 000002066B7ECA70 0000020600F1CEA0 obs.dll!obs_source_release+0x49
000000F3740FB640 00007FFA7812150E 0000000000000000 0000000000000000 0000000000000000 000002066B7F0A80 obs.dll!obs_set_output_source+0x14e
000000F3740FB690 00007FF71B5250E9 000002060A05E558 000002066B7F0A80 000000F3740FB7C0 000002066B7F0A80 obs64.exe!OBSBasic::ClearSceneData+0x89
000000F3740FB6C0 00007FF71B540B75 000002066B772940 000000F3740FBE90 000002066B74FAA0 000002060187F370 obs64.exe!OBSBasic::closeEvent+0x455

With lots of testing, I figured out that although Source Record is NEVER part of those stack traces, it actually IS(!) the root cause of them. And because the crashes always looks very similar but not exactly identical, it seems like a strange timing problem. As I'm not an OBS Studio developer and do not know the internals well enough, I've applied a basic device & conquer approach and found the root cause in the two lines of Source Records source_record_filter_destroy function:

audio_output_close(context->audio_output);
video_output_close(o);

If I comment out those two lines, the crashed fully stop. Once they are part of the game, about every 3-4th try, OBS Studio crashes at shutdown. Although I've no deterministic scenario at hand, I'm rather sure that these two lines are the root cause. Logically they look correct, of course. But they seem to badly interact with OBS Studio's other scene/source shutdown procedures and rather reliable cause the crashes. By comparing your other audio shutdown steps, I've now figure out that performing a audio_output_stop(context->audio_output) just before audio_output_close(context->audio_output) nearly solves the problem. OBS Studio then at least crashes far fewer times on shutdown, but still nearly every time on scene collection switch. So, it helps and it seems to be a good additional step to do, but unfortunately it still doesn't really resolve the entire problem.

This is the patch I would at least recommend to reduce the problems:

bugfix.diff.txt

And for completeness reasons I append my particular OBS Studio profile and scene collection I use for testing:

config.zip

PS: When the two mentioned lines are commented out, the crashes stop immediately. But, interesting, as your Virtual Cam Filter is also part of my setup, I then get a nearly identical problem there. There the crash dumps at least show the Virtual Cam Filter's influence (see below). So, I guess the same destroy trouble exists there, too.

Unhandled exception: c0000005
Date/Time: 2021-06-20, 01:07:55
Fault address: 7FFAB09B2DDF (c:\users\rse\prj\obs-studio-msg-filmstudio\dst\bin\64bit\w32-pthreads.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread 129B0: (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
000000081ADE9F40 00007FFAB09B2DDF 0000000000000000 0000011A664FFBC0 0000000000000008 0000000000000001 w32-pthreads.dll!pthread_mutex_trylock+0x3f
000000081ADE9FC0 00007FFAB09B258B 0000000000000000 0000011A664FFBC0 0000011A664FFBA0 0000000000000008 w32-pthreads.dll!pthread_mutex_destroy+0x2b
000000081ADEA010 00007FFA7E578D77 0000000800000000 00007FFA7E590318 000000081ADEA068 0000011A65F85580 obs.dll!scene_destroy+0x17
000000081ADEA040 00007FFA7E54BBE7 0000011A4943DFC0 000000081ADEA760 0000011A65F87540 0000000000000001 obs.dll!obs_source_destroy+0x1d7
000000081ADEA140 00007FFA7E54FBE9 0000011A65F85580 0000011A65F87540 0000000000000001 0000000000003958 obs.dll!obs_source_release+0x49
000000081ADEA170 00007FFA7E54C92F 0000011A4936D080 0000000000000001 0000011A65F87540 000000081ADEA760 obs.dll!obs_source_enum_active_tree+0x9f
000000081ADEA1B0 00007FFA7E54B88D 0000011A5D49DD00 0000011A5D49DD00 000000081ADEA760 0000011A65F85580 obs.dll!obs_source_deactivate+0x5d
000000081ADEA1E0 00007FFAAB1B12CB 0000011A65F84060 00007FFA7E591B20 0000011A666E53A0 0000011A5C9BDC80 virtual-cam-filter.dll!virtual_cam_filter_source_filter_remove+0x2b
000000081ADEA210 00007FFA7E54CF82 0000011A4943DFC0 0000000000000000 0000011A65F84060 0000011A65F87540 obs.dll!obs_source_filter_remove_refless+0x1b2
000000081ADEA310 00007FFA7E54CDB5 0000011A65F85580 0000011A65F87540 0000011A65F85580 0000000000000004 obs.dll!obs_source_filter_remove+0x45
000000081ADEA340 00007FFA7E54BB12 0000000000000000 000000081ADEA760 0000011A65F87540 0000011A65F85580 obs.dll!obs_source_destroy+0x102
000000081ADEA440 00007FFA7E54FBE9 0000000000000000 0000011A65F87540 0000011A4947C640 0000000000000004 obs.dll!obs_source_release+0x49
000000081ADEA470 00007FFA7E555216 000000081ADE0001 0000011A65F87540 0000011A4947C640 0000000000000000 obs.dll!obs_transition_clear+0xd6
000000081ADEA4B0 00007FFA7E54BA85 0000011A4947C640 000000081ADEA760 0000000000000000 0000011A4947C640 obs.dll!obs_source_destroy+0x75
000000081ADEA5B0 00007FFA7E54FBE9 0000011A65F87540 0000011A49475710 0000011A49475710 0000011A65F87540 obs.dll!obs_source_release+0x49
000000081ADEA5E0 00007FFA7E56150E 0000000000000000 0000000000000000 0000000000000000 0000011A4947C640 obs.dll!obs_set_output_source+0x14e
000000081ADEA630 00007FF71B5250E9 00000000FFFFFFFF 0000011A4947C640 0000000000000000 0000011A4947C640 obs64.exe!OBSBasic::ClearSceneData+0x89
000000081ADEA660 00007FF71B52DC58 00000000FFFFFFFF 0000011A00000000 0000011A65F74BC0 00000000FFFFFFFF obs64.exe!OBSBasic::LoadData+0x48
000000081ADEA850 00007FF71B5F0080 0000011A65F74BC0 0000011A65B7E080 0000011A4942A101 0000011A65F74BC0 obs64.exe!OBSBasic::ChangeSceneCollection+0x1d0
rse commented 3 years ago

Ok, I can confirm that with the audio_output_stop() in source_record_filter_destroy most of the crashes are gone. Unfortunately, when I open/close OBS Studio and switch between scene collections long enough I still get the following types of crashes (this time Source Record is part of the strack trace):

Unhandled exception: c0000005
Date/Time: 2021-06-20, 01:19:58
Fault address: 7FFA7E59AC8F (c:\users\rse\prj\obs-studio-msg-filmstudio\dst\bin\64bit\obs.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread 16BDC: audio-io: audio thread (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
0000000EFBC9F270 00007FFA7E59AC8F 00007FFACBAF6620 0000000EFBC9F8B0 0000000000000048 00007FFACB9D1374 obs.dll!obs_filter_get_parent+0x2f
0000000EFBC9F2A0 00007FFAAFAA267D 0002276C5AF4E954 0002276C59D4FB2C 000000000006E400 0002276A2A323954 source-record.dll!calc_min_ts+0xd
0000000EFBC9F500 00007FFA7E57E5B5 00000583A4BD0283 0000000000000015 000000000006E000 0002276C5AF4E954 obs.dll!input_and_output+0x225
0000000EFBC9F780 00007FFA7E57E169 0000000000000015 00000180530DFE40 0000000000000000 0000000000000000 obs.dll!audio_thread+0xf9
0000000EFBC9F7D0 00007FFAB0AF5924 000001804B8725C0 0000000000000000 0000000000000000 0000000000000000 w32-pthreads.dll!ptw32_threadStart+0x74
0000000EFBC9F850 00007FFAC9941BB2 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ucrtbase.dll!0x7ffac9941bb2
0000000EFBC9F880 00007FFACB4F7034 0000000000000000 0000000000000000 0000000000000000 0000000000000000 kernel32.dll!0x7ffacb4f7034
0000000EFBC9F8B0 00007FFACBA02651 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ntdll.dll!0x7ffacba02651

How to avoid these second types of crashes I've still not figured out. But at least we now already know that the following updated patch fixes most of the problems:

bugfix.diff.txt

exeldro commented 3 years ago

Where find you find the audio_output_stop function? It is an unresolved external for me. I searched on the OBS code, but could not find that function.

rse commented 3 years ago

Yes, indeed. You're right. I'm puzzled myself now what I've done yesterday:

$ grep -r audio_output_stop .
Binary file ./obs-studio/build/plugins/source-record/source-record.dir/Release/source-record.obj matches
./obs-studio/plugins/source-record/source-record.c:     audio_output_stop(context->audio_output);

So, in my whole source tree there is no audio_output_stop at all. I don't understand why it does not crash because of this and why this even resolves the crashes. I'm more than puzzled now...

rse commented 3 years ago

Ok, the audio_output_stop aspect I no longer understand myself. So I started from scratch this morning with the latest HEAD of your master branch. A simple OBS Studio shutdown immediately resulted once again in the usual crashes with the usual stack traces (where Source Record is not part of the game):

Unhandled exception: c0000005
Date/Time: 2021-06-20, 09:42:07
Fault address: 7FFAB09B2DDF (c:\users\rse\prj\obs-studio-msg-filmstudio\dst\bin\64bit\w32-pthreads.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread 130E4: (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
00000028B8CFB060 00007FFAB09B2DDF 0000000000000000 000001F993F5C180 0000000000000008 0000000000000000 w32-pthreads.dll!pthread_mutex_trylock+0x3f
00000028B8CFB0E0 00007FFAB09B258B 0000000000000000 000001F993F5C180 000001F993F5C160 0000000000000008 w32-pthreads.dll!pthread_mutex_destroy+0x2b
00000028B8CFB130 00007FFA78138D77 0000002800000000 00007FFA78150318 00000028B8CFB188 000001F999A2CFE0 obs.dll!scene_destroy+0x17
00000028B8CFB160 00007FFA7810BBE7 00007FFA67D2C928 000001F99998C4A0 0000000000000404 0000000000000000 obs.dll!obs_source_destroy+0x1d7
00000028B8CFB260 00007FFA7810FBE9 00007FFA67D2C928 00007FFA67D2C928 0000000000000404 000001F987C049A0 obs.dll!obs_source_release+0x49
00000028B8CFB290 00007FFA679C2195 000001F987C04A08 0000000000000003 000001F985A28BF0 0000000000000000 qt5core.dll!0x7ffa679c2195
00000028B8CFB2D0 00007FFA679C26BC 000001F987C049E8 00007FFA00000404 0000000000000003 000001F987C049A0 qt5core.dll!0x7ffa679c26bc
00000028B8CFB300 00007FFA679E6443 000001F987C049C0 0000000000000000 000001F9A2001C00 00007FFA73DD7811 qt5core.dll!0x7ffa679e6443
00000028B8CFB330 00007FFA679EB7BB 000001F99A141390 000001F900000000 0000000000000002 00000000FFFFFFFF qt5core.dll!0x7ffa679eb7bb
00000028B8CFB360 00007FFA68406EA1 000001F9999337C0 00000000FFFFFFFF 000001F9A2001C00 00007FFAC992F05B qt5widgets.dll!0x7ffa68406ea1
00000028B8CFB390 00007FFA6866AF6E 0000000000000001 0000000000000000 0000000000000000 00000000FFFFFFFF qt5widgets.dll!0x7ffa6866af6e
00000028B8CFB3E0 00007FF71B5215D5 0000000000000003 000001F987E688F0 000001F985A28BF0 000001F985A28BF0 obs64.exe!QListWidgetItem::`vector deleting destructor'+0x15
00000028B8CFB410 00007FFA6866BBCF 000001F9A26F87A8 00000028B8CFB570 000001F985A28BF0 000001F985A28BF0 qt5widgets.dll!0x7ffa6866bbcf
00000028B8CFB440 00007FF71B525098 000001F9A26F87A8 000001F985A28BF0 00000028B8CFB570 000001F985A28BF0 obs64.exe!OBSBasic::ClearSceneData+0x38
00000028B8CFB470 00007FF71B540B75 000001F9859EEEA0 00000028B8CFBC40 000001F9859C4FB0 000001F9A2936EE0 obs64.exe!OBSBasic::closeEvent+0x455

When I uncomment the following two lines again in source_record_filter_destroy, the crashes on shutdown stop:

$ (cd obs-studio/plugins/source-record; git diff)
diff --git a/source-record.c b/source-record.c
old mode 100644
new mode 100755
index 9bc8b14..4adc22a
--- a/source-record.c
+++ b/source-record.c
@@ -803,9 +803,9 @@ static void source_record_filter_destroy(void *data)
        obs_weak_source_release(context->audio_source);
        context->audio_source = NULL;

-       audio_output_close(context->audio_output);
+       // audio_output_close(context->audio_output);

-       video_output_close(o);
+       // video_output_close(o);

        obs_service_release(context->service);

But I still get crashes on scene collection changes every time:

Unhandled exception: c0000005
Date/Time: 2021-06-20, 09:45:01
Fault address: 7FFAB09B2DDF (c:\users\rse\prj\obs-studio-msg-filmstudio\dst\bin\64bit\w32-pthreads.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread 9D54: (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
000000DEBC16A3A0 00007FFAB09B2DDF 0000000000000000 000001FB47A84A80 0000000000000008 000001FB40F47000 w32-pthreads.dll!pthread_mutex_trylock+0x3f
000000DEBC16A420 00007FFAB09B258B 0000000000000000 000001FB47A84A80 000001FB47A84A60 0000000000000008 w32-pthreads.dll!pthread_mutex_destroy+0x2b
000000DEBC16A470 00007FFA78138D77 000000DE00000000 00007FFA78150318 000000DEBC16A4C8 000001FB40F43B20 obs.dll!scene_destroy+0x17
000000DEBC16A4A0 00007FFA7810BBE7 000001FB47A84360 0000000000000008 0000000000000002 000001FB40F47000 obs.dll!obs_source_destroy+0x1d7
000000DEBC16A5A0 00007FFA7810FBE9 000001FB47EEAAC0 0000000000000000 0000000000000008 0000000000000000 obs.dll!obs_source_release+0x49
000000DEBC16A5D0 00007FFA7813C101 0000000000000000 0000000000000002 0000000000000002 0000000000000004 obs.dll!obs_sceneitem_destroy+0xa1
000000DEBC16A600 00007FFA7813DDCA 000001FB40E0CD88 000001FB40E0CD80 0000000000000004 0000000000000008 obs.dll!remove_all_items+0x17a
000000DEBC16A660 00007FFA78138D6E 000000DE00000000 00007FFA78150318 000000DEBC16A6B8 000001FB40F47000 obs.dll!scene_destroy+0xe
000000DEBC16A690 00007FFA7810BBE7 0000000000000000 000000DEBC16AAB0 000001FB40CA2CA0 000001FB40F47000 obs.dll!obs_source_destroy+0x1d7
000000DEBC16A790 00007FFA7810FBE9 0000000000000000 000001FB40CA2CA0 000001FB2D58E850 0000000000000004 obs.dll!obs_source_release+0x49
000000DEBC16A7C0 00007FFA78115216 000000DEBC160001 000001FB40CA2CA0 000001FB2D58E850 0000000000000000 obs.dll!obs_transition_clear+0xd6
000000DEBC16A800 00007FFA7810BA85 000001FB2D58E850 000000DEBC16AAB0 0000000000000000 000001FB2D58E850 obs.dll!obs_source_destroy+0x75
000000DEBC16A900 00007FFA7810FBE9 000001FB40CA2CA0 000001FB2D51B690 000001FB2D51B690 000001FB40CA2CA0 obs.dll!obs_source_release+0x49
000000DEBC16A930 00007FFA7812150E 0000000000000000 0000000000000000 0000000000000000 000001FB2D58E850 obs.dll!obs_set_output_source+0x14e
000000DEBC16A980 00007FF71B5250E9 0000000000000001 000001FB2D58E850 0000000000000000 000001FB2D58E850 obs64.exe!OBSBasic::ClearSceneData+0x89
000000DEBC16A9B0 00007FF71B52DC58 0000000000000001 000001FB00000000 000001FB40CDD680 0000000000000001 obs64.exe!OBSBasic::LoadData+0x48
000000DEBC16ABA0 00007FF71B5F0080 000001FB40CDD680 000001FB48498CA0 000001FB2D4C6B01 000001FB40CDD680 obs64.exe!OBSBasic::ChangeSceneCollection+0x1d0

Once I remove Source Record (just delete the *.dll, nothing else changed) the scene collection changes work just fine again. So, I can at least tell you:

  1. The root cause of the crashes is Source Record, although it usually never is seen in the stack traces. But just removing it always fully gets rid of all those crashes (except those crashes caused by a similar problem in Virtual Cam Filter).

  2. The root cause of at least the OBS Studio shutdown crashes are the two lines audio_output_close(context->audio_output); and video_output_close(o); in source_record_filter_destroy, although logically they seem to be fine.

  3. As the crashes in the stack trace are always similar but not identical, it seems an overall timing or race condition issue to me.

rse commented 3 years ago

Ok, I've found out more through dozens of tests: if Source Record is just applied once(!) on a scene/source, the crashes on scene collection switching do not occur. If it is applied multiple times on a single scene/source, one can rather reliably cause the crashes on scene collection switching.

To understand why I have Source Record applied twice on the same scene/source: I want different x264 encoder parameters for Recording and Streaming: for recording I use CRF mode, for streaming I use CBR mode. So, I drive Source Record in two modes: in recording and streaming. And because there are only one set of encoder options, I have to apply source record twice on the same source (but enable just one of them, of course).

image image

So, the trouble seems to be related to a scenario when Source Record is applied twice on the same scene/source. Does this give you a clue what has to be changed to the cleanup steps in Source Record to let OBS Studio not crash in those scenarios.

Just to make sure: Source Record works just fine in this scenario for both recording and streaming. It is just the case that one no longer can switch scene collections as OBS Studio then crashes all the time. The recording and streaming itself works perfectly. But I need a 1080p profile/collection pair and a 720p profile/collection pair, so it is essential for me to let the users switch between them. And I still would like to use optimized recording/streaming encoder parameters.

Or would it be possible that Source Record provides 2 encoder property sets, one for recording and for streaming? This would indirectly solve this problem and perhaps even reduce the overall configuration complexity, too.

rse commented 3 years ago

[ALL BASED ON LATEST SOURCE RECORD master/HEAD AS OF TODAY, INCLUDING THE LATEST FIXES]

Ok, I've reduced my OBS Studio config to just a single profile plus 4 scene collections and in each collection there is just one scene with new sources at all but with Source Record applied. In "Presenter-A1" and "Presenter-A1" Source Record is applied just once on the scene, in "Presenter-B1" and "Presenter-B2" Source Record is applied twice. Here is the configuration:

config.zip

When you toggle between "Presenter-A1" and "Presenter-A2" everything works as expected. No crashes. But when you toggle to "Presenter-B1" it still works, but then toggling over to "Presenter-B2" OBS Studio rather reliably crashes. It is all the time for me under Windows 10: toggling away from either "Presenter-B1" or "Presenter-B2" lets OBS Studio crash. Sometimes without a crash log, sometimes with a crash log.

In case of a crash log, it most of the time contains entries which seem to be related to the audio processing. As in this case:

Unhandled exception: c0000005
Date/Time: 2021-06-21, 08:58:58
Fault address: 7FFA77A6D3DD (c:\users\rse\prj\obs-studio-plugin-run\dst\bin\64bit\obs.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread BEB4: audio-io: audio thread (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
0000006C917EF080 00007FFA77A6D3DD 000001F0D0A50920 000001F0D0C14280 0000006C917EF520 000000000000000C obs.dll!obs_context_data_remove+0xd
0000006C917EF0B0 00007FFA77A5BB24 000001F0D0D413C0 00028F0D23A910C6 000001F0D0C14280 0000006C917EF520 obs.dll!obs_source_destroy+0x114
0000006C917EF1B0 00007FFA77A5FBE9 000001F0D0A50920 000001F0D0C14280 0000006C917EF520 0000000000000000 obs.dll!obs_source_release+0x49
0000006C917EF1E0 00007FFA77A5C92F 0000000000000410 0000000000000400 0000000000000001 000001F0BCDB0000 obs.dll!obs_source_enum_active_tree+0x
0000006C917EF220 00007FFA7F0827B6 00028F0D24EE961C 00028F0D23C4982C 0000000000047400 00028F0BBA89261C source-record.dll!0x7ffa7f0827b6
0000006C917EF480 00007FFA77A3E5B5 0000068CEE700BC3 0000000000000015 0000000000047000 00028F0D24EE961C obs.dll!input_and_output+0x225
0000006C917EF700 00007FFA77A3E169 0000000000000015 000001F0D0D413C0 0000000000000000 0000000000000000 obs.dll!audio_thread+0xf9
0000006C917EF750 00007FFA969B5924 000001F0D0D64AF0 0000000000000000 0000000000000000 0000000000000000 w32-pthreads.dll!ptw32_threadStart+0x7
0000006C917EF7D0 00007FFAC9941BB2 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ucrtbase.dll!0x7ffac9941bb2
0000006C917EF800 00007FFACB4F7034 0000000000000000 0000000000000000 0000000000000000 0000000000000000 kernel32.dll!0x7ffacb4f7034
0000006C917EF830 00007FFACBA02651 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ntdll.dll!0x7ffacba02651

Or another one from yesterday:

Unhandled exception: c0000005
Date/Time: 2021-06-20, 23:26:41
Fault address: 7FFA77F62940 (c:\users\rse\prj\obs-studio-plugin-run\dst\bin\64bit\obs.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread E1C8: audio-io: audio thread (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
0000002B5527F6C8 00007FFA77F62940 0000019C318CD400 0000000000000008 0000019C1DCF1C40 0000002B5527F758 obs.dll!getsignal+0x20
0000002B5527F6D0 00007FFA77F63205 0000002B00000000 00007FFA77FE0318 0000002B5527F758 0000019C318CD400 obs.dll!signal_handler_signal+0x45
0000002B5527F730 00007FFA77F9BBD5 0000019C31A6F430 00026FD244427BF0 0000019C31C99E40 0000002B5527FBA0 obs.dll!obs_source_destroy+0x1c5
0000002B5527F830 00007FFA77F9FBE9 0000019C318CD400 0000019C31C99E40 0000002B5527FBA0 0000019C31AF6578 obs.dll!obs_source_release+0x49
0000002B5527F860 00007FFA77F9C92F 00007FFACB9C78AA 0000000000000000 0000000000000048 00007FFACB9D1374 obs.dll!obs_source_enum_active_tree+0x
0000002B5527F8A0 00007FFAAC8627B6 00026FD245880145 00026FD2450738C8 0000000000022C00 00026FD194C89BF0 source-record.dll!0x7ffaac8627b6
0000002B5527FB00 00007FFA77F7E5B5 0000063CFB91FE02 0000000000000015 0000000000022800 00026FD245880145 obs.dll!input_and_output+0x225
0000002B5527FD80 00007FFA77F7E169 0000000000000015 0000019C31A6F430 0000000000000000 0000000000000000 obs.dll!audio_thread+0xf9
0000002B5527FDD0 00007FFAB09B5924 0000019C31A84470 0000000000000000 0000000000000000 0000000000000000 w32-pthreads.dll!ptw32_threadStart+0x7
0000002B5527FE50 00007FFAC9941BB2 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ucrtbase.dll!0x7ffac9941bb2
0000002B5527FE80 00007FFACB4F7034 0000000000000000 0000000000000000 0000000000000000 0000000000000000 kernel32.dll!0x7ffacb4f7034
0000002B5527FEB0 00007FFACBA02651 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ntdll.dll!0x7ffacba02651

So, we now already know three things:

  1. The problem can be rather deterministically caused by applying Source Record twice onto the same source.
  2. The crashes occur when OBS Studio tries to shutdown sources (either in case OBS Studio should shutdown or the user wants to switch the scene collections)
  3. In case of crash dumps, the stack traces most of the time show an indication that the audio processing inside Source Record is still accessing information inside OBS Studio which no longer seems to exist.
rse commented 3 years ago

Please tell me if I can, beside the sample config and some stack traces above, give you more information to let you hunt down the root cause of the problem inside Source Record. I'm currently stuck with this problem as it prevents me from using multiple scene collections at all and unfortunately with my still very limited knowledge about OBS Studio internals and Source Record I'm not able to figure out the final root cause or even fix it myself...

exeldro commented 3 years ago

I have been able to replicate the crash and at a first glance I don't see the cause of the issue. I have allocated time for a deeper investigation tomorrow.

rse commented 3 years ago

Good that you are at least able to reproduce the crash now on your side, too. This way the chance is a lot higher to really find the root cause of the problem. Thanks for your efforts, Exeldro.

exeldro commented 3 years ago

I think I got the crash in the audio thread fixed now with https://github.com/exeldro/obs-source-record/commit/a04018bc983a1c90eb4508a2f167937b460b50f6.

rse commented 3 years ago

Sorry for the delay in my response: I've today tested it with the latest version (HEAD as of today) and unfortunately it still crashes. I still use the configuration you see in config.zip above and once I switch away from e.g. Presenter-B1 the scene collection I get crashes. One where Source Record can be directly seen in the stack trace is:

Unhandled exception: c0000005
Date/Time: 2021-07-04, 12:55:12
Fault address: 7FFA8C3D2940 (c:\users\rse\prj\obs-studio-plugin-run\dst\bin\64bit\obs.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread F1A8: audio-io: audio thread (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
00000029950BF358 00007FFA8C3D2940 000001484CAF3180 0000000000000008 0000014838E91600 00000029950BF3E8 obs.dll!getsignal+0x20
00000029950BF360 00007FFA8C3D3205 0000002900000000 00007FFA8C450318 00000029950BF3E8 000001484CAF3180 obs.dll!signal_handler_signal+0x45
00000029950BF3C0 00007FFA8C40BBD5 000001484C6D8A10 000699825B1AC6F2 000001484C516680 00000029950BF830 obs.dll!obs_source_destroy+0x1c5
00000029950BF4C0 00007FFA8C40FBE9 000001484CAF3180 000001484C516680 00000029950BF830 0000000000000000 obs.dll!obs_source_release+0x49
00000029950BF4F0 00007FFA8C40C92F 00007FFACB9C78AA 0000000000000000 0000000000000048 00007FFACB9D1374 obs.dll!obs_source_enum_active_tree+0x
00000029950BF530 00007FFAA14A27D8 000699825C604C48 000699825C437C80 000000000001C800 00069981CB6AEC48 source-record.dll!0x7ffaa14a27d8
00000029950BF790 00007FFA8C3EE5B5 000010E524C33C20 0000000000000015 000000000001C400 000699825C604C48 obs.dll!input_and_output+0x225
00000029950BFA10 00007FFA8C3EE169 0000000000000015 000001484C6D8A10 0000000000000000 0000000000000000 obs.dll!audio_thread+0xf9
00000029950BFA60 00007FFAB0AC5924 000001484C602110 0000000000000000 0000000000000000 0000000000000000 w32-pthreads.dll!ptw32_threadStart+0x7
00000029950BFAE0 00007FFAC9941BB2 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ucrtbase.dll!0x7ffac9941bb2
00000029950BFB10 00007FFACB4F7034 0000000000000000 0000000000000000 0000000000000000 0000000000000000 kernel32.dll!0x7ffacb4f7034
00000029950BFB40 00007FFACBA02651 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ntdll.dll!0x7ffacba02651
rse commented 3 years ago

OBS Studio still always crashes one I switch away from any scene collection where Source Record is applied twice on a scene. Not always is a stack trace written. But when it is written is nearly always looks like this:

Unhandled exception: c0000005
Date/Time: 2021-07-04, 13:02:19
Fault address: 7FFA9CE22940 (c:\users\rse\prj\obs-studio-plugin-run\dst\bin\64bit\obs.dll)
libobs version: 27.0.1 (64-bit)
Windows version: 10.0 build 19043 (release: 2009; revision: 1052; 64-bit)
CPU: Intel(R) Core(TM) i5-10600K CPU @ 4.10GHz

Thread 14234: audio-io: audio thread (Crashed)
Stack            EIP              Arg0             Arg1             Arg2             Arg3             Address
0000000EEBE7EFB8 00007FFA9CE22940 0000011BBB84FB60 0000000000000008 0000011BA79C4EA0 0000000EEBE7F048 obs.dll!getsignal+0x20
0000000EEBE7EFC0 00007FFA9CE23205 0000000E00000000 00007FFA9CEA0318 0000000EEBE7F048 0000011BBB84FB60 obs.dll!signal_handler_signal+0x45
0000000EEBE7F020 00007FFA9CE5BBD5 0000011BBB669BF0 000699E5C37174A8 0000011BBB476B20 0000000EEBE7F490 obs.dll!obs_source_destroy+0x1c5
0000000EEBE7F120 00007FFA9CE5FBE9 0000011BBB84FB60 0000011BBB476B20 0000000EEBE7F490 0000000000000000 obs.dll!obs_source_release+0x49
0000000EEBE7F150 00007FFA9CE5C92F 0000000000000410 0000000000000400 0000000000000001 0000011BA7950000 obs.dll!obs_source_enum_active_tree+0x
0000000EEBE7F190 00007FFAA32527D8 000699E5C4B6F9FD 000699E5C3D44074 0000000000011800 000699E56BB484A8 source-record.dll!0x7ffaa32527d8
0000000EEBE7F3F0 00007FFA9CE3E5B5 000010E6233D00A5 0000000000000015 0000000000011400 000699E5C4B6F9FD obs.dll!input_and_output+0x225
0000000EEBE7F670 00007FFA9CE3E169 0000000000000015 0000011BBB669BF0 0000000000000000 0000000000000000 obs.dll!audio_thread+0xf9
0000000EEBE7F6C0 00007FFAB1915924 0000011BBB574B40 0000000000000000 0000000000000000 0000000000000000 w32-pthreads.dll!ptw32_threadStart+0x7
0000000EEBE7F740 00007FFAC9941BB2 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ucrtbase.dll!0x7ffac9941bb2
0000000EEBE7F770 00007FFACB4F7034 0000000000000000 0000000000000000 0000000000000000 0000000000000000 kernel32.dll!0x7ffacb4f7034
0000000EEBE7F7A0 00007FFACBA02651 0000000000000000 0000000000000000 0000000000000000 0000000000000000 ntdll.dll!0x7ffacba02651
naveenkcherukuri commented 2 years ago

Hi, Were you able to resolve this. I see the exact similar crashes.

KeiBoogie commented 5 months ago

Same problem, decided to uninstall the plugin.