Cocos2dx iOS Approved App Crashing

5

So I have been stuck for a couple of days on this extremely strange and annoying problem. So I have an app that I released to the ios app store and I have recently went back and added some extra features to the application. I didnt touch the core of the app just added things like twitter, facebook, in app purchases, and google admob (for the free version that is based off the full version). So here is where things go weird. I tested my update I made a adhoc release build and tested on my iphone 3gs, 4s, ipad 2 - no problems at all. I submitted to apple they approved the update and it was released. I updated the application and tried to run it and boom crashes right after the splash screen (again nothing here was changed). My project uses the cocos2dx framework (version cocos2d-2.0-x-2.0.4 @ Nov 02 2012) and I uses cocosbuilder (2.1). I looked at the log and it seemed to be an unalignment issue inside the CCBReader::readFloat() function. I found that there was a fix to this here: https://github.com/DarraghCoy/cocos2d-x/commit/34b31fd754778f815fcac108089e3fe015e2e2b9.

So I went ahead and modified my default case as well from this: float CCBReader::readFloat() { unsigned char type = this->readByte();

        switch (type) {
            case kCCBFloat0:
                return 0;    
            case kCCBFloat1:
                return 1;
            case kCCBFloatMinus1:
                return -1;
            case kCCBFloat05:
                return 0.5f;
            case kCCBFloatInteger:
                return (float)this->readInt(true);
            default:
                {
                    /* using a memcpy since the compiler isn't
                     * doing the float ptr math correctly on device.
                     * TODO still applies in C++ ? */
                    float * pF = (float*)(this->mBytes + this->mCurrentByte);
                    float f = 0;

                    memcpy( &f, pF, sizeof(float));
                    this->mCurrentByte += 4;

                    return f;
                }
        }
    }

To this:

    float CCBReader::readFloat() {
        unsigned char type = this->readByte();

        switch (type) {
            case kCCBFloat0:
                return 0;    
            case kCCBFloat1:
                return 1;
            case kCCBFloatMinus1:
                return -1;
            case kCCBFloat05:
                return 0.5f;
            case kCCBFloatInteger:
                return (float)this->readInt(true);
            default:
                {
                    /* using a memcpy since the compiler isn't
                     * doing the float ptr math correctly on device.
                     * TODO still applies in C++ ? */
                    float * pF = (float*)(this->mBytes + this->mCurrentByte);
                    float f = 0;

                    memcpy((void*) &f, (const void*) pF, sizeof(float));

                    this->mCurrentByte += sizeof(float);


                    return f;
                }
        }
    }        

Again testing a release build on devices no isses. I submitted this fix to apple and requested a expedited review so the application would run instead of crashing and it got apple approval within 1 day and was shipped out. I update to the new version launch and again its crashing.

Here is a copy of the crash log:

Incident Identifier: DCFEA2A4-9707-4FF7-A4B7-26CF61B4A73F
CrashReporter Key:   b91e2f134184158618753244f837ff2ac5114f0d
Hardware Model:      iPhone4,1
Process:         GAMEAPP [848]
Path:            /var/mobile/Applications/F860F02C-3D16-4995-A19F-CE036200209F/GAMEAPP.app/GAMEAPP
Identifier:      GAMEAPP
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2013-03-01 19:42:44.987 -0500
OS Version:      iOS 6.1.2 (10B146)
Report Version:  104

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: EXC_ARM_DA_ALIGN at 0x1f0807c9
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   GAMEAPP                     0x000f971c cocos2d::extension::CCBReader::readFloat() (CCBReader.cpp:422)
1   GAMEAPP                     0x000f9e52 cocos2d::extension::CCBReader::readKeyframe(int) (CCBReader.cpp:648)
2   GAMEAPP                     0x000f99ae cocos2d::extension::CCBReader::readNodeGraph(cocos2d::CCNode*) (CCBReader.cpp:509)
3   GAMEAPP                     0x000f9c20 cocos2d::extension::CCBReader::readNodeGraph(cocos2d::CCNode*) (CCBReader.cpp:586)
4   GAMEAPP                     0x000f9342 cocos2d::extension::CCBReader::readFileWithCleanUp(bool) (CCBReader.cpp:689)
5   GAMEAPP                     0x000f92ec cocos2d::extension::CCBReader::readNodeGraphFromData(cocos2d::extension::CCData*, cocos2d::CCObject*, cocos2d::CCSize const&, cocos2d::extension::CCBAnimationManager**) (CCBReader.cpp:230)
6   GAMEAPP                     0x000f91aa cocos2d::extension::CCBReader::readNodeGraphFromFile(char const*, cocos2d::CCObject*, cocos2d::CCSize const&, cocos2d::extension::CCBAnimationManager**) (CCBReader.cpp:213)
7   GAMEAPP                     0x000f90a4 cocos2d::extension::CCBReader::readNodeGraphFromFile(char const*, cocos2d::CCObject*) (CCBReader.cpp:192)
8   GAMEAPP                     0x00119b50 IntroScene::init() (IntroScene.cpp:55)
9   GAMEAPP                     0x00119ca8 IntroScene::create() (IntroScene.h:19)
10  GAMEAPP                     0x00119a7c IntroScene::scene() (IntroScene.cpp:22)
11  GAMEAPP                     0x00110290 AppDelegate::applicationDidFinishLaunching() (AppDelegate.cpp:144)
12  GAMEAPP                     0x000dab94 cocos2d::CCApplication::run() (CCApplication.mm:50)
13  GAMEAPP                     0x000b6610 -[AppController application:didFinishLaunchingWithOptions:] (AppController.mm:76)
14  UIKit                           0x36522ad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
15  UIKit                           0x3652265e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
16  UIKit                           0x3651a846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
17  UIKit                           0x364c2c34 -[UIApplication handleEvent:withNewEvent:] + 1000
18  UIKit                           0x364c26c8 -[UIApplication sendEvent:] + 68
19  UIKit                           0x364c2116 _UIApplicationHandleEvent + 6150
20  GraphicsServices                0x381d85a0 _PurpleEventCallback + 588
21  GraphicsServices                0x381d81ce PurpleEventCallback + 30
22  CoreFoundation                  0x3468f170 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
23  CoreFoundation                  0x3468f112 __CFRunLoopDoSource1 + 134
24  CoreFoundation                  0x3468df94 __CFRunLoopRun + 1380
25  CoreFoundation                  0x34600eb8 CFRunLoopRunSpecific + 352
26  CoreFoundation                  0x34600d44 CFRunLoopRunInMode + 100
27  UIKit                           0x36519480 -[UIApplication _run] + 664
28  UIKit                           0x365162fc UIApplicationMain + 1116
29  GAMEAPP                     0x000b6c22 main (main.m:14)
30  GAMEAPP                     0x000b6344 start + 36

Thread 1:
0   libsystem_kernel.dylib          0x3c8d5d98 __workq_kernreturn + 8
1   libsystem_c.dylib               0x3c823cf6 _pthread_workq_return + 14
2   libsystem_c.dylib               0x3c823a12 _pthread_wqthread + 362
3   libsystem_c.dylib               0x3c8238a0 start_wqthread + 4

Thread 2 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 2:
0   libsystem_kernel.dylib          0x3c8c5648 kevent64 + 24
1   libdispatch.dylib               0x3c7f5974 _dispatch_mgr_invoke + 792
2   libdispatch.dylib               0x3c7f5654 _dispatch_mgr_thread$VARIANT$mp + 32

Thread 3:
0   libsystem_kernel.dylib          0x3c8d5d98 __workq_kernreturn + 8
1   libsystem_c.dylib               0x3c823cf6 _pthread_workq_return + 14
2   libsystem_c.dylib               0x3c823a12 _pthread_wqthread + 362
3   libsystem_c.dylib               0x3c8238a0 start_wqthread + 4

Thread 4 name:  WebThread
Thread 4:
0   libsystem_kernel.dylib          0x3c8c4eb4 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3c8c5048 mach_msg + 36
2   CoreFoundation                  0x3468f040 __CFRunLoopServiceMachPort + 124
3   CoreFoundation                  0x3468dd9e __CFRunLoopRun + 878
4   CoreFoundation                  0x34600eb8 CFRunLoopRunSpecific + 352
5   CoreFoundation                  0x34600d44 CFRunLoopRunInMode + 100
6   WebCore                         0x3a60a500 RunWebThread(void*) + 440
7   libsystem_c.dylib               0x3c82e30e _pthread_start + 306
8   libsystem_c.dylib               0x3c82e1d4 thread_start + 4

Thread 5 name:  AURemoteIO::IOThread
Thread 5:
0   libsystem_kernel.dylib          0x3c8c4eb4 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3c8c5048 mach_msg + 36
2   AudioToolbox                    0x3418391c AURemoteIO::IOThread::Run() + 104
3   AudioToolbox                    0x34185c84 AURemoteIO::IOThread::Entry(void*) + 4
4   AudioToolbox                    0x340c3882 CAPThread::Entry(CAPThread*) + 294
5   libsystem_c.dylib               0x3c82e30e _pthread_start + 306
6   libsystem_c.dylib               0x3c82e1d4 thread_start + 4

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x1ed49740    r1: 0x1f0807c9      r2: 0x000001cd      r3: 0x000001c8
    r4: 0x00000004    r5: 0x1ed49740      r6: 0x42480000      r7: 0x2fd4af48
    r8: 0xffffffff    r9: 0x000001c9     r10: 0x1ed49740     r11: 0x1ed4a8a0
    ip: 0x000001c7    sp: 0x2fd4af48      lr: 0x000f9e57      pc: 0x000f971c
  cpsr: 0x00000030

Binary Images:

I did modifie the other linker flags to include -lsqlite3.0 and -ObjC (originally it was just -lxml2 and -lz). My release build optimization is -Os (Fastest, Smallest).

Anyone else have this issue? I have no idea how to debug this as I cannot repro. Lastly how is it that apple approves the app yet it crashes right after the splash screen? If I can guess when the run the app it works and maybe it gets broken when it goes threw the "Processing for App Store" stage post app approval (not sure).

Thanks!

iphone
ios
cocos2d-iphone
cocos2d-x
asked on Stack Overflow Mar 3, 2013 by kub • edited Mar 3, 2013 by kub

5 Answers

2

My first reaction, based on your statements towards the end, is that the 'app update bug' which Apple claimed to have solved is not completely solved yet. The DRM patch which is added during the update, somehow crashes updated apps immediately on start. http://www.tuaw.com/2013/03/01/bug-in-latest-evernote-for-ios-update-causes-the-app-to-crash/ https://discussions.apple.com/thread/3389977?start=0&tstart=0 http://www.pcworld.com/article/258827/updated_apps_crashing_heres_what_you_need_to_know.html

There have been many similar questions asked related to App update crash bug. There are some best practises or workarounds, undocumented by Apple specifically wrt avoiding the update bug. Do check them out. One of them may workout for you, if it is not something specific to your app.

Updated App Crashing on iPad iPhone app crash immediately after update

answered on Stack Overflow Mar 4, 2013 by S G • edited May 23, 2017 by Community
2

This post regarding EXC_BAD_ACCESS errors in CCBReader helped me with the exact same issue: http://www.cocos2d-x.org/boards/6/topics/18183

Turns out, it was linked to memory misalignment in CCBReader which will run fine on the sim, but will crash on a device due to its ARM processor.

answered on Stack Overflow Mar 5, 2013 by rswayz • edited Mar 5, 2013 by rswayz
2

I know a workaround. Edit the scheme to build for Debug and not Release and it seems to not blow up.

I've had two rejections, too. Trick was I had one version (FREE) of the app passing and the other (PREMIUM) crashing. I chased down that difference, and confirmed that the difference.

CCBReader 2.0

The side effect of Debug/Release is possibly the optimization, as @LearnCocos2D mentioned.


Optimization workaround:

  • Select the target.
  • Select the Build Phases tab.
  • Expand the Compile Sources item. It should list all the files compiled. If you notice at the top there is a second column "Compiler Flags".
  • Select CCBReader.m
  • Double-click the Compiler Flags column
  • enter "-O0"

resolved the problem for me.

answered on Stack Overflow Apr 4, 2013 by bshirley • edited Apr 4, 2013 by bshirley
0

I was like "WTF is CCB doing there?" .... anyhow, try with -O3 or no optimization at all. -Os is known to cause subtle issues, especially with cocos2d. There's a reason why -Os is not the default level for cocos2d (and I believe the Xcode templates too).

If this fixes the issue, you can set optimization level or disable optimizations just for this file or function using one of the answers of this question.

answered on Stack Overflow Mar 3, 2013 by LearnCocos2D • edited May 23, 2017 by Community
0

you are using ccbi files to create UI,Your game crashing randomly because of you are not setting your reference variable to nullptr in init method of your class.

For Example i declared Label *homeLabel; in intorScene.h file, in .cpp file init method you should set this variable to

homeLabel = nullptr;

answered on Stack Overflow Jun 8, 2016 by Shauket Sheikh

User contributions licensed under CC BY-SA 3.0