SDL_INIT_EVERYTHING crashes on IOS 7.0 simulator

Hello ,

I am getting strange behavior when using SDL_INIT_EVERYTHING with SDL 2.0.2
and IOS 7.0 x86 simulator, Mac OSX 10.9 .
If I take the XCODE IOS template from the SDL source and change
SDL_Init(SDL_INIT_VIDEO) )
to SDL_Init(SDL_INIT_EVERYTHING) . I got random crashes and this errors
from the address sanitizer.

==9791==ERROR: AddressSanitizer: attempting double-free on 0x0ab7a350 in
thread T0:

#0 0x102035 in wrap_free _asan_rtl_
#1 0x54714 in SDL_DestroySemaphore SDL_syssem.c:119
#2 0x54150 in SDL_CreateThread SDL_thread.c:382
#3 0x54d12 in SDL_TimerInit SDL_timer.c:233
#4 0x3ede in SDL_InitSubSystem SDL.c:158
#5 0x36e7 in SDL_main main.cpp:74
#6 0x8ae30 in -[SDLUIKitDelegate postFinishLaunch]

SDL_uikitappdelegate.m:189
#7 0x61012b in __NSFireDelayedPerform (in Foundation) + 371
#8 0x2908bd5 in
CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION (in
CoreFoundation) + 21
#9 0x29085bc in __CFRunLoopDoTimer (in CoreFoundation) + 1180
#10 0x28f0627 in __CFRunLoopRun (in CoreFoundation) + 1815
#11 0x28efac2 in CFRunLoopRunSpecific (in CoreFoundation) + 466
#12 0x28ef8da in CFRunLoopRunInMode (in CoreFoundation) + 122
#13 0x372b9e1 in GSEventRunModal (in GraphicsServices) + 191
#14 0x372b808 in GSEventRun (in GraphicsServices) + 103
#15 0x9ead3a in UIApplicationMain (in UIKit) + 1224

#16 0x8a95a in main SDL_uikitappdelegate.m:59
#17 0x33cd70c in start (in libdyld.dylib) + 0
#18 0x0 in 0x0

0x0ab7a350 is located 0 bytes inside of 28-byte region
[0x0ab7a350,0x0ab7a36c)
freed by thread T0 here:
==9791==AddressSanitizer CHECK failed:
/Users/sabotage3d/DEV/libs/llvm/projects/compiler-unsigned short
restrict/lib/asan/asan_allocator2.cc:237 “((id)) != (0)” (0x0, 0x0)
#0 0x10ade7 in __asan::AsanCheckFailed asan_rtl
#1 0x10ec21 in __sanitizer::CheckFailed sanitizer_common.cc:76

 #1 0x54714 in SDL_DestroySemaphore SDL_syssem.c:119

How did you build SDL? Line 119 is only SDL_DestroySemaphore() if you
use the SDL_syssem.c in the “generic” folder. You want the one in the
"pthread" folder for iOS.

(If you’re compiling SDL with the rest of your app…that’s sort of
risky, for just this sort of reason.)

–ryan.

I copied all the sources and headers from the Xcode template and I made my
own custom cmake build. I coped all files form src and include to my build.
The Cmake is explicit for the source and headers but I will double check if
it is not mixing some wrong files.

Thanks,

Alex

Hi again, I can see the exactly same behavior from the Xcode SDL project in
SDL 2.0.2 .
These are the steps to reproduce the problem.

  1. Build with the SDL 2.0.2 with the Xcode project provided for the
    simulator
  2. Open the SDL template and add the static SDL library to the project and
    the headers from the include directory of the SDL source.
  3. If we run with SDL_INIT_VIDEO its all fine it runs properly.
  4. if we run with SDL_INIT_EVERYTHING the same problems it seems it is
    referencing wrong files somewhere .

==18042==ERROR: AddressSanitizer: attempting double-free on 0x0aa789a0 in
thread T0:

#0 0xf3035 in wrap_free _asan_rtl_
#1 0x281ed in SDL_DestroySemaphore SDL_syssem.c:119
#2 0x28bba in SDL_CreateThread SDL_thread.c:382
#3 0x4422 in SDL_TimerInit SDL_timer.c:233
#4 0x27a54 in SDL_InitSubSystem SDL.c:158
#5 0x3a17 in SDL_main main.c:59
#6 0x5d340 in -[SDLUIKitDelegate postFinishLaunch]

SDL_uikitappdelegate.m:18

Let me know if it is worth trying another version .

Thanks,

Alex

.

That call stack looks good, since we use the generic semaphore support on
iOS, but I don’t see any way for there to be a double free on that
semaphore. It’s allocated in that function, and then freed in a single
place in that same function.

SDL_INIT_EVERYTHING does initialize the haptic system, which isn’t
supported on iOS, so SDL_Init() fails… maybe there’s something else going
on?

Do you have memory corruption happening in your program? Maybe there’s a
bug in AddressSanitizer?On Sun, Mar 16, 2014 at 10:20 AM, Alexander Chaliovski <sabotage3d at gmail.com wrote:

Hi again, I can see the exactly same behavior from the Xcode SDL project
in SDL 2.0.2 .
These are the steps to reproduce the problem.

  1. Build with the SDL 2.0.2 with the Xcode project provided for the
    simulator
  2. Open the SDL template and add the static SDL library to the project and
    the headers from the include directory of the SDL source.
  3. If we run with SDL_INIT_VIDEO its all fine it runs properly.
  4. if we run with SDL_INIT_EVERYTHING the same problems it seems it is
    referencing wrong files somewhere .

==18042==ERROR: AddressSanitizer: attempting double-free on 0x0aa789a0 in
thread T0:

#0 0xf3035 in wrap_free _asan_rtl_
#1 0x281ed in SDL_DestroySemaphore SDL_syssem.c:119
#2 0x28bba in SDL_CreateThread SDL_thread.c:382
#3 0x4422 in SDL_TimerInit SDL_timer.c:233
#4 0x27a54 in SDL_InitSubSystem SDL.c:158
#5 0x3a17 in SDL_main main.c:59
#6 0x5d340 in -[SDLUIKitDelegate postFinishLaunch]

SDL_uikitappdelegate.m:18

Let me know if it is worth trying another version .

Thanks,

Alex

.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ok I think I know what is happening

This macro inside /thread/pthread/SDL_syssem.c doesn’t seem to work under
the simulator

#if defined(MACOSX) || defined(IPHONEOS)
/* Mac OS X doesn’t support sem_getvalue() as of version 10.4 */
#include “…/generic/SDL_syssem.c”
#else

then the compiler includes /generic/SDL_syssem.c

And this function causes problems.

SDL_DestroySemaphore(SDL_sem * sem)
{
if (sem) {
sem->count = 0xFFFFFFFF;
while (sem->waiters_count > 0) {
SDL_CondSignal(sem->count_nonzero);
SDL_Delay(10);
}
SDL_DestroyCond(sem->count_nonzero);
if (sem->count_lock) {
SDL_LockMutex(sem->count_lock);
SDL_UnlockMutex(sem->count_lock);
SDL_DestroyMutex(sem->count_lock);
}
SDL_free(sem);
}
}

LLDB is triggered as well but I guess this is not suppose to be compiled in
the first place.

~Alex

I can confirm that after commenting this line

SDL_DestroyCond(sem->count_nonzero);

cleared any crashes or issues I had. So far I did some tests with most of
the subsystems and they seem to be stable. I switched to 2.0.3 mercurial .

~Alex