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

Windows & Android: "Close Content" crashes when the core uses RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK with RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK #7647

Open
Ghabry opened this issue Nov 25, 2018 · 8 comments

Comments

@Ghabry
Copy link
Contributor

Ghabry commented Nov 25, 2018

Because it affects all cores which use these APIs (RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK with RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK) I assume this is a RetroArch bug.

Description

Load Content through Dinothwar, lutro or easyrpg and then press F1 and select "Close Content".
These are the only 3 cores which use that API.

Stacktrace:

Only the first function on the stackframe is from the core, the rest on the stackframe is RetroArch. The crash is at the prolog of the function which means the memory is unmapped (DLL unloaded?). I can't even read any core variable through gdb, just get "Cannot access memory".

I guess audio_driver_callback should stop invoking the audio callback after unloading the core, but I'm not familiar enough with the code to fix this on my own.

Dinothwar (no idea why, i have symbols loaded)

Thread 12 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 19640.0x477c]
0x000000000fb0c473 in ?? ()

Lutro

#0  emit_audio () at libretro.c:35
#1  0x000000000043b238 in audio_driver_callback ()
    at audio/audio_driver.c:1451
#2  0x00000000006b6cc6 in audio_thread_loop (data=0xf471060)
    at audio/audio_thread_wrapper.c:108
#3  0x00000000006b2d86 in thread_wrap (data_=0xd82fc20)
    at libretro-common/rthreads/rthreads.c:148
#4  0x00007ffacf7e3034 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\System32\kernel32.dll
#5  0x00007ffacff01471 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
#6  0x0000000000000000 in ?? ()

Easyrpg core shows this:

#0  retro_write_audio ()
    at EasyRPG/libretro-super/libretro-easyrpg/builds/libretro/../../src/libretro_wrapper.cpp:34
#1  0x000000000043b238 in audio_driver_callback ()
    at audio/audio_driver.c:1451
#2  0x00000000006b6cc6 in audio_thread_loop (data=0xdbecbf0)
    at audio/audio_thread_wrapper.c:108
#3  0x00000000006b2d86 in thread_wrap (data_=0xdb2f020)
    at libretro-common/rthreads/rthreads.c:148
#4  0x00007ffacf7e3034 in KERNEL32!BaseThreadInitThunk ()
   from C:\WINDOWS\System32\kernel32.dll
#5  0x00007ffacff01471 in ntdll!RtlUserThreadStart ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
#6  0x0000000000000000 in ?? ()

Version/Commit

  • RetroArch: 4a4a651 (25 Nov 18), from the buildbot

Environment information

  • OS: Win10 x64
  • Compiler: nightly from buildbot
  • Audio: RTKVHD64 (Surface Pro 4, cheap version with m3-6Y30 CPU)
@Ghabry
Copy link
Contributor Author

Ghabry commented Nov 25, 2018

When using "info sharedlibrary" on startup and when the segfault occurs I see that the library was relocated:

Startup:
0x000000000f771000  0x000000000f811ba8  Yes         cores\lutro_libretro.dll

Sigsegv:
0x000000000f731000  0x000000000f7d1ba8  Yes         cores\lutro_libretro.dll

@RobLoach
Copy link
Member

RobLoach commented Dec 1, 2018

What game are you running through Lutro? I'm unable to replicate this issue on Linux.

@Ghabry
Copy link
Contributor Author

Ghabry commented Dec 1, 2018

It works on Linux that's why I prefixed the issue with "Windows:"

What game

iirc it was Tetris but shouldn't matter

@ghost
Copy link

ghost commented Dec 31, 2018

@Ghabry did you try it with 'wasapi' audio driver?

@Ghabry
Copy link
Contributor Author

Ghabry commented Jan 4, 2019

Don't ask me which commit solved this but it works now for me with any audio backend.

Except Dinothawr but this must be a different bug. 👍

@Ghabry Ghabry closed this as completed Jan 4, 2019
@Ghabry Ghabry changed the title Windows: "Close Content" crashes when the core uses RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK with RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK Windows & Android: "Close Content" crashes when the core uses RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK with RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK Apr 27, 2019
@Ghabry
Copy link
Contributor Author

Ghabry commented Apr 27, 2019

Actually this was not really fixed, happened later again, maybe some race condition.
This is also crashing on Android, I can proof this: I added code to remove the callback while unloading the core and it suddenly stopped crashing.

Related issue: libretro/easyrpg-libretro#36 (comment)

Workaround:

RETRO_API void retro_unload_game() { 
	// Workaround a crash on Windows & Android because the callbacks are invoked after the DLL/SO was unloaded 
	static retro_audio_callback no_audio_callback_definition = { 
		nullptr, 
		nullptr 
	}; 
	environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK, &no_audio_callback_definition); 

cc @RobLoach

@SapphireDrew
Copy link

SapphireDrew commented Feb 3, 2021

Can second this is not resolved. This is probably why I'm having Access Violations whenever I move or resize RA's window while OBS is capturing RA via Game Capture, and likewise in the Lutro core if I move the windows around mid-sound effect then immediately select Close Content on the Quick Menu.

I can reproduce the bug consistently on Windows 10.

@Ghabry
Copy link
Contributor Author

Ghabry commented Feb 4, 2021

okay will reopen this.

@Ghabry Ghabry reopened this Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants