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

Crash on iOS when swiping app out #112

Open
sdelaysam opened this issue Nov 29, 2017 · 11 comments
Open

Crash on iOS when swiping app out #112

sdelaysam opened this issue Nov 29, 2017 · 11 comments

Comments

@sdelaysam
Copy link

sdelaysam commented Nov 29, 2017

Hi, @frankinshtein !

There is a crash on iOS when using OXYGINE_DEBUG_TRACE_LEAKS.
It occurs each time when app is swiped out from tasks.

4  game                           0x1013d4ea8 oxygine::ObjectBase::__removeFromDebugList(oxygine::ObjectBase*) + 932
5  game                           0x1013d54c0 oxygine::ObjectBase::~ObjectBase() + 216
6  game                           0x10129c2f0 oxygine::Object::~Object() + 40
7  game                           0x1015a184c oxygine::ShaderProgram::~ShaderProgram() + 36
8  game                           0x1015a1938 oxygine::ShaderProgramGL::~ShaderProgramGL() + 136
9  game                           0x1015a1974 oxygine::ShaderProgramGL::~ShaderProgramGL() + 28
10 game                           0x1015a19dc oxygine::ShaderProgramGL::~ShaderProgramGL() + 28

I've managed to catch it in Xcode debugger

if (_tracingLeaks)
{
    MutexAutoLock m_(getMutex());
    if (base->__traceLeak)
    {
        base->__traceLeak = false;
        __createdObjects& objs = __getCreatedObjects();
        __createdObjects::iterator i = std::find(objs.begin(), objs.end(), base);
        OX_ASSERT(i != objs.end());  // <-- That line
        objs.erase(i);
    }
}

UPD: maybe its on my side, didn't notice it on example projects..

@frankinshtein
Copy link
Contributor

yes, it is on your side
same object was deleted twice or was deleted previously

@sdelaysam
Copy link
Author

No, having the same issue with HelloWorld example

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x00000001836c5348 __pthread_kill + 8
1   libsystem_pthread.dylib       	0x00000001837d9354 pthread_kill$VARIANT$mp + 396
2   libsystem_c.dylib             	0x0000000183634fd8 abort + 140
3   libsystem_c.dylib             	0x0000000183608abc basename_r + 0
4   HelloWorld_ios                	0x00000001011c4ab0 oxygine::ObjectBase::__removeFromDebugList(oxygine::ObjectBase*) + 264880 (Object.cpp:226)
5   HelloWorld_ios                	0x00000001011c5048 oxygine::ObjectBase::~ObjectBase() + 266312 (Object.cpp:187)
6   HelloWorld_ios                	0x00000001011c68e8 oxygine::Object::~Object() + 272616 (Object.h:83)
7   HelloWorld_ios                	0x00000001011db224 oxygine::EventDispatcher::~EventDispatcher() + 356900 (EventDispatcher.cpp:20)
8   HelloWorld_ios                	0x0000000101190864 oxygine::Actor::~Actor() + 51300 (Actor.cpp:96)
9   HelloWorld_ios                	0x0000000101236b64 oxygine::VStyleActor::~VStyleActor() + 732004 (VisualStyle.h:29)
10  HelloWorld_ios                	0x000000010123b7ac oxygine::TextField::~TextField() + 751532 (TextField.cpp:43)
11  HelloWorld_ios                	0x000000010123b7e0 oxygine::TextField::~TextField() + 751584 (TextField.cpp:43)
12  HelloWorld_ios                	0x000000010123b848 oxygine::TextField::~TextField() + 751688 (TextField.cpp:40)

@frankinshtein
Copy link
Contributor

how to reproduce it in HelloWorld then?

@sdelaysam
Copy link
Author

Just try launch it on device, then put to background, then swipe out from recent tasks.
I did it like 10 times and found 3 crashes in device logs (Xcode -> Devices & Simulators -> View Device Logs)

@frankinshtein
Copy link
Contributor

but without crash in xcode?

@sdelaysam
Copy link
Author

Hmm, what do you mean?

@frankinshtein
Copy link
Contributor

breakpoint stop when error occurs

@sdelaysam
Copy link
Author

Ahh, yep, I could catch it that way, but only once. Steps are the same.

@sdelaysam
Copy link
Author

After some investigation, I think that it might be SDL issue. Looks like there is a problem with app termination on iOS. Just give you an idea of what I did.

  1. In SDL_video.c
void SDL_OnApplicationWillTerminate(void)
{
    SDL_SendQuit(); // <-- add this line
    SDL_SendAppEvent(SDL_APP_TERMINATING);
}
  1. In SDL_main.h add these lines
#define SDLEXIT_DECLSPEC
#define exit    SDL_exit
extern C_LINKAGE SDLEXIT_DECLSPEC void SDL_exit();
  1. In main.cpp defined exit() function, which do regular destroy logic.

  2. In SDL_uikitappdelegate.m

- (void)applicationWillTerminate:(UIApplication *)application
{
    SDL_OnApplicationWillTerminate();
    SDL_exit(); // <-- add this line
}

Note: I'm using CADisplayLink for game loop update.

@frankinshtein
Copy link
Contributor

hmm, oxygine examples doesnt use CADisplayLink
in this case you just have to destroy everything in applicationWillTerminate

/*
     If we get here, the user has requested the Application to terminate.
     We dump and log all our created objects that have not been freed yet
    */
    ObjectBase::dumpCreatedObjects();

    /*
    Let's clean up everything right now and call ObjectBase::dumpObjects() again.
    We need to free all allocated resources and delete all created actors.
    All actors/sprites are smart-pointer objects and don't need to be removed by hand.
    But now we want to delete it by hand.
    */

    // See example.cpp for the shutdown function implementation
    example_destroy();


    //renderer.cleanup();

    // Releases all internal components and the stage
    core::release();

    // The dump list should be empty by now,
    // we want to make sure that there aren't any memory leaks, so we call it again.
    ObjectBase::dumpCreatedObjects();

    ObjectBase::__stopTracingLeaks();

@sdelaysam
Copy link
Author

Yes, exactly! Release logic need to be called synchronously in applicationWillTerminate.

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

2 participants