xcode: Thread 1: Signal SIGABART in class AppDelegate: UIResponder, UIApplicationDelegate (game application) - ios

Before marking as duplicate, please consider that I have searched the web and StackOverflow but I didn't find any solution for this specific problem (because all questions about this error are for apps, not games).
I am making a very basic Space Shooter game and I reached a stage where I want to make the hero (code below) shoot bullets; I created a function spawn_bullet to do this. After I wrote this function and called it in the function:
override func update(currentTime: CFTimeInterval),
I get the error: Thread 1: signal SIGABRT. Image is shown below
I believe that the error has something to do with the execution of the spawn_bullet function but I am not sure where it is, why it caused and how to fix it. Anyone has an idea to fix it and if possible to provide enough details for why it causes?
Thank you!
NOTE
English is not my first language (that's why it's bad)
Below I provide my code used in GameScene.swift:
import SpriteKit
class GameScene: SKScene {
var hero = SKSpriteNode(imageNamed: "hero")
var bullet = SKSpriteNode(imageNamed: "bullet")
var enemy = SKSpriteNode(imageNamed: "enemy")
var init_bullet_position = CGFloat(0)
var bullet_velocityY = CGFloat(5)
override func didMoveToView(view: SKView) {
/* Setup your scene here */
self.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.8, alpha: 1)
self.hero.anchorPoint = CGPointMake(0.5, 0)
self.hero.size.height = 50
self.hero.size.width = 30
self.hero.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinX(self.frame) + self.hero.size.height)
self.bullet.anchorPoint = CGPointMake(0.5, 0)
self.bullet.size.height = 30
self.bullet.size.width = 15
self.bullet.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinX(self.frame) + self.hero.size.height + self.hero.size.height / 4)
self.init_bullet_position = CGFloat(CGRectGetMinX(self.frame) + self.hero.size.height + self.hero.size.height / 4)
self.hero.zPosition = 1; //1 = front
self.addChild(bullet)
self.addChild(hero)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode!(self)
hero.position.x = location.x
if self.bullet.position.y == init_bullet_position{
self.bullet.position.x = location.x
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode!(self)
self.hero.position.x = location.x
if self.bullet.position.y == init_bullet_position{
self.bullet.position.x = location.x
}
}
}
func spawn_bullets(){
self.bullet.anchorPoint = CGPointMake(0.5, 0)
self.bullet.size.height = 30
self.bullet.size.width = 15
self.bullet.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinX(self.frame) + self.hero.size.height + self.hero.size.height / 4)
self.addChild(bullet)
if self.bullet.position.y < self.frame.size.height{
self.bullet.position.y += self.bullet_velocityY
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
spawn_bullets()
}
}
Here is the exception message:
2016-07-14 23:07:54.564 Space shooter[14391:191912] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attemped to add a SKNode which already has a parent: <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'bullet' (400 x 600)] position:{160, 62.5} scale:{1.00, 1.00} size:{15, 30} anchor:{0.5, 0} rotation:0.00'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ec4fd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000111299deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ec4fcbd +[NSException raise:format:] + 205
3 SpriteKit 0x000000010fb74903 -[SKNode insertChild:atIndex:] + 162
4 SpriteKit 0x000000010fb74840 -[SKNode addChild:] + 68
5 Space shooter 0x000000010ea62d23 _TFC13Space_shooter9GameScene13spawn_bulletsfT_T_ + 995
6 Space shooter 0x000000010ea62ef4 _TFC13Space_shooter9GameScene6updatefSdT_ + 36
7 Space shooter 0x000000010ea62f2c _TToFC13Space_shooter9GameScene6updatefSdT_ + 44
8 SpriteKit 0x000000010fb48072 -[SKScene _update:] + 312
9 SpriteKit 0x000000010fb6503a -[SKView _update:] + 932
10 SpriteKit 0x000000010fb6221a __59-[SKView _renderSynchronouslyForTime:preRender:postRender:]_block_invoke + 170
11 SpriteKit 0x000000010fb620e8 -[SKView _renderSynchronouslyForTime:preRender:postRender:] + 235
12 SpriteKit 0x000000010fb64ac2 -[SKView layoutSubviews] + 85
13 UIKit 0x000000010fdd8980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
14 QuartzCore 0x00000001151d7c00 -[CALayer layoutSublayers] + 146
15 QuartzCore 0x00000001151cc08e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
16 QuartzCore 0x00000001151cbf0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
17 QuartzCore 0x00000001151c03c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
18 QuartzCore 0x00000001151ee086 _ZN2CA11Transaction6commitEv + 486
19 QuartzCore 0x00000001151ee7f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
20 CoreFoundation 0x000000010eb74c37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
21 CoreFoundation 0x000000010eb74ba7 __CFRunLoopDoObservers + 391
22 CoreFoundation 0x000000010eb6a11c CFRunLoopRunSpecific + 524
23 UIKit 0x000000010fd18f21 -[UIApplication _run] + 402
24 UIKit 0x000000010fd1df09 UIApplicationMain + 171
25 Space shooter 0x000000010ea64e82 main + 114
26 libdyld.dylib 0x0000000111dc792d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

It occurs on this line:
self.addChild(bullet)
This is because bullet already has a parent.
To fix it, add this line before you add the child:
bullet.removeFromParent()

To answer the stated question:
Here's your error:
Attemped to add a SKNode which already has a parent
The problem is in your spawn_bullets() function. You're not actually instantiating new bullets in this function. You're just updating properties on self's instance of bullet, then trying to add it as a child of your scene. The second time this function is called, it crashes, because the bullet is already a child of the scene.
Instead, you should create new instances of your bullet node.
Regarding the underlying problem of creating unique bullets:
This is a whole separate topic in and of itself. I assume you only want to fire bullets at specific times, such as when you tap on something, so rather than spawning bullets from the update() function, which is called before each frame is rendered, I would call spawn_bullets() from a tap method, or other interaction. Secondly, you will want to create new instances of your bullet instead of updating a variable on your scene. These can be added, animated, and subsequently removed. Finally, take a look at the SKAction class for actually animating (and ultimately removing) the bullets. For example:
let newBullet = SKSpriteNode(imageNamed: "bullet")
newBullet.position = CGPoint(x: 10, y: 10)
self.addChild(newBullet)
let moveAction = SKAction.moveTo(CGPoint(x: 50, y: 10), duration: 0.4)
let removeAction = SKAction.removeFromParent()
newBullet.runAction(SKAction.sequence([moveAction, removeAction])) {
// Bullet is done and removed.
}
You can do a lot more with SKAction than is shown here. You can play audio files, follow paths, or even simply run a block.

Related

AudioKit crash: required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode

We are experiencing an exception in our project:
2019-08-08 10:18:28.703708-0600 AppName[99385:5069475] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ee2e8db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010e21bac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010ee2e662 +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x0000000111b94dbc _Z19AVAE_RaiseExceptionP8NSStringz + 156
4 AVFAudio 0x0000000111bf3937 _Z11_AVAE_CheckPKciS0_S0_b + 295
5 AVFAudio 0x0000000111b8cb8f _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 1031
6 AVFAudio 0x0000000111bfb598 _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 194
7 AVFAudio 0x0000000111bfb5ff -[AVAudioEngine connect:to:format:] + 83
8 AppName 0x000000010a424c10 $s8AudioKitAAC6outputAA6AKNodeCSgvWZTf4dd_n + 2576
9 AppName 0x000000010a4230fd $s8AudioKitAAC6outputAA6AKNodeCSgvsZ + 93
10 AppName 0x000000010a2ba3a3 $s6AppName7MaestroC17setUpTrackPlayers7fileURLy10Foundation0H0V_tF + 1235
Examining the common gotchas video I see a similar exception being thrown, required condition is false: !nodeMixerConns.empty() && !hasDirectConnToIONode, which is caused by allowing the variables to go out of scope rather than be retained in the class.
So this occurs when we create an AKPlayer, which is retained in a class, then we create an AKTimePitch with this player which is also retained in that class, and finally assign that to AudioKit.output which triggers the exception. After that we were storing the class that holds onto the player and time pitch in an array, so I tried to move this up after it's created in hopes that was the issue, but I see the same exception.
Interestingly, this code works fine initially when we load up the first song but crashes when we hit the next button to load up the next song.
final class Maestro : NSObject {
static let shared = Maestro()
var audioPlayers = [TrackPlayer]()
func setUpTrackPlayers(fileURL: URL) {
let playerOne = TrackPlayer(url: fileURL)
audioPlayers.append(playerOne)
AudioKit.output = playerOne.handleMixerChain() //boom
do {
try AudioKit.start()
} catch {
print("Maestro AudioKit.start error: \(error)")
}
}
func next() {
for player in audioPlayers {
player.stop()
}
audioPlayers.removeAll()
setUpTrackPlayers(fileURL: newSong.getFileUrl())
}
}
final class TrackPlayer {
let player : AKPlayer
lazy var timePitch = AKTimePitch()
init(url: URL) {
player = AKPlayer(url: url)!
}
func handleMixerChain(pitch: Double = 0.0, tempo: Double = 1.0) -> AKTimePitch {
timePitch = AKTimePitch(player)
timePitch.pitch = pitch
timePitch.rate = tempo
return timePitch
}
}
Any ideas? If you need any more info let me know. May be good to note we are updating from AudioKit 4.5.5 where we didn't experience this crash.
I've opened the project and it seems like you're being a bit too relaxed about your set up / tear down of the signal chain. You're setting up AudioKit's output using local variables, never tearing down this signal chain, and then coming back resetting the AudioKit output and telling AudioKit to start without ever calling AudioKit.stop().

Removing SCNNode nodes from scene.rootNode is causing a crash, in SceneKit

I am trying to remove set of nodes from my scene which represent a path. They are a combination of SCNSphere geometry nodes, and custom geometry representing lines, created using SCNGeometrySource and SCNGeometryElement.
I am not retaining these nodes in any kind of array. Instead, I search the first level of the node tree of the rootNode in the scene for these nodes, by their name, and the subsequent call an action sequence that makes them fade out, and they should remove themselves from the root node.
The code is as follows:
func clearPath() {
//
let disappear = SCNAction.fadeOut(duration: 0.1)
let remove = SCNAction.removeFromParentNode()
let sequence = SCNAction.sequence([disappear, remove])
if let pathNodesToRemove = pathNodes() {
//
for node in pathNodesToRemove {
//
node.removeAllActions()
node.runAction(sequence)
}
}
if let lineNodesToRemove = lineNodes() {
for node in lineNodesToRemove {
//
node.removeAllActions()
node.runAction(sequence)
}
}
path.removeAll()
}
where:
func pathNodes() -> [SCNNode]? {
//
...
let nodes = rootNode.childNodes.filter { (node) -> Bool in
//
guard let name = node.name else { return false }
if name.hasPrefix(configurationComponent.id) &&
name.range(of:"_PATH") != nil {
return true
} else {
return false
}
}
return nodes
}
The lineNodes() function is basically the same.
I switched on Zombie Objects to trace where the error is coming from, and I always get the same error: a reference to SceneKit`C3DNodeRemoveFromParentNode as the last thing to call on the thread, and a EXC_BAD_ACCESS (code=1, address... ).
The clearPath() function is the only place in the entire app that I am calling 'RemoveFromParentNode'.
The nodes don't have physics bodies on them and are not being retained anywhere elsewhere.
Any thoughts as to how to resolve this?
EDIT 28/4/18:
Here is a crash report of the thread where it occurs. It would appear that removeObjectFromChildNodesAtIndex is being called twice...
Thread 9 name: Dispatch queue: com.apple.scenekit.renderingQueue.Air_Relay.ARTCSCNView0x104126720
Thread 9 Crashed:
0 SceneKit 0x00000001957d668c C3DNodeRemoveFromParentNode + 40
1 SceneKit 0x0000000195826e28 -[SCNNode __removeObjectFromChildNodesAtIndex:] + 184
2 SceneKit 0x0000000195826e28 -[SCNNode __removeObjectFromChildNodesAtIndex:] + 184
3 SceneKit 0x0000000195827350 -[SCNNode removeFromParentNode] + 396
4 SceneKit 0x000000019593e9fc -[SCNActionRemove updateWithTarget:forTime:] + 92
5 SceneKit 0x0000000195907cb8 SCNCActionSequence::cpp_updateWithTargetForTime+ 2202808 (SCNNode*, double) + 316
6 SceneKit 0x00000001957bcfb0 SCNActionApply + 112
7 SceneKit 0x0000000195853d2c _applyActions + 236
8 CoreFoundation 0x00000001814dccbc __CFDictionaryApplyFunction_block_invoke + 24
9 CoreFoundation 0x00000001814c3f98 CFBasicHashApply + 132
10 CoreFoundation 0x00000001814cdb64 CFDictionaryApplyFunction + 288
11 SceneKit 0x0000000195853b5c C3DAnimationManagerApplyActions + 92
12 SceneKit 0x000000019583b054 -[SCNRenderer _update:] + 656
13 SceneKit 0x000000019583d018 -[SCNRenderer _drawSceneWithNewRenderer:] + 252
14 SceneKit 0x000000019583d69c -[SCNRenderer _drawScene:] + 84
15 SceneKit 0x000000019583daa0 -[SCNRenderer _drawAtTime:] + 728
16 SceneKit 0x00000001958e446c -[SCNView _drawAtTime:] + 512
EDIT 30/04/18
I continued to add other features to the app, where I needed to remove nodes using SCNAction.removeFromParentNode(). I isolated those as well to cause the problem independently of the above code.
These are called more frequently on the SCNRendererDelegate update as each new nodes are generated.
I also tried to use removeFromParentNode() directly on the node using SCNAction.run block, and the same issue occurs.
When you use SCNAction.removeFromParentNode() you aren't removing the node, you have to remove the node it's self. If you remove the path or action you are essentially make a value nil so when the path or action is called there is now a nil value and it crashes.

Watch app starts with error clientIdentifier for interfaceControllerID not found

I'm having a smartwatch app on watchos2. The app always worked but now when it starts I immediately get this error:
Lop_WatchKit_Extension[17535:7854201] *********** ERROR -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] clientIdentifier for interfaceControllerID:447E0002 not found
I found some topics here on stackoverflow but nothing solved the problem.
In my case, this was due to a retain cycle in one InterfaceController of mine.
If you get the logs similar to:
[default] -[SPRemoteInterface
_interfaceControllerClientIDForControllerID:]:0000: ComF: clientIdentifier for interfaceControllerID:XXXXXXXX not found
&/or...
[default] _SendRecordedValues:000: ComF:<-Plugin controller ID
XXXXXXXX has no client identifier
First, figure out which InterfaceController has the controller ID XXXXXXXX.
Have this in awake(withContext:)
override func awake(withContext context: Any?) {
//...
if let id = self.value(forKey: "_viewControllerID") as? NSString {
let strClassDescription = String(describing: self)
print("\(strClassDescription) has the Interface Controller ID \(id)")
}
//...
}
This logs:
[Target.Classname: 0xYYYYYYYY] has the Interface Controller ID
XXXXXXXX
Once you identify the InterfaceController causing these logs, you can continue to debug.
It could be different in your case but in mine I had created a retain cycle with self in one of my closures within which took awhile to locate but I eventually broke the retain cycle with a [weak self] capture.
Basically, the error logs appear when an InterfaceController is trying to execute some code but it has already been released.
What I already had:
DispatchQueue.main.async {
self.doSomethingThatDoesSomethingAsync()
}
What I fixed:
DispatchQueue.main.async { [weak self] in
self?.doSomethingThatDoesSomethingAsync()
}
If you use didSet on any IBOutlets it will also throw this error in the logs.
class MyInterfaceController: WKInterfaceController {
#IBOutlet var myLabel: WKInterfaceLabel! {
didSet {
myLabel.setTitle("Test")
}
}
How #nickromano sad, it's happens when you use didSet with IBOutlets. Cause it's calls before awake(withContext context: Any?)
We can suppress this error if wrap it in DispatchQueue.main.async
#IBOutlet var statusLabel: WKInterfaceLabel! {
didSet {
DispatchQueue.main.async {
self.statusLabel.setHidden(true)
}
}
This has happened to me a few times and more times than not, it is because of a timer that is still firing in a just-previously dismissed WKInterfaceController that I did not catch.
Best thing to do aside from comparing ID's like in #staticVoidMan's answer is to read the call stack. In my case I was able to identify that the old timer was still firing based off these hints:
8 Foundation 0x00007fff214be867 __NSFireTimer + 67
9 CoreFoundation 0x00007fff207a8e3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
10 CoreFoundation 0x00007fff207a8912 __CFRunLoopDoTimer + 926
Here is the original call stack (for reference):
<MyApp.InterfaceController: 0x7fb3e4d2d020> has the Interface Controller ID 1EB00002
2021-05-26 14:44:06.632758-0600 MyApp WatchKit Extension[73392:3546879] [default] -[SPRemoteInterface _interfaceControllerClientIDForControllerID:]:2464: ComF: clientIdentifier for interfaceControllerID:1EB00007 not found. callStack:(
0 WatchKit 0x00007fff38d1a268 -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] + 220
1 WatchKit 0x00007fff38d1bfff __54+[SPRemoteInterface setController:key:property:value:]_block_invoke + 340
2 WatchKit 0x00007fff38d12323 spUtils_dispatchAsyncToMainThread + 30
3 WatchKit 0x00007fff38d1be60 +[SPRemoteInterface setController:key:property:value:] + 179
4 WatchKit 0x00007fff38d057af -[WKInterfaceObject _sendValueChanged:forProperty:] + 706
5 WatchKit 0x00007fff38d2a5f8 -[WKInterfaceObject _setImage:forProperty:] + 50
6 MyApp WatchKit Extension 0x000000010955531d $s26MyApp_WatchKit_Extension25ActivityIndicatorDelegateC06handleE5TimeryyF + 813
7 MyApp WatchKit Extension 0x000000010955537a $s26MyApp_WatchKit_Extension25ActivityIndicatorDelegateC06handleE5TimeryyFTo + 42
8 Foundation 0x00007fff214be867 __NSFireTimer + 67
9 CoreFoundation 0x00007fff207a8e3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
10 CoreFoundation 0x00007fff207a8912 __CFRunLoopDoTimer + 926
11 CoreFoundation 0x00007fff207a7ec5 __CFRunLoopDoTimers + 265
12 CoreFoundation 0x00007fff207a2546 __CFRunLoopRun + 1949
13 CoreFoundation 0x00007fff207a18be CFRunLoopRunSpecific + 567
14 GraphicsServices 0x00007fff25b49fd3 GSEventRunModal + 139
15 UIKitCore 0x00007fff43290f24 -[UIApplication _run] + 917
16 UIKitCore 0x00007fff43295c0b UIApplicationMain + 101
17 WatchKit 0x00007fff38d0de65 WKExtensionMain + 800
18 libdyld.dylib 0x00007fff20202db5 start + 1
19 ??? 0x0000000000000001 0x0 + 1
)
Have you changed the name of your module? If this is the case then you have to go through your storyboard and update it manually for all the Interfaces you have.
Edit with steps to fix:
Go to the storyboard and for each interface open the Identity inspector, then delete what's in Module and press enter, the new module should get auto-filled.

Swift 2 - Sigabrt Error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm creating a countdown timer for a game but I'm getting the SIGABRT error. I am coding in Swift 2. It countdowns from 45 seconds then has two other labels, one that is 5 seconds less, and the other 10 seconds less. The app opens up successfully in the simulator. Once I click on the screen then it crashes. I tried removing all the ties between the buttons/labels on the Storyboard to the ViewController.swift. Then, I re-"attached" them. The button has no text and is above everything. So, no matter where you tap on the screen, it will either start or reset. Once the button is clicked the NSTimer starts. Once the button is clicked again it resets the timer so its ready for the next time.
ViewController Code:
//
// ViewController.swift
// CS:GO C4 Timer
//
// Created by Panja on 11/14/15.
// Copyright © 2015 Panja. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var Main:Int = 0
var Kit:Int = 0
var NoKit:Int = 0
#IBOutlet weak var MainTime: UILabel!
#IBOutlet weak var DiffuseKit: UILabel!
#IBOutlet weak var NoDiffuseKit: UILabel!
var TimerCount = 0;
var TimerRunning = false;
var Timer = NSTimer();
var Toggle = false;
func Countdown(){
//Time Left Before Bomb Explodes
TimerCount = 45;
TimerCount -= 1
if(TimerCount <= 0){
MainTime.text = "No Time"
}else{
MainTime.text = "\(TimerCount)"
Main = TimerCount
}
//Time Left To Diffuse With A Kit
Kit = Main - 5
if(Kit <= 0){
DiffuseKit.text = "No Time"
}else{
DiffuseKit.text = "\(Kit)"
}
//Time Left To Diffuse Without A Kit
NoKit = Main - 10
if(NoKit <= 0){
NoDiffuseKit.text = "No Time"
}else{
NoDiffuseKit.text = "\(NoKit)"
}
}
#IBAction func ToggleButton(sender: AnyObject) {
//If The Button Is At Its Default at 45 Seconds & Not Running
if(Toggle == false){
if TimerRunning == false{
Timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true)
TimerRunning = true;
Toggle = true;
}
//If Timer is Running & Needs To Be Stopped
}else if (Toggle == true){
if TimerRunning == true{
Timer.invalidate()
TimerRunning = false
TimerCount = 45;
MainTime.text = "45"
Toggle = false;
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Error From Debug Console:
2015-11-15 12:20:54.288 CS:GO C4 Timer[32688:6460757] -[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00
2015-11-15 12:20:54.323 CS:GO C4 Timer[32688:6460757] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00'
*** First throw call stack:
(
0 CoreFoundation 0x00000001080849b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109c83deb objc_exception_throw + 48
2 CoreFoundation 0x000000010808cfdd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107fda9fa ___forwarding___ + 970
4 CoreFoundation 0x0000000107fda5a8 _CF_forwarding_prep_0 + 120
5 Foundation 0x000000010846b6f1 __NSFireTimer + 83
6 CoreFoundation 0x0000000107fe4de4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x0000000107fe4991 __CFRunLoopDoTimer + 1089
8 CoreFoundation 0x0000000107fa6331 __CFRunLoopRun + 1937
9 CoreFoundation 0x0000000107fa5918 CFRunLoopRunSpecific + 488
10 GraphicsServices 0x000000010c5ccad2 GSEventRunModal + 161
11 UIKit 0x00000001088a199e UIApplicationMain + 171
12 CS:GO C4 Timer 0x0000000107ea218d main + 109
13 libdyld.dylib 0x000000010a7de92d start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Main.Storyboard
Image of The Main Storyboard
Thread 1 - 12 Main
Picture of the Thread 1 file that shows when the application crashes
The problem is that Counting and Countdown are two different words.

Why my [UIScrollView removeFromSuperview] is crashing?

The crash log is below.
Do you know any particular reason why might [UIScrollView removeFromSuperview] can crash? The scrollview contains view hierarchy with different types of UIViews. I also finds that the ad hoc version crash often not the debug version. I could not find any reason for that.
Same viewcontroller is loaded in a different flow in iPhone that works fine. But in iPad it crashes.
In iPad, in a container view controller, only viewcontroler.view is loaded.
Incident Identifier: EE102239-34D1-4BE7-8B52-41F74AB26203
CrashReporter Key: 2b11ea2a01ac5618e199ffc5a1e1f321600bb6a9
Hardware Model: iPad3,4
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2013-06-18 15:19:16.132 +0200
OS Version: iOS 6.1.3 (10B329)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3bab7070 prepareForMethodLookup + 20
1 libobjc.A.dylib 0x3bab6fb2 lookUpMethod + 42
2 libobjc.A.dylib 0x3bab6f7e _class_lookupMethodAndLoadCache3 + 14
3 libobjc.A.dylib 0x3bab6638 objc_msgSend_uncached + 24
4 QuartzCore 0x357f2a72 CA::Layer::contents_visibility_changed(CA::Transaction*, bool) + 50
5 QuartzCore 0x357f29de CA::Layer::mark_visible(CA::Transaction*, bool) + 190
6 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
7 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
8 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
9 QuartzCore 0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
10 QuartzCore 0x357f28d2 CA::Layer::update_removed_sublayer(CA::Transaction*, unsigned int) + 18
11 QuartzCore 0x357f255a CA::Layer::remove_sublayer(CA::Transaction*, CALayer*) + 130
12 QuartzCore 0x357f246a CA::Layer::remove_from_superlayer() + 34
13 UIKit 0x35a6e92c -[UIView(Hierarchy) removeFromSuperview] + 144
14 UIKit 0x35b857bc -[UIScrollView removeFromSuperview] + 60
15 MyApp 0x000bde8a -[iPadNavigationController vcAnimationDone] (iPadNavigationController.m:400)
16 UIKit 0x35a55ab6 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 154
17 UIKit 0x35aca8f8 -[UIViewAnimationState animationDidStop:finished:] + 44
18 QuartzCore 0x35801304 CA::Layer::run_animation_callbacks(void*) + 204
19 libdispatch.dylib 0x3bed55d8 _dispatch_client_callout + 20
20 libdispatch.dylib 0x3bed8e40 _dispatch_main_queue_callback_4CF + 224
21 CoreFoundation 0x33c051ac __CFRunLoopRun + 1284
22 CoreFoundation 0x33b78238 CFRunLoopRunSpecific + 352
23 CoreFoundation 0x33b780c4 CFRunLoopRunInMode + 100
24 GraphicsServices 0x37733336 GSEventRunModal + 70
25 UIKit 0x35a942b4 UIApplicationMain + 1116
A few line from the code (as asked),
previous = showing;
showing = [ vc retain ];
showing.view.frame = startFrameIn;
[ container addSubview:showing.view ];
CGContextRef context = UIGraphicsGetCurrentContext();
[ UIView beginAnimations:nil context:context ];
[ UIView setAnimationDelegate:self ];
[ UIView setAnimationDidStopSelector:#selector(vcAnimationDone) ];
[ UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
[ UIView setAnimationDuration:0.4 ];
previous.view.frame = endFrameOut;
showing.view.frame = detailFrame;
[ UIView commitAnimations ];
}
- (void) vcAnimationDone {
if ( previous != nil ) {
if (previous.view.superview != nil) {
[previous.view removeFromSuperview];
}
[ previous release ];
previous = nil;
}
A very probable reason is that you are overreleasing your scrollview or one of the views inside it.
Calling removeFromSuperview then deallocates the view instead of simply decreasing the retain count.
Actually, if you are still stuck with non-ARC project, Static Code Analysis is very useful for this kind of bug. Retain/release balancing issues are hard to pin down, and nearly impossible with incomplete method so I suggest you post the full method body if possible.
Thanks everyone for your answers, tips and tricks. However one thing I want share with you is the cause of the crash. I found that the crash was at different thread in different times. I had several views loaded with button pressing/menu in my iPad app. Some of the button pressing fetch data from web service. So I was bit confused to get the cuase of crash, animation, or url connection etc... I tried with enabled NSZombie objects, but it did not show any information.
Then I tried with Guard Malloc. This only runs in Simulator. And magically I found the code point of crash. I have function to convert a hex string into data. There I have line of code to make a C string null terminated. where I assigned 0 at the last index. and that makes the crash!
tmpCh[count] = 0;
I do not why, but probably it takes some time in the memory management procedure in iOS so it crash at different thread at different times. But with Guard malloc in Simulator, it always point out here and when I rewrite the code, the crash is gone.
/* Converts a hex string to bytes.
Precondition:
. The hex string can be separated by space or not.
. the string length without space or 0x, must be even. 2 symbols for one byte/char
. sample input: 23 3A F1 OR 233AF1
*/
+ (NSData *) dataFromHexString:(NSString*)hexString
{
if (hexString.length < 1) {
return nil;
}
char * tmpCh = (char *) malloc([hexString length] * sizeof(char));
int count = 0;
for (int k=0; k<hexString.length;k++) {
char c = [hexString characterAtIndex:k];
if (c == (char)0x20) { //skip space
continue;
}
if (c == '0') { // skip 0x
if(k+1 < hexString.length){
if ([hexString characterAtIndex:k+1] == 'x'
|| [hexString characterAtIndex:k+1] == 'X' )
{
k = k + 1;
continue;
}
}
}
tmpCh[count] = c;
count++;
}
tmpCh[count] = 0; // make null terminated string
if (count % 2) {
return nil;
}
NSString *temp = [[NSString alloc] initWithUTF8String:tmpCh];
free(tmpCh);
if ([temp length] % 2 != 0) {
return nil;
}
NSMutableData *result = [[NSMutableData alloc] init];
unsigned char byte;
char hexChars[3] = {0};
for (int i=0; i < (temp.length/2); i++) {
hexChars[0] = [temp characterAtIndex:i*2];
hexChars[1] = [temp characterAtIndex:i*2+1];
if (![Util isValidChar:hexChars[0]] || ![Util isValidChar:hexChars[1]]) {
return nil;
}
byte = strtol(hexChars, NULL, 16);
[result appendBytes:&byte length:1];
}
NSData * data = [NSData dataWithData:result];
[result release];
return data;
}

Resources