Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Even more debug code for _scrollViewDidChangeBounds
Since SPTableView and SPCopyTable seem to be the cause behind the majority of crashes let's take a closer look at them.
  • Loading branch information
dmoagx committed Sep 14, 2015
1 parent 4707c32 commit aa192cf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Source/SPObjectAdditions.m
Expand Up @@ -30,6 +30,7 @@

#import <objc/runtime.h>
static NSMutableDictionary *gScrollViewListeners;
static NSMutableDictionary *gScrollViewDealloc;

@implementation NSObject (SPObjectAdditions)

Expand Down Expand Up @@ -97,7 +98,10 @@ - (void)_scrollViewDidChangeBounds:(id)obj

NSString *key = [NSString stringWithFormat:@"snd=%p,obs=%p",obj,self];

[msg appendFormat:@"registration info for pair (%@):\n %@",key,[gScrollViewListeners objectForKey:key]];
[msg appendFormat:@"registration info for pair (%@):\n %@\n\n",key,[gScrollViewListeners objectForKey:key]];

NSString *deallocKey = [NSString stringWithFormat:@"=%p",self];
[msg appendFormat:@"self %@ was originally dealloc'ed at:\n %@",deallocKey,[gScrollViewDealloc objectForKey:deallocKey]];

@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:msg userInfo:nil];
}
Expand Down Expand Up @@ -144,4 +148,41 @@ - (void)sp_addObserver:(id)notificationObserver selector:(SEL)notificationSelect
[self sp_addObserver:notificationObserver selector:notificationSelector name:notificationName object:notificationSender];
}

@end

#import "SPTableView.h"

@implementation SPTableView (SPScrollViewDebug)

+ (void)load
{
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
gScrollViewDealloc = [[NSMutableDictionary alloc] init];

Class tableView = [self class];

SEL orig = @selector(dealloc);
SEL exch = @selector(sp_dealloc);

Method origM = class_getInstanceMethod(tableView, orig);
Method exchM = class_getInstanceMethod(tableView, exch);

method_exchangeImplementations(origM, exchM);
});
}

- (void)sp_dealloc
{
NSString *key = [NSString stringWithFormat:@"=%p",self];
NSString *val = [NSString stringWithFormat:@"\ndealloc backtrace:\n%@\n\n",[NSThread callStackSymbols]];

[gScrollViewDealloc setObject:val forKey:key];

// not recursive! method is swizzled.
[self sp_dealloc];
}


@end
5 changes: 5 additions & 0 deletions Source/SPTableView.m
Expand Up @@ -61,6 +61,11 @@ - (id) init
return self;
}

- (void)dealloc
{
[super dealloc];
}

- (void) awakeFromNib
{
[super setDoubleAction:@selector(_doubleClickAction)];
Expand Down

0 comments on commit aa192cf

Please sign in to comment.