Application crash on -[__NSCFSet bytes]: unrecognized selector sent to instance ""? - iphone

I developing an application that application well worked for me my XCode version is 4.2.1 and iOS version is 5.0 ARC enable code. My process is i showing a bunch of YouTube videos in tableview using web service. I cache those video Icon in my directory. When i sending that application for apple review... application going crash there, the crash report is following,
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 2
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet bytes]: unrecognized selector sent to instance 0x27b300'
*** First throw call stack:
(0x3502e88f 0x36455259 0x35031a9b 0x35030915 0x34f8b650 0x34f7da4d 0x3587f2b9 0x3587ef31 0x3587ee9d 0x321102ab 0x321101c7 0xe36dd 0x31053c59 0x3105f7bb 0x36cd9dfb 0x36cd9cd0)
Thread 2 name: Dispatch queue: com.apple.root.default-priority
Thread 2 Crashed:
0 libsystem_kernel.dylib 0x34e2232c __pthread_kill + 8
1 libsystem_c.dylib 0x36d1e208 pthread_kill + 48
2 libsystem_c.dylib 0x36d17298 abort + 88
3 libc++abi.dylib 0x309e3f64 abort_message + 40
4 libc++abi.dylib 0x309e1346 _ZL17default_terminatev + 18
5 libobjc.A.dylib 0x36455350 _objc_terminate + 140
6 libc++abi.dylib 0x309e13be _ZL19safe_handler_callerPFvvE + 70
7 libc++abi.dylib 0x309e144a std::terminate() + 14
8 libc++abi.dylib 0x309e2798 __cxa_throw + 116
9 libobjc.A.dylib 0x36455290 objc_exception_throw + 88
10 CoreFoundation 0x35031a94 -[NSObject doesNotRecognizeSelector:] + 168
11 CoreFoundation 0x3503090e ___forwarding___ + 294
12 CoreFoundation 0x34f8b648 _CF_forwarding_prep_0 + 40
13 CoreFoundation 0x34f7da46 CFDataGetBytePtr + 90
14 ImageIO 0x3587f2b2 CGImageReadGetBytePointer + 30
15 ImageIO 0x3587ef2a _CGImageSourceBindToPlugin + 86
16 ImageIO 0x3587ee96 CGImageSourceGetCount + 50
17 UIKit 0x321102a4 _UIImageRefFromData + 124
18 UIKit 0x321101c0 -[UIImage initWithData:] + 52
19 MyAppName 0x000e36d6 __37-[JMImageCache imageForURL:delegate:]_block_invoke_0 + 142
20 libdispatch.dylib 0x31053c52 _dispatch_call_block_and_release + 6
21 libdispatch.dylib 0x3105f7b4 _dispatch_worker_thread2 + 256
22 libsystem_c.dylib 0x36cd9df4 _pthread_wqthread + 288
23 libsystem_c.dylib 0x36cd9cc8 start_wqthread + 0
Now my coding part in application ,
On Table view data source method
if(![[JMImageCache sharedCache] isImageExistInCache: cell.videoThumbnailImageLink]){
[cell.activityIndicator startAnimating];
cell.videoThumbnail.image = [[JMImageCache sharedCache] imageForURL:cell.videoThumbnailImageLink delegate:cell];
}
else{
[cell.activityIndicator stopAnimating];
[cell.activityIndicator removeFromSuperview];
cell.videoThumbnail.image = [[JMImageCache sharedCache] imageFromDiskForURL:cell.videoThumbnailImageLink];
}
And at custom cell of that tableview,
#pragma mark - JMImageCacheDelegate Methods
- (void) cache:(JMImageCache *)c didDownloadImage:(UIImage *)i forURL:(NSString *)url {
if([url isEqualToString:self.videoThumbnailImageLink]) {
self.imageView.image = i;
[self setNeedsLayout];
}
[self.activityIndicator stopAnimating];
[self.activityIndicator removeFromSuperview];
}
In JMImageCache library code block,
- (UIImage *) imageForURL:(NSString *)url delegate:(id<JMImageCacheDelegate>)d {
if(!url) {
return nil;
}
id returner = [super objectForKey:url];
if(returner) {
return returner;
} else {
UIImage *i = [self imageFromDiskForURL:url];
if(i) {
[self setImage:i forURL:url];
return i;
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
__unsafe_unretained NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *i = [[UIImage alloc] initWithData:data];
__unsafe_unretained NSString* cachePath = cachePathForURL(url);
NSInvocation* writeInvocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:#selector(writeData:toPath:)]];
[writeInvocation setTarget:self];
[writeInvocation setSelector:#selector(writeData:toPath:)];
[writeInvocation setArgument:&data atIndex:2];
[writeInvocation setArgument:&cachePath atIndex:3];
[self performDiskWriteOperation:writeInvocation];
[self setImage:i forURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
if(d) {
if([d respondsToSelector:#selector(cache:didDownloadImage:forURL:)]) {
[d cache:self didDownloadImage:i forURL:url];
}
}
});
});
return nil;
}
}
Thanks.

You have a memory problem. The hint is, that the variable which points to 0x27b300 in memory now contains a __NSCFSet (otherwise known as an NSSet). Make sure you're not using a variable which hasn't been nil'd out or is weak when it should be strong.

Your data is being released and deallocated before it's used, so when CoreGraphics calls -bytes on it, it's no longer there (and in this case, an NSSet has been allocated in its place).
Presumably this is because you declared it as __unsafe_unretained.

Related

iOS crash: respondsToSelector: message sent to deallocated instance

I am using a UINavigationController as rootviewController and storyboard segue for pushingViewController. I have many viewcontrollers in my app. I pass them using push view controller only.
Crash scenario: (can reproduce)
I have a Products list viewController and I will navigate to products detail viewController when I tap on product in the list using tap Gesture recognizer.
From the detail view controller, I will be pushed to cart item viewController which displays all selected products when I tap a button named 'Addd to cart'.
If I try to pay for all the products I want to choose a contact from the people picker, when I press pay button, it will present peopelpickerController as modalViewController and when I choose a contact it gets crashed.
Crash occurs only when move to and fro from products list view controlelr to peoplepicker contoller. When I debugged using instrument I got crash saying deallocated instance receiving message.
I have included the method where I am getting crash. But i never tried to call the method from any controller.
Code...
//choosing contact and people picker delegate
- (IBAction) chooseContacts: (id) sender {
picker = [
[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController: picker animated: YES completion: nil];
}
#pragma mark - Addressbook delegate methods
- (void) peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController * ) peoplePicker {
[self dismissViewControllerAnimated: YES completion: nil];
}
- (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController * ) peoplePicker
shouldContinueAfterSelectingPerson: (ABRecordRef) person {
[self dismissViewControllerAnimated: YES completion: ^ {
[self displayPerson: person];
}];
return NO;
}
Crash occurs in the below method at the line performSegueWithIdentifier,
#pragma mark- Tap gesture delegates
-(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
{
UIImageView *image = (UIImageView *)sender.view;
if (image.tag < [_productsArray count]) {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
productDetailDictionary = [_productsArray objectAtIndex:image.tag];
NSLog(#"%#",productDetailDictionary);
[self performSegueWithIdentifier:#"productDetailSeague" sender:sender];
}
NSLog(#"imageView.Tag %ld",(long)image.tag);
}
Crash Log:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x39cb11fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x39d1aa2e pthread_kill + 54
2 libsystem_c.dylib 0x39c61ff8 abort + 72
3 libc++abi.dylib 0x38f90cd2 abort_message + 70
4 libc++abi.dylib 0x38fa96e0 default_terminate_handler() + 248
5 libobjc.A.dylib 0x396f291e _objc_terminate() + 190
6 libc++abi.dylib 0x38fa71c4 std::__terminate(void (*)()) + 76
7 libc++abi.dylib 0x38fa6a18 __cxa_throw + 112
8 libobjc.A.dylib 0x396f277e objc_exception_throw + 246
9 CoreFoundation 0x2ef5be88 +[NSException raise:format:] + 100
10 UIKit 0x317b9590 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 496
11 UIKit 0x317b7dce -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2054
12 UIKit 0x317b6e20 -[UIViewController presentViewController:withTransition:completion:] + 4664
13 UIKit 0x31992cae -[UIViewController presentModalViewController:animated:] + 26
14 DHCC Events 0x0008f0c0 0x38000 + 356544
15 libdispatch.dylib 0x39bd5d18 _dispatch_call_block_and_release + 8
16 libdispatch.dylib 0x39bdbd16 _dispatch_after_timer_callback$VARIANT$mp + 46
17 libdispatch.dylib 0x39bd5d04 _dispatch_client_callout + 20
18 libdispatch.dylib 0x39bde7fe _dispatch_source_invoke$VARIANT$mp + 258
19 libdispatch.dylib 0x39bdc73a _dispatch_main_queue_callback_4CF$VARIANT$mp + 186
20 CoreFoundation 0x2ef26814 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
21 CoreFoundation 0x2ef250e8 __CFRunLoopRun + 1296
22 CoreFoundation 0x2ee8fc22 CFRunLoopRunSpecific + 518
23 CoreFoundation 0x2ee8fa06 CFRunLoopRunInMode + 102
24 GraphicsServices 0x33b8327e GSEventRunModal + 134
25 UIKit 0x31733044 UIApplicationMain + 1132
26 DHCC Events 0x00041ad6 0x38000 + 39638
27 libdyld.dylib 0x39bfaab4 start + 0
Appreciate your help.
On -(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
you perform the segue with
[self performSegueWithIdentifier:#"productDetailSeague" sender:sender];
but I think the sender should be self and not sender..
UPDATE
Do you try to perform segue while picker is active? In this case self may be deallocated, so you can try to perform segue after picker is dismissed:
[picker dismissViewControllerAnimated:YES completion:^{[self performSegueWithIdentifier:#"productDetailSeague" sender:self];}];

Exception / Crash When Merging CoreData Managed Contexts

Im getting the following exception when attempting to merge a managed context (running on a background thread) with my main managed context (on mainthread). I cant seem to catch the exception in my own #try expression. Does anyone have any insight into this issue?
I'm using the default merge policy but im not sure this is correct - this issue is very intermittent - happens rarely but is causing my app to crash.
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x37e3b8bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x319211e5 objc_exception_throw + 33
2 CoreData 0x344b7ea5 -[NSSQLiteStatement cachedSQLiteStatement] + 1
3 CoreData 0x344b774f -[NSSQLiteConnection prepareSQLStatement:] + 55
4 CoreData 0x3455b049 -[NSSQLChannel selectRowsWithCachedStatement:] + 61
5 CoreData 0x34586d63 newFetchedRowsForFetchPlan_MT + 783
6 CoreData 0x344bfb07 -[NSSQLCore newRowsForFetchPlan:] + 351
7 CoreData 0x34565011 -[NSSQLCore fetchRowForObjectID:] + 1005
8 CoreData 0x344d1a57 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 195
9 CoreData 0x344d0f83 _PFFaultHandlerLookupRow + 423
10 CoreData 0x3450e111 -[NSFaultHandler fulfillFault:withContext:] + 25
11 CoreData 0x34518999 -[NSManagedObject(_NSInternalMethods) _newPropertiesForRetainedTypes:andCopiedTypes:preserveFaults:] + 77
12 CoreData 0x345178ef -[NSManagedObject(_NSInternalMethods) _newAllPropertiesWithRelationshipFaultsIntact__] + 79
13 CoreData 0x345284db -[NSManagedObjectContext(_NSInternalChangeProcessing) _establishEventSnapshotsForObject:] + 47
14 CoreData 0x3452694b -[NSManagedObjectContext deleteObject:] + 155
15 CoreData 0x345238a1 -[NSManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:] + 813
16 CoreData 0x34522c35 -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:] + 189
17 myapp 0x0008f0e9 0x8d000 + 8425
18 CoreFoundation 0x37d9a22b -[NSObject performSelector:withObject:] + 43
19 Foundation 0x31d75757 __NSThreadPerformPerform + 351
20 CoreFoundation 0x37e0fb03 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
21 CoreFoundation 0x37e0f2cf __CFRunLoopDoSources0 + 215
22 CoreFoundation 0x37e0e075 __CFRunLoopRun + 653
23 CoreFoundation 0x37d914dd CFRunLoopRunSpecific + 301
24 CoreFoundation 0x37d913a5 CFRunLoopRunInMode + 105
25 GraphicsServices 0x3790ffcd GSEventRunModal + 157
26 UIKit 0x35221743 UIApplicationMain + 1091
I init the background context in start() of a nsoperation like so:
AppDelegate *appController = [[UIApplication sharedApplication] delegate];
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[appController setPersistentStore:_managedObjectContext];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receivedDeletedObjects:) name:NSManagedObjectContextDidSaveNotification object:_managedObjectContext];
I also set up a notification event which is called when objects are deleted on the background managed context, the callback then does:
-(void)receivedDeletedObjects:(NSNotification *)note
{
AppDelegate *appController = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *mainContext = [self managedObjectContext];
[mainContext performSelectorOnMainThread:#selector(mergeChangesFromContextDidSaveNotification:) withObject:note waitUntilDone:NO];
}
Thats pretty much the code. I have 4 different background threads each with its own managed context doing the same thing merging with the main context in this manner. Im wondering multiple threads are getting into mergeChangesFromContextDidSaveNotification at the same time but this shouldnt be the case as it is always called on the mainthread.
How about this:
(all in AppDelegate, call freshContextForBackgroundTask from a background Thread and use save: to trigger the merge.) Note syncObj is a plain NSObject instance needed for synchronization within the app delegate when using many background threads (or just have bad luck with scheduling)
-(NSManagedObjectContext*) freshContextForBackgroundTask {
#synchronized(syncObj) {
NSManagedObjectContext* r = [[NSManagedObjectContext alloc] init];
[r setPersistentStoreCoordinator:self.managedObjectContext.persistentStoreCoordinator];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(backgroundContextDidSave:)
name:NSManagedObjectContextDidSaveNotification
object:r];
return r;
}
}
- (void)backgroundContextDidSave:(NSNotification *)notification {
/* Make sure we're on the main thread when updating the main context */
//NSLog(#"merging change: %#",notification);
dispatch_async(dispatch_get_main_queue(), ^{
NSManagedObjectContext *context = [self managedObjectContext];
// this for loop may not be needed for your purpose.
for(NSManagedObject *object in [[notification userInfo] objectForKey:NSUpdatedObjectsKey]) {
[[context objectWithID:[object objectID]] willAccessValueForKey:nil];
}
[self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
});
}
Your approach seems strange. Especially when you set your app delegate's persistent store to the (nil) one of the freshly init'ed context.

UIWebView load crash [__NSCFDictionary _isChargeEnabled]

I use UIWebView to load this site http://www.xiami.com/song/1024665
sometimes my app crashes if I touch the view or play the audio in this site and sometimes it does not, why?
is it because html5? how to solve?
other website is no problem.
crash log is
* -[MPTransportButton _isChargeEnabled]: message sent to deallocated instance 0x20aa58d0
any help is much appreciated
---update---
I create a new view-base project, the code in ViewController is as following
This time, the crash log is
2011-08-16 18:11:25.450 WebTest[1291:707] -[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10
2011-08-16 18:11:25.462 WebTest[1291:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10'
*** Call stack at first throw:
(
0 CoreFoundation 0x30ea764f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x349c2c5d objc_exception_throw + 24
2 CoreFoundation 0x30eab1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x30eaa649 ___forwarding___ + 508
4 CoreFoundation 0x30e21180 _CF_forwarding_prep_0 + 48
5 UIKit 0x30f232bd -[UIWindow warpPoint:] + 200
6 UIKit 0x30f0c1d5 _UIApplicationHandleEvent + 2404
7 GraphicsServices 0x30790e77 PurpleEventCallback + 666
8 CoreFoundation 0x30e7ea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
9 CoreFoundation 0x30e8083f __CFRunLoopDoSource1 + 166
10 CoreFoundation 0x30e8160d __CFRunLoopRun + 520
11 CoreFoundation 0x30e11ec3 CFRunLoopRunSpecific + 230
12 CoreFoundation 0x30e11dcb CFRunLoopRunInMode + 58
13 GraphicsServices 0x3079041f GSEventRunModal + 114
14 GraphicsServices 0x307904cb GSEventRun + 62
15 UIKit 0x30f37d69 -[UIApplication _run] + 404
16 UIKit 0x30f35807 UIApplicationMain + 670
17 WebTest 0x00013425 main + 48
18 WebTest 0x000133f0 start + 40
)
terminate called after throwing an instance of 'NSException'
the source code in the project, not use MPMoviePlayerController this time or something else
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [self init];
return self;
}
- (id)init
{
if (self = [super initWithNibName:nil bundle:nil])
{
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[web loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://www.xiami.com/song/1024665"]]];
web.delegate = self;
[self.view addSubview:web];
[web release];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 10);"];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
}
There's nothing wrong in code that you posted.
NSZombie says that there is a MPTransportButton somewhere in your code that was previously deallocated (released) and after that, somewhere else in your code, you want to do something with it.
I think that you do it in one of your UIWebView's delegate methods.
But... we need more code. Where do you alloc/init your MPMoviePlayerController? Or do you alloc/init a MPTransportButton?

UIWebView loading html5-Video EXC_BAD_ACCESS crash

in our iPad-App we are using an UIWebView to load different sites from one domain some of them with a hml5-Video.
Sites without a Video do load perfectly. But when I'm loading a site containing htmlt5-video sometimes my app
crashes during the loading-process of the UIWebView with EXC_BAD_ACCESS and sometimes it does not. Whenever such a crash occurs it seems to happen at the point where the Video-Player is added into the site.
I did download the UICatalog-Example from Apple and just did change the Default-URL in the WebViewController-Class to a URL of a site containg html5-video. Same results ... sometimes crash sometimes no crash.
I also did create a New Project on Xcode (View-based Application - for iPad) and only did add a UIWebView to the new Projects ViewController. Again ... loading a site containing html5-video sometimes leads to a crash and sometimes not.
CODE FROM "NEW PROJECTS" VIEWCONTROLLER (IMPLEMENTATION):
- (void)viewDidLoad {
[super viewDidLoad];
self.myWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129103114849"]]];
//More Sites with HTML5-Videos ...
//[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129103746403"]]];
//[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129105233646"]]];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.myWebView = nil;
}
- (void)viewWillDisappear:(BOOL)animated {
[self.myWebView stopLoading];
}
- (void)dealloc {
myWebView.delegate = nil;
[myWebView release];
[super dealloc];
}
CODE FROM "NEW PROJECTS" VIEWCONTROLLER (HEADER):
#interface WebViewTestViewController : UIViewController <UIWebViewDelegate> {
UIWebView *myWebView;
}
#property (nonatomic, retain) UIWebView *myWebView;
DEVICE LOGS:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000098
Crashed Thread: 0
Thread 0 Crashed:
0 WebCore 0x34c7d09e WebCore::RenderLayer::clippingRoot() const + 110
1 WebCore 0x34c7cf2a WebCore::RenderLayer::childrenClipRect() const + 26
2 WebCore 0x34c7ce0c WebCore::RenderWidget::setWidgetGeometry(WebCore::IntRect const&) + 40
3 WebCore 0x34c5e0f8 WebCore::RenderWidget::updateWidgetPosition() + 320
4 WebCore 0x34ba0170 WebCore::RenderView::updateWidgetPositions() + 144
5 WebCore 0x34b97d16 WebCore::FrameView::performPostLayoutTasks() + 202
6 WebCore 0x34b8a6c0 WebCore::FrameView::layout(bool) + 2116
7 WebCore 0x34bc5244 WebCore::FrameView::forceLayout(bool) + 4
8 WebKit 0x302c0c24 -[WebHTMLView layoutToMinimumPageWidth:height:maximumPageWidth:adjustingViewSize:] + 136
9 WebKit 0x302c0b8e -[WebHTMLView layout] + 18
10 WebKit 0x302c26f2 -[WebHTMLView(WebInternal) _layoutIfNeeded] + 50
11 WebKit 0x302c2622 -[WebHTMLView(WebInternal) _web_layoutIfNeededRecursive] + 14
12 WebKit 0x302c251e -[WebHTMLView(WebPrivate) viewWillDraw] + 50
13 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
14 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
15 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
16 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
17 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
18 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
19 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
20 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
21 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
22 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
23 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
24 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
25 WebKit 0x302c24cc -[WebView(WebPrivate) viewWillDraw] + 56
26 WebCore 0x34bafec0 WebCore::TileCache::prepareToDraw() + 36
27 WebCore 0x34bafe6e -[TileLayer display] + 26
28 QuartzCore 0x31079fb0 CALayerDisplayIfNeeded + 176
29 QuartzCore 0x3106f56e CA::Context::commit_transaction(CA::Transaction*) + 214
30 QuartzCore 0x3106f37c CA::Transaction::commit() + 184
31 QuartzCore 0x31092f96 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 46
32 CoreFoundation 0x3580ac52 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10
33 CoreFoundation 0x3580aac6 __CFRunLoopDoObservers + 406
34 CoreFoundation 0x358020c4 __CFRunLoopRun + 848
35 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
36 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
37 GraphicsServices 0x320c84a4 GSEventRunModal + 108
38 GraphicsServices 0x320c8550 GSEventRun + 56
39 UIKit 0x341dc322 -[UIApplication _run] + 406
40 UIKit 0x341d9e8c UIApplicationMain + 664
41 WebViewTest 0x00002c24 0x1000 + 7204
42 WebViewTest 0x00002bd8 0x1000 + 7128
Can anybody give me an idea?
Thanks in advance, Florian
There is a little trick to override this crash. If you slightly scroll the webview just before the video content is loaded, the crash can be avoided. Before trying it out from code, try scrolling the webView a bit on device with your finger. It won't crash now.
In code, do something like this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 10);"];
}
to simulate a scroll on the webview through javascript. The scroll value can be as low as 1, so the user won't notice the scroll at all.
Telling the webview to evaluate any JavaScript (or none at all) on webViewDidFinishLoad: seems work (albeit hacky).
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:#""];
}
Seems I've solved this issue...
i've moved all HTML-5 video tags insertion in Javascript
function placeVideoTag() {
var val = '<video />';
var el = document.getElementById('video-id');
el.innerHTML = val;
}
And i'm calling JS in [UIWebView didFinishLoad]
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
[aWebView stringByEvaluatingJavaScriptFromString:#"placeVideoTag()"];
}
Works perfectly in my case.
Other suggestions didn't work for me.
I have exactly the same problem. no answer yet. Saw many others reports similar problems - iOS 4.2.1 only.
Basically, I have a UIView Controller with a webview as its subview, and load a URLRequest to a youtube link.
The first time I load the viewController, the console logs error "Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/System/Library/Internet Plug-Ins/QuickTime Plugin.webplugin/QuickTime Plugin (file not found).". I stop loading and release the viewController. The second time I re-load new viewController with the same request to that youtube link, now the app crashed with EXC_BAD_ACCESS
Thanks, for your posts!!! In my case it only works with different quite high offset-values for Portrait- and Landscape-Mode on iPad
(Portrait-Mode: greater than 60; Landscape-Mode: greater than 780):
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait ||
self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 60);"];
} else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 780);"];
}
webView.loadCounter--;
}
But with this solution my app crashes by double-tapping to zoom during the loading-process of a site.
I did subclass UIWebView to solve this problem (to prevent webView from zooming while loading):
.m:
#synthesize loadCounter;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint p = currentPoint;
NSTimeInterval t = currentTimestamp;
currentPoint = point;
currentTimestamp = [event timestamp];
if (CGPointEqualToPoint(p, point) &&
[event timestamp] - t < 0.2 && loadCounter > 0){
return self.superview;
}
return [super hitTest:point withEvent:event];
}
.h:
#interface NonDoubleTapableWhileLoadingWebView : UIWebView {
CGPoint currentPoint;
NSTimeInterval currentTimestamp;
NSInteger loadCounter;
}
#property (assign) NSInteger loadCounter;
And added a counter to determine the last "didFinish"-call and to reactivate the double-tapping possibility
(init loadCounter with 0)
- (void)webViewDidStartLoad:(UIWebView *)webView {
linkWebView.loadCounter++;
}

How to ensure that UIImage is never released?

I grabbed the crash log from the iPhone:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000c
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x30011940 objc_msgSend + 20
1 CoreFoundation 0x30235f1e CFRelease + 98
2 UIKit 0x308f4974 -[UIImage dealloc] + 36
3 CoreFoundation 0x30236b72 -[NSObject release] + 28
4 UIKit 0x30a00298 FlushNamedImage + 64
5 CoreFoundation 0x30250a20 CFDictionaryApplyFunction + 124
6 UIKit 0x30a0019c _UISharedImageFlushAll + 196
7 UIKit 0x30a00730 +[UIImage(UIImageInternal) _flushCacheOnMemoryWarning:] + 8
8 Foundation 0x3054dc7a _nsnote_callback + 178
9 CoreFoundation 0x3024ea52 _CFXNotificationPostNotification + 298
10 Foundation 0x3054b854 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
11 Foundation 0x3054dbba -[NSNotificationCenter postNotificationName:object:] + 14
12 UIKit 0x30a00708 -[UIApplication _performMemoryWarning] + 60
13 UIKit 0x30a006a0 -[UIApplication _receivedMemoryNotification] + 128
14 UIKit 0x30a005d0 _memoryStatusChanged + 56
15 CoreFoundation 0x30217410 __CFNotificationCenterDarwinCallBack + 20
16 CoreFoundation 0x3020d0aa __CFMachPortPerform + 72
17 CoreFoundation 0x30254a70 CFRunLoopRunSpecific + 2296
18 CoreFoundation 0x30254164 CFRunLoopRunInMode + 44
19 GraphicsServices 0x3204529c GSEventRunModal + 188
20 UIKit 0x308f0374 -[UIApplication _run] + 552
21 UIKit 0x308eea8c UIApplicationMain + 960
...
...
From my previous question, Can somebody give me a hand about this stacktrace in iPhone app?, I have changed my codes mainly around UIImage part. I now use [[UIImage alloc] initWithContentsOfFile ... ]. No more [UIImage imageNamed: ... ] or the like. The portion is below.
//this is a method of a subclass of UIImageView.
- (void) reviewImage: (bool) review{
NSString* st;
if (review){
NSString* origin = [NSString stringWithString: [[ReviewCardManager getInstance] getCardImageString:chosenIndex]];
NSString* stt = [origin substringToIndex: [origin length]-4];
st = [[NSString alloc] initWithString: stt];
if (myImageFlipped == nil)
myImageFlipped = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:#"png"]];
[self setImage:myImageFlipped];
if (notRotated){
self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
notRotated = false;
}
}else{
st = [[NSString alloc] initWithFormat:#"sc%d", chosenNumber];
if (myImage == nil)
myImage = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:#"png"]];
[self setImage:myImage];
if (notRotated){
self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
notRotated = false;
}
}
[st release];
}
I also have the UIImage already retained in the property.
#property (nonatomic, retain) UIImage* myImage, *myImageFlipped;
Memory Leaks have also been taken cared of. These variables are release in dealloc method.
I thought that I have successfully killed the bug, but it seems that I still have a rare occuring bug problem.
Based on the crash log, my application yells out "performMemoryWarning". I am just "alloc"-ing 13 .png images with the size 156 x 272. I'm confused. Those images shouldn't take that much memory to the point that it exceeds iPhone's RAM. Or is there something I am overlooking? Please advise.
To help you with memory issues and UIImages, you might want to use the imageNamed convience method of UIImage, from the docs:
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
Alternatively, you might want to go this route if you still run into memory issues after switching to UIImage imageNamed, because there are some downsides to using the convinience method.
The problem is solved. I forgot to change UIImage at one place. Now, all UIImages are truly "alloc", no more autorelease.
FYI, if you are using [UIImage imageNamed: ... ], use "Simulate Memory Warning" on iPhone Simulator to see whether you are having a problem with it when the real device is low on memory.