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

g_extern.audio_data.data NULL on ios 8 with retroarch 1.0.0.2 / 1.0.3 #1067

Closed
jeapostrophe opened this issue Sep 30, 2014 · 3 comments
Closed

Comments

@jeapostrophe
Copy link
Contributor

I'm building my own version for a non-Jailbroken device. I am using the latest git version as of yesterday.

I got lots of crashes that had stacks like this:

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000

0 RetroArch 0x00013c88 audio_convert_s16_float_asm (utils_neon.S:63)
1 RetroArch 0x0006b476 audio_convert_s16_to_float_neon (utils.c:159)
2 RetroArch 0x000435d8 rarch_audio_flush (retroarch.c:483)
3 RetroArch 0x00042b46 audio_sample_batch (libretro_version_1.c:125)

To simplify debugging, I disabled the NEON assembly by changing utils.c:283 to

audio_convert_s16_to_float_arm = cpu & RETRO_SIMD_NEON & 0 ?

(notice the & 0)

This got me crashes like this:

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000

0 RetroArch 0x0006b4fe audio_convert_s16_to_float_C (utils.c:35)
1 RetroArch 0x00043628 rarch_audio_flush (retroarch.c:483)
2 RetroArch 0x00042b96 audio_sample_batch (libretro_version_1.c:125)

Since that code dereferences out and in, I went back to rarch_audio_flush to look at its arguments. In retroarch.c:484-ish, it is called with:

out = g_extern.audio_data.data and in = data

I added this around line 481

if (!g_extern.audio_data.data)
return false;

to protect against it being NULL as an experiment. At this point, the crashes went away and I got the expected result of the game playing but not having any audio.

The initialization code from driver.c:1107 is wrapped in an rarch_assert, which is surprising because it is definitely NULL here.

Any ideas about how I might fix this problem or provide more useful debugging information?

@jeapostrophe
Copy link
Contributor Author

I have found that it is being initialized correctly by adding some printfs:

Sep 30 11:28:26 RetroArch[3036] : BEFORE Initializing g_extern.audio_data.data: 0000000000000000
Sep 30 11:28:26 RetroArch[3036] : AFTER Initializing g_extern.audio_data.data: 000000000577c000

But that by the time we go to flush, it has been zero'd

Sep 30 11:28:26 RetroArch[3036] : Getting ready to flush to g_extern.audio_data.data: 0000000000000000

I also added some printfs in the uninit audio code and it is NOT getting uninitialized early. Any where else that audio_data could be effected?

@jeapostrophe
Copy link
Contributor Author

https://github.com/libretro/RetroArch/blob/master/retroarch.c#L2536

That's the line that kills it.

Sep 30 11:55:00 Bleu RetroArch[3074] : BEFORE Initializing g_extern.audio_data.data: 0000000000000000
Sep 30 11:55:00 Bleu RetroArch[3074] : AFTER Initializing g_extern.audio_data.data: 0000000006eb3000
Sep 30 11:55:00 Bleu RetroArch[3074] : Exiting init_audio: g_extern.audio_data.data: 0000000006eb3000
Sep 30 11:55:00 Bleu RetroArch[3074] : GL VSync => on
Sep 30 11:55:00 Bleu RetroArch[3074] : BEFORE (clearing g_extern) g_extern.audio_data.data: 0000000006eb3000
Sep 30 11:55:00 Bleu RetroArch[3074] : AFTER (clearing g_extern) g_extern.audio_data.data: 0000000000000000

@jeapostrophe
Copy link
Contributor Author

diff --git a/retroarch.c b/retroarch.c
index abb060d..fb8b658 100644
--- a/retroarch.c
+++ b/retroarch.c
@@ -475,7 +475,7 @@ bool rarch_audio_flush(const int16_t *data, size_t samples)

    if (g_extern.is_paused || g_extern.audio_data.mute)
       return true;
-   if (!g_extern.audio_active)
+   if (!g_extern.audio_active || !g_extern.audio_data.data)
       return false;

    RARCH_PERFORMANCE_INIT(audio_convert_s16);
@@ -2533,7 +2533,12 @@ void rarch_main_clear_state(void)

    deinit_log_file();

+   // XXX This memset is really dangerous. (a) it can leak memory
+   // because the pointers in g_extern aren't freed and (b) it can
+   // zero pointers that the rest of the code will look at.
+   uninit_drivers();
    memset(&g_extern, 0, sizeof(g_extern));
+   init_drivers();

    init_state();

inactive123 added a commit that referenced this issue Jul 11, 2019
2820ab0b51 Merge pull request #1076 from KhronosGroup/bitcast-pre-330-glsl
63bcbd511e GLSL: Need extension to use bitcast on GLSL < 330.
9f3bebe3d0 Merge pull request #1075 from lifpan/master
b11c20fc1d Remove unreasonable assertion for OpTypeImage Sampled parameter.
1a592b7c0f Merge pull request #1067 from cdavis5e/msl-scalar-block-layout
28454facbb MSL: Handle packed matrices.
ea5c0ed82f MSL: Fix alignment of packed types.
44f688bf0b Merge pull request #1070 from KhronosGroup/fix-1066
25c74b324e Forget loop variable enables after emitting block chain.
6b010e0cbc Merge pull request #1069 from KhronosGroup/fix-1053
f6f849397e MSL: Re-roll array expressions in initializers.
e5fa7edfd6 MSL: Support scalar block layout.

git-subtree-dir: deps/SPIRV-Cross
git-subtree-split: 2820ab0b51bf5e4187435d904b34e762b988f48b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant