app crashing due to resource not loading properly randomly - ios

basically Im making a game on Sprite Kit using Obj-C in XCode 5
whenever I tap the screen, I use an SKAction to play a sound file
[self runAction:[SKAction playSoundFileNamed:#"tap.caf" waitForCompletion:NO]];
Previously I used the mp3 file that i had of the same sound and the error kept popping up randomly after about more than 50 taps at least, sometimes more sometimes less, sometimes it doesn't even cause an error,
So i read the apple documentation and decided to convert to ima4 .caf extention.
I'm not sure if its made a difference, It happens much less often. I've got 2 more audio files that are played through SKActions and none of them have yet failed loading.
Any suggestions?
Debug console output below:
2014-07-05 16:14:15.716 GoUp[777:60b] *** Terminating app due to uncaught exception
'Failed to Load Resource', reason: 'Resource tap.caf can not be loaded'
*** First throw call stack:
(0x306d7fd3 0x3ae86ccf 0x306d7f15 0x32e09e55 0x32dc2b2d 0xf9331 0x32de69ab 0x32f28651
0x32f236eb 0x32ef88ed 0x32ef6f97 0x306a325b 0x306a272b 0x306a0f1f 0x3060bf0f 0x3060bcf3
0x35510663 0x32f5716d 0xfcd61 0x3b393ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Just to add, I tried to check if the file was faulty by setting a repeatforever waitforcomplete:YES SKAction playing the sound file, (i did wait for it to complete each time otherwise, it may have crashed due to significant number of actions). It ran without problem for at least 5 mins, until i decided to stop the app. Not sure if this confirms the file is not damaged
EDIT 2 : Just tried a different sound file and it happened again with a different file :(

I have no explanation about why that "crash" occurs,
but, you can easily solve this problem by declaring and loading your sounds into cash (to avoid to load it each time the sound is played) as follow:
In the .h
#property (strong, nonatomic) SKAction *aSound;
in the .m
Ignit it on the top:
self.aSound = [SKAction playSoundFileNamed:#"FileName.wav" waitForCompletion:NO];
En then call it each time you want to play the sound:
[self runAction:_aSound];
Also and for some reasons,
I advice you to convert all your Audios files into .Wav, which is uncompressed (allowing much more speed from the Processor that hasn't uncompressed the file before to read it)
It also dodge a lot of exceptions in C picked-up from the Breakpoint of Xcode.

Related

MPMoviePlayerController crashing and not playing movie

I am trying to play a movie using MPMoviePlayerController. When I call play method, i am getting following crash.
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MPAVController 0x15786750> for the key path "currentItem" from <MPAVPlaylistManager 0x15787750> because it is not registered as an observer.'
*** First throw call stack:
(0x2f148ed3 0x391716c7 0x2f148e15 0x2fa7227f 0x2fa71ca7 0x30393977 0x3038d5ef 0x303889d5 0x3036a36b 0x3036c6bb 0x2f10ae79 0x2f07eb81 0x2fa463c5 0x2fa4acc7 0x303ef943 0x39672103 0x396720ef 0x396749a9 0x2f1135b9 0x2f111e85 0x2f07c541 0x2f07c323 0x33b10343 0x316957b5 0x3a719 0x3a6a0)
libc++abi.dylib: terminating with uncaught exception of type NSException
I am not sure whats happening, as I dont have setup any KVO observer for currentItem from MPAVPlaylistManager which is an internal class.
anybody else got this issue?
Your app is massing with MPMoviePlayerController instance that was created. I had the same issue a while back and As far as i can think of there can be two things 1. You are changing contentURL of the instance that you have created while playing a video 2.you are incorrectly releasing the instance of MPMoviePlayerController.
I resolved the issue, the problem was related to iOS7 (that is under NDA at the moment). AVPlayer behaviour is changed if the player is started from a secondary thread. the player object will be nil. fixed my issue.

GPUImageMovieWriter starting new recording

Can i reuse an existing GPUImageMovieWriter (after calling finishRecording) or is there a method to pause and resume the recording?
I get error if i call startRecoding after a finishRecording.
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '*** -[AVAssetWriter addInput:] Cannot call method when status is 2'
You can't call startRecording() on the same movieWriter instance after calling finishRecording().
finishRecording() writes the completion block for the video into file, thus all subsequent frames added to the video file would be useless anyway. If what you want to achieve is to pause recording for a bit and append video at the end again after pausing, you should probably create a "pause" state where you don't record, but simply measure the amount of time paused, and then use an adjusted frame time for when you resume recording again.
Cheers!
Vijay

Cocos2d: nasty exception with batched sprites

I can't quiet figure how to debug this. I have a CCScene running and when the scene is replaced I get the following error message.
The scene has a sprite batch node where the CCSpriteSubclass is added.
That's the cleanup method and below that you will find the assertion failure message:
-(void) cleanup
{
[[GameController sharedGameController].musicLayer removeMusicSourceForKey:backgroundMusicFileName];
[CCTextureCache purgeSharedTextureCache];
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCAnimationCache purgeSharedAnimationCache];
// [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[super cleanup];
}
The batch node is created as following in the initWithId:(int)sceneId method:
//Prepare sprites sheets for the rest of the game art
[frameCache addSpriteFramesWithFile:[NSString stringWithFormat:#"art%i-hd.plist", sceneId]];
sharedSpriteMainBatchNode = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:#"art%i-hd.png", sceneId]];
And then I add all CCSpriteSubclass objects.
That's the assertion failure message:
** Assertion failure in -[CCSpriteSubclass setTexture:], /Users/xxx/Desktop/xxx/xxx/libs/cocos2d/CCSprite.m:934
2012-12-03 12:54:33.335 RockTale[869:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: Batched sprites should use the same texture as the batchnode'
*** First throw call stack:
(0x338d28bf 0x303c61e5 0x338d27b9 0x311193b3 0x9ad43 0x9a2fb 0x4bca3 0x44ddf 0x38b07 0x503f7 0x94c03 0xbbeed 0xbcfe7 0x34fb7423 0x34fb7379 0x31b4cf93 0x36e52891 0x3389bf43 0x338a6553 0x338a64f5 0x338a5343 0x338284dd 0x338283a5 0x37f9afcd 0x3128b743 0x2edf 0x2ea0)
terminate called throwing an exception(lldb)
EDIT: Added a breakpoint to the setTexture method and here is what I "DON't" see :)
EDIT 2: I whish I could manage to retrieve the full stacktrace like in Java.. I have asked this in a different question and I was told I should add a global exception.. I still need to figure out how to retrieve the stacktrace..
From the text of your exception message it seems that you create sprites with spriteframes from different spritesheets.
I solved this problem in the same way as here. It was due to the fact that sprite frames where referred while the previous class was replacing the existing one and hence the previous class cleanup method was calling the purge frame cache which was consequently removing the yet unused sprite frames which where being loaded in memory by the newly created object.

Unity iOS game crashing with NSInternalInconsistencyException

I am using Prime31's GameCenter Turn Based plugin in my game in order to handle online matches. A problem arises when I receive an "invitation to play" notification from Game Center while Game Center's matchmaker is showing (called using the plug-in => GameCenterTurnBasedBinding.findMatch(2,2,false); ).
The app crashes and the following output is shown in Xcode:
2012-08-20 08:39:27.050 Cabrais[1808:707] *** Assertion failure in -[NSIndexPath row], /SourceCache/UIKit/UIKit-1914.85/UITableViewSupport.m:2606
2012-08-20 08:39:27.052 Cabrais[1808:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.'
*** First throw call stack:
(0x355ec88f 0x33210259 0x355ec789 0x349e03a3 0x32d4d673 0x35dba49d 0x35dd90e5 0x35dd9379 0x32d4cefb 0x32d4bfd9 0x32d4b763 0x35da7657 0x32ceff37 0x3554b1fb 0x32716aa5 0x327166bd 0x327165c9 0x35dd8179 0x35da936b 0x35dbce65 0x35dbb6b3 0x33979c59 0x33984e91 0x355bf2ad 0x355424a5 0x3554236d 0x332dd439 0x32d1acd5 0x6954 0x3388)
terminate called throwing an exception(lldb)
I have tried disabling notifications through the Ipad/Iphone settings for both my app and GameCenter as well as through the code by removing all notification related code but this hasn't had any effect at all.
I know through debugging that the code in my function attached to GameCenterTurnBasedManager.handleTurnEventEvent doesn't get called before the crash occurs, and neither does the one registered to EtceteraManager.remoteNotificationReceived. (Both these function work perfectly fine otherwise.)
I have asked Prime31 and they have told me that the exception is a mishandling of the tables data source, and to file a bug report with Apple.
Has anyone experienced a similar crash/error while working with Unity?
And is there any way I can try to catch the notification before it arrives and remove the matchmaker or be able to handle the error from unity?
Any insight/help/comments would be greatly appreciated,
Thanks.

XCode4 Debugger Always Breaks in Main

After upgrading to XCode4 (v. 4.2, 4D199) it seems every time my apps crash while debugging, the debugging points to main(), and the stack is unsymbolicated and useless.
This has been working fine for years, I have no idea what has gone wrong.
I'm using GDB. I also tried the LLDB as per this advice, and it didn't work either (similar, useless stack).
My breakpoints work, I get the full stack, and can inspect variables when my code hits those.
Steps to reproduce:
NB. this happens with my own project, but I'll use Apple's code here to remove that variable from the equation
Download the following sample from Apple: https://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007710
In the ImagesViewController class, add the following code to the viewDidLoad method (so it will crash – we want it to crash for this test):
// please note: this code is designed to crash! I want it to crash, to highlight my issue with XCode.
NSMutableArray* test = [NSMutableArray new];
[test insertObject:NULL atIndex:0];
Then run the app & hit the 'Images' row.
It crashes with a message like:
2011-12-23 14:07:02.788 UICatalog[13394:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x37bbb8bf 0x316a11e5 0x37b1020f 0x699f 0x34fac7ff 0x34fb8c39 0x34fb8aa9 0x34fb898f 0x34fb815b 0x34fb7f53 0x34fac673 0x34fac349 0x66c1 0x35026565 0x3509ece7 0x31aec943 0x37b8fa63 0x37b8f6c9 0x37b8e29f 0x37b114dd 0x37b113a5 0x3768ffcd 0x34fa1743 0x2459 0x2418)
terminate called throwing an exception(gdb)
View in xcode:
Thanks to brigadir for pointing me to the solution!
It works well. Here's some screenshots for how to solve this for anyone finding my question:
Tap the plus button of the breakpoints tab
Then click Done

Resources