Getting EXC_BAD_ACCESS when trying to call [UITableView panGestureRecognizer] - uitableview

Just upgraded xCode to 4.5. iOS 5 is still my deployment target, but Base SDK is now 6.0.
Application now crashes where previously it did not. The project uses ARC.
The offending line is a property call on a UITableView... asking for the panGestureRecognizer (line 3 below).
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIPanGestureRecognizer* pgr = [imageTableView panGestureRecognizer];
[pgr setMinimumNumberOfTouches:2];
[pgr setMaximumNumberOfTouches:2];
}
Produces the following error message:
-[UIScrollViewPanGestureRecognizer retain]: message sent to deallocated instance 0x1ea38f70
How is this possible? Zombie Analysis says that the gestureRecognizer has been released already?!

Turns out this was an ARC issue... two different solutions for those interested.
#autoreleasepool {
UIPanGestureRecognizer* pgr = [imageTableView panGestureRecognizer];
[pgr setMinimumNumberOfTouches:2];
[pgr setMaximumNumberOfTouches:2];
}
Or
[imageTableView.panGestureRecognizer setMinimumNumberOfTouches:2];
[imageTableView.panGestureRecognizer setMaximumNumberOfTouches:2];
Lesson learned, if it can't be possible.... try ARC as the culprit.

Related

returned nil from -traitCollection, which is not allowed in Xcode 11 Beta

Assertion failure in UITraitCollection * _Nonnull
returned nil from -traitCollection, which is not allowed?
when I try to run Xcode 11 beta in ios 13 it crashed. I don't know what was wrong.
[super init]
I ran across this problem because one of the unnamed previous coders on my codebase, whom I frequently curse, didn't call [super init] on a class that implements the UITraitEnvironment (aka UIView or UIViewController)!
If I could wield a battle hammer backwards five years in time, I would.
This implementation in a subclass of UIViewController…
- (id)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
_startPosition = startPosition;
_scrollViewHeight = scrollViewHeight;
self.isPdfView = YES;
return self;
}
was updated to…
- (instancetype)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
self = [super initWithNibName:nil bundle:nil];
_startPosition = startPosition;
_scrollViewHeight = scrollViewHeight;
_isPdfView = YES;
return self;
}
and resolved the crash I started receiving in Xcode 11 / iOS 13.
This is how iOS 13 and Xcode 11 deal with the main thread checker inconsistencies.
basically, you are updating the UI from a background thread. Just make sure you're updating all your UI in the main thread.
Simply wrap the code that updates your UI inside DispatchQueue.main.async { }.
Just simple put your code in main thread of UI update :
DispatchQueue.main.async
{
// Put your code here
}

UIWebView subclass causing malloc_zone_unregister() in XCode 7

I'm running my project in XCode 7 and I'm trying to hunt down some EXC_BAD_ACCESS KERN_INVALID_ADDRESS which my users on the AppStore are experiencing.
I'm running XCode 7 with Enable Address Sanitizer on. After the app starts and all the init is done I see these warnings int the console:
IKMS(1001,0x60081000) malloc: *** malloc_zone_unregister() failed for 0x1a8ad000
==1001==__asan_mz_destroy() called -- ignoring
IKMS(1001,0x60081000) malloc: *** malloc_zone_unregister() failed for 0x1a8b0000
==1001==__asan_mz_destroy() called -- ignoring
IKMS(1001,0x60081000) malloc: *** malloc_zone_unregister() failed for 0x1a8ab000
==1001==__asan_mz_destroy() called -- ignoring
After some debugging I found that this happens when during my initial allocation in the AppDelegate of the app, if I create a CustomWebview and set it's frame when the app becomes active this error appears.
This is the init function of the custom UIWebView:
- (id) init
{
if (self = [super init])
{
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.scalesPageToFit = YES;
self.userInteractionEnabled = NO;
self.delegate = self;
}
return self;
}
This is how I initialise it:
CustomUIWebView *custom = [[CustomUIWebView alloc] init];
custom.frame = CGRectMake(109/2, 220/2, 326/2, 326/2);
[anotherView addSubview:custom];
If I move this line:
custom.frame = CGRectMake(109/2, 220/2, 326/2, 326/2);
After the app becomes active the errors go away.
This of course is part of a bigger project and I fixed all errors like this but I still get these errors in the console. So basically I have these questions:
Are there any other views that behave like this?
Do you know by any chance why this error occurs? EXC_BAD_ACCESS
KERN_INVALID_ADDRESS Maybe besides memory overwrite and out of
memory?
Is there way to catch these errors when they happen rather than when
they crash the app? (The memory ones).
Do you know by any chance why this error occurs? EXC_BAD_ACCESS KERN_INVALID_ADDRESS Maybe besides memory overwrite and out of memory?
You should execute the designated initializer, when you step up from a subclass' initializer. The designated initializer for UIView and its subclass UIWebView is -initWithFrame:, not -init. To do so, you have to pass a frame rest to your initializer or to set a default one. So it should be (option 1):
- (id) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
…
}
return self;
}
…
CustomUIWebView *custom = [[CustomUIWebView alloc] initWithFrame:CGRectMake(109/2, 220/2, 326/2, 326/2)];
BTW: Do you know, that 109/2 is an integer division with the result 54, not 54.5?
Are there any other views that behave like this?
I do not know, whether views behaves exactly like this. But almost every view will need to know the frame at initialization.
Is there way to catch these errors when they happen rather than when they crash the app? (The memory ones).
I'm not sure, what you want to say. Maybe exception breakpoint?

unable to find cause of EXC_BAD_ACCESS on a iOS7.1 app

I'm building a small demo app with MQTTKit and Estimote iOS SDK that ranges the beacons and sends the beacons proximity uuid, major and minor to a MQTT broker.
The sample works fine for a while, but sometimes it crashes and I get a EXC_BAD_ACCESS (code=2, address=0x27c8eff4)) on Thread 1 - Queue:com.apple.main-thread. In XCode, while debugging I can see the following when the exception throws:
CoreFoundation`CFRelease:
0x2fdc9f54: push {r4, r5, r6, r7, lr}
That is where the exception occurs, but I have no clue what that represents nor what it means.
Could anyone point out what is that I am not retaining or releasing to early, because from what I have read is something among the lines of objects being released to early and trying to access them after being released?
EDIT: As per the comment's suggestions, I have enabled NSZombies and breakpoints on exceptions and now I get more info:
Pulsr(21312,0x3cb4118c) malloc: *** error for object 0x16f27404: incorrect checksum for freed object - object was probably modified after being freed. *** set a breakpoint in malloc_error_break to debug
And the line where it stops is at [UIView animateWith ...];:
dispatch_async(dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:0.250
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
weakSelf.streamingCountLabel.layer.backgroundColor = streaming ? weakSelf.yellowColor.CGColor : weakSelf.redColor.CGColor;
}
completion:nil];
if (!streaming)
{
weakSelf.streamingCountLabel.text = #"0";
}
});
First thing that comes to my mind is this part:
- (instancetype)init
{
self = [super init];
return [self initWithUUID:ESTIMOTE_PROXIMITY_UUID identifier:#"Pulsr"];
}
- (instancetype)initWithUUID:(NSUUID *)uuid identifier:(NSString *)identifier
{
self = [super init];
if (self) {
_manager = [[ESTBeaconManager alloc] init];
_region = [[ESTBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];
}
return self;
}
You are calling [super init] two times on one alloc. It might not be a problem but it's definitely wrong approach. In this case just remove [super init] from init method.

Strange EXC_BAD_ACCESS SpriteKit removeSubsprite crash

I am new to SpriteKit and just built my first game. Everything was working great until iOS 7.1. Now, after a few times of advancing to a new level and presenting a new Scene, it crashes. I don't think I am presenting it in an incorrect way:
ZSSMyScene *nextLevel = [[ZSSMyScene alloc] initWithSize:self.size level:self.level score:score];
[self.view presentScene:nextLevel];
I get a EXC_BAD_ACCESS error, and it looks like it is happening on removeSubsprite, but I can't find anywhere in my code that I would be removing a subsprite:
Not sure what other info to provide as this is just an obscure error that seemed to start when I updated to iOS 7.1 SDK.
This appears to be a bug, possibly only with SKShapeNodes.
My solution was to create an SKNode category and call this cleanup method when any node i'm removing has children.
- (void)cleanUpChildrenAndRemove {
for (SKNode *child in self.children) {
[child cleanUpChildrenAndRemove];
}
[self removeFromParent];
}

How can I keep my UIGestureRecognizers from crashing?

I'm having a really frustrating issue with UIGestureRecognizers. They get added fine, but whenever one gets triggered, it crashes with the message EXC_BAD_ACCESS (code=1, address=0xf0000008). I'm adding it in the view controller using the following code:
- (void)handleDrag:(UIGestureRecognizer *)sender {
NSLog(#"%#", sender);
}
- (void)viewDidLoad {
[super viewDidLoad];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handleDrag:)];
[self.windowBar addGestureRecognizer:panGesture];
}
self.windowBar is a UIImageView. I've enabled user interaction on said UIImageView. But whenever I start actually dragging it, it crashes.
I'm not sure if this has anything to do with it, but I'm using the new ARC feature.
What else am I missing? :(
Try running with the Zombies Instrument to detect exactly which zombie (already released) object is being referenced. It will point you to the exact object that the system thinks it should send a message to, but has already been released (with retain count set to 0, and the memory already reassigned).

Resources