UIImage: imageNamed crash - uiimage

I am having truble while using [UIImage imageNamed:] method
It appeares that crash occured when launching app from killed state and getting an resource image.
All my images are stored in bundle and no issue with background thread.
Following is crash log
Thread : Crashed: com.apple.main-thread
19 UIKit 0x186739714 +[UIImage imageNamed:inBundle:compatibleWithTraitCollection:] + 380
20 UIKit 0x18658cc8c +[UIImage imageNamed:] + 124
This happens on
UIImage * image = [UIImage imageNamed:#"abc.png"];

Related

PDFDocument removePageAtIndex: is not working when updated to Mac OS X 10.11

I am using the PDFKit Framework into my cocoa app for PDFViewer.When I am trying to delete one of the page from the PDFDocument The app freezes at the line of code
[[self pdfDocument] removePageAtIndex:0]; // can see this Problem only in Mac OS X 10.11
This works perfectly when I run the app in Mac OS X 10.10
I read all the related apple documents but I didn't get any solution yet.
Here is the backtrace :
* thread #1: tid = 0x85e1, 0x00007fff92571f5e libsystem_kernel.dylib`__psynch_cvwait + 10, queue = 'com.apple.main-thread', stop reason = signal SIGTERM
frame #0: 0x00007fff92571f5e libsystem_kernel.dylib`__psynch_cvwait + 10
frame #1: 0x00000001006c05f7 libsystem_pthread.dylib`_pthread_cond_wait + 767
frame #2: 0x00007fff904c6e32 Foundation`-[__NSOperationInternal _waitUntilFinished:] + 131
frame #3: 0x00007fff904921fa Foundation`-[NSOperationQueue waitUntilAllOperationsAreFinished] + 254
* frame #4: 0x000000010017efe1 Neat`-[NRMPDFCoordinator waitUntilAllOperationsAreFinished](self=0x0000608000ad3be0, _cmd=0x00007fff8877e285) + 145 at NRMPDFCoordinator.m:1362
frame #5: 0x00000001000109cf Neat`-[NRMItemEditorDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:](self=0x000060000094a190, _cmd=0x00007fff88777581, delegate=0x0000000000000000, didSaveSelector=0x0000000000000000, contextInfo=0x0000000000000000) + 1151 at NRMItemEditorDocument.m:325
frame #6: 0x000000010001018a Neat`-[NRMItemEditorDocument saveDocument:](self=0x000060000094a190, _cmd=0x00007fff8874cbb4, sender=0x00006080003a8b20) + 58 at NRMItemEditorDocument.m:234
frame #7: 0x0000000100013bef Neat`-[NRMItemEditorWindowController saveAndClose:](self=0x00006080003a8b20, _cmd=0x00000001002cf2d2, sender=0x000060000094a5b0) + 95 at NRMItemEditorWindowController.m:244
frame #8: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #9: 0x00007fff87fc79b5 AppKit`-[NSApplication sendAction:to:from:] + 460
frame #10: 0x00007fff87fd9bb2 AppKit`-[NSControl sendAction:to:] + 86
frame #11: 0x00007fff87fd9adc AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 131
frame #12: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #13: 0x00007fff87fd9a39 AppKit`-[NSCell _sendActionFrom:] + 144
frame #14: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #15: 0x00007fff87fd805e AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
frame #16: 0x00007fff88020d1c AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
frame #17: 0x00007fff87fd6788 AppKit`-[NSControl mouseDown:] + 669
frame #18: 0x00007fff88524575 AppKit`-[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
frame #19: 0x00007fff88525559 AppKit`-[NSWindow _reallySendEvent:isDelayedEvent:] + 212
frame #20: 0x00007fff87f6ad31 AppKit`-[NSWindow sendEvent:] + 517
frame #21: 0x00007fff87eeaccb AppKit`-[NSApplication sendEvent:] + 2540
frame #22: 0x0000000100225f35 Neat`-[NRMApplication sendEvent:](self=0x00006000001205a0, _cmd=0x00007fff88749e04, event=0x0000608000725640) + 1141 at NRMApplication.m:95
frame #23: 0x00007fff87d51f3e AppKit`-[NSApplication run] + 796
frame #24: 0x00007fff87d1b162 AppKit`NSApplicationMain + 1176
frame #25: 0x0000000100012d67 Neat`main(argc=3, argv=0x00007fff5fbff718) + 119 at main.m:21
frame #26: 0x0000000100001e74 Neat`start + 52
here is the method where I am using removePageAtIndex method of PDFDocument
-(NSError *)removePageOpImpl:(NRMPDFOperation *)op
{
NSLog(#"\n Inside removePageOpImpl Method ...");
NSError* error = [self loadDocument];
if( !error )
{
NSUInteger index = [self pageIndexForId:[op pageId]];
NSLog(#"Page count: %ld", [self pageCount]);
if( index < [self pageCount] )
{
NSLog(#"PDF Document:-- %#", [self pdfDocument]);
NSLog(#"Index is: %ld", index);
#try {
[(PDFDocument *)[self pdfDocument] removePageAtIndex:index];//At this line the app getting freezed and control is ended.
NSLog(#"Page count after delete: %ld", [self pageCount]);
}
#catch (NSException *exception) {
NSLog(#"Exception: %#", exception);
}
#finally {
NSLog(#"Finally called");
[[self mutablePageIdList] removeObjectAtIndex:index];
[self updatePageLabelsFromIndex:index];
[self updateChangeCount:NSChangeDone];
self.contentsChanged = YES;
}
}
else
{
// TODO: error
}
}
return error;
}
Can anyone please suggest me what might be the problem... also attached screenshots of the Queues which were blocking the UI
I tried applying dispatch_async on main queue to the PDFDocument page removal operations like below
- (NSError *)removePageOpImpl:(NRMPDFOperation *)op
{
NSError* error = [self loadDocument];
if( !error )
{
NSUInteger index = [self pageIndexForId:[op pageId]];
if( index < [self pageCount] )
{
dispatch_async(dispatch_get_main_queue(), ^{
[[self pdfDocument] removePageAtIndex:index];
[[self mutablePageIdList] removeObjectAtIndex:index];
[self updatePageLabelsFromIndex:index];
[self updateChangeCount:NSChangeDone];
self.contentsChanged = YES;
});
}
else
{
// TODO: error
}
}
return error;
}
Now the app is not hanging, but I fall into another problem. I have other operations which should run synchronously after the removePageOpImpl operations. but they are executing before removePageOpImpl completion which is changing the behaviour of my app. Can you suggest me how can I execute other operations synchronously after removePageOpImpl. I read about completion handler but, in this scenario I am confused of how to use it.
Please suggest
You have created a nice little deadlock here.
Your main thread is waiting for an operation to finish, but that operation (indicated by this trace)...
is running on a background thread and, as you can see, it's waiting on a semaphore that is most likely only going to be signaled from the main thread. This has the earmarks of something like dispatch_sync to the main thread. Since it happens inside the PDFDocument implementation, I imagine it is trying to make sure it runs something on the main thread before returning to the user (reader/writer lock
Thus, your main thread is waiting for an operation to finish, and that operation is waiting for the main thread to finish what it's trying to do. Classic deadlock.
This happens because the main thread kicks off the save, and then waits for everything to complete before progressing (but some of that other work also needs to run on the main thread).
You need to kick off the save as an asynchronous operation, so it is not running on the main thread while waiting for the operations to complete. Then, when the save is done, if you have to update UI, it can report its success/failure via a completion block or delegate running on the main thread.

EXC_BAD_ACCESS only on 10.6.8

I am trying to get my app to run on version 10.6 but when I do I get an EXC_BAD_ACCESS exception. When I run it on my computer which has the latest version it runs fine, but for some reason it won't work on versions below 7. Since I don't develop on a 10.6 computer all I have to look at is the crash log:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x00007fff87604930 CFDictionaryGetValue + 96
1 com.apple.CFNetwork 0x00007fff810814d9 CFHTTPCookieCreateWithProperties + 111
2 com.apple.Foundation 0x00007fff88812f4c -[NSHTTPCookie initWithProperties:] + 29
3 com.apple.Foundation 0x00007fff88813243 +[NSHTTPCookie cookieWithProperties:] + 50
This is the main part of the crash log. It seems to crash trying to get a dictionary value but I'm not exactly sure how to read these.
Okay I was able to solve it. I loaded a cookie on start with a method like this:
- (NSHTTPCookie *)loadCookie {
NSDictionary *properties = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kDefCookie];
return [NSHTTPCookie cookieWithProperties:properties[COOKIE_KEY]];
}
I saved the cookie properties in defaults so I could save the users cookie across sessions. Running on the latest version, this method returned nil for me when there was no cookie stored in defaults. For some reason this doesn't seem to work on 10.6. I changed the method like this and it works perfectly now.
- (NSHTTPCookie *)loadCookie {
NSDictionary *properties = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kDefCookie];
if (properties)
return [NSHTTPCookie cookieWithProperties:properties[COOKIE_KEY]];
else return nil;
}
Thanks Carter Pape fo helping me read the crash log. I focused to much on the cfDictionary part and I didn't read the stuff that came before

EXC_BAD_INSTRUCTION in Lion but not in Mountain Lion

I'm getting the following EXC_BAD_INSTRUCTION exception when opening a window in Lion but the app appears to work fine in Mountain Lion. What can be the problem?
Process:         MyApp [595]
Path:            /Users/USER/Desktop/MyApp.app/Contents/MacOS/MyApp
Identifier:      com.example.MyApp
Version:         ??? (0.4)
Code Type:       X86-64 (Native)
Parent Process:  launchd [146]
Date/Time:       2012-09-25 11:09:14.498 +0200
OS Version:      Mac OS X 10.7.3 (11D50d)
Report Version:  9
Sleep/Wake UUID: BA4DA964-60E8-4DC6-B63C-99435074A41C
Interval Since Last Report:          2901634 sec
Crashes Since Last Report:           367
Per-App Interval Since Last Report:  129923 sec
Per-App Crashes Since Last Report:   8
Anonymous UUID:                      BFF6E121-730D-4729-B07F-DA8550F46E14
Crashed Thread:  0  Dispatch queue: com.apple.main-thread
Exception Type:  EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Application Specific Information:
objc[595]: garbage collection is OFF
objc[595]: cannot form weak reference to instance (0x7fc091666650) of class MyViewController
Performing #selector(startPressed:) from sender NSButton 0x7fc09167d210
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                0x00007fff91496768 _objc_trap + 4
1   libobjc.A.dylib                0x00007fff914968aa _objc_fatal + 195
2   libobjc.A.dylib                0x00007fff914a24ad weak_register_no_lock + 346
3   libobjc.A.dylib                0x00007fff914a2a59 objc_storeWeak + 360
4   com.apple.CoreFoundation       0x00007fff8f29c75d -[NSObject performSelector:withObject:] + 61
5   com.apple.AppKit               0x00007fff94bb5392 -[NSNibOutletConnector establishConnection] + 405
6   com.apple.AppKit               0x00007fff94bb2a89 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 107
Found it. The problem was that I had declared a delegate id property with weak and assigned a NSVieWcontroller to it.
Apparently, if you want to support Lion and be safe you should never declare id properties as weak. From the Transitioning to ARC Release Notes:
Note: In addition, in OS X v10.7, you cannot create weak references to
instances of NSFontManager, NSFontPanel, NSImage, NSTableCellView,
NSViewController, NSWindow, and NSWindowController. In addition, in OS
X v10.7 no classes in the AV Foundation framework support weak
references.
Solution: use assign instead.
#property (nonatomic, assign) IBOutlet id<MyDelegateProtocol> delegate;

IOS 6 MKMapView crashes on [EAGLContext setCurrentContext]

We are developing an iPad application starting from map view with annotations.
By using storyboard when We switch to another view which has an opengl based charting solution (shinobi).
On return to the view with map it has no problem until a touch on the map to move it.
As we try to move map it crashes with exc_bad_access exception at [EAGLContext setCurrentContext]
Any ideas?
Here is the part of the crash log:
OS Version: iOS 6.0 (10A403)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000c
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 OpenGLES 0x39974b12 +[EAGLContext setCurrentContext:] + 74
1 VectorKit 0x32c64f0c -[VGLGPU setPaused:] + 120
2 VectorKit 0x32c54db8 -[VKMainLoop updateLinkState] + 492
3 VectorKit 0x32c54950 -[VKScreenCanvas _updateDisplayStatus:] + 104
4 VectorKit 0x32ccea9a -[VKScreenCanvas setGesturing:] + 254
5 MapKit 0x34defc3c -[MKMapView _willStartUserInteraction] + 48
6 MapKit 0x34de891a -[MKMapGestureController beginGesturing] + 50
7 MapKit 0x34de8c6c -[MKMapGestureController handlePan:] + 252
8 UIKit 0x379ead2c _UIGestureRecognizerSendActions + 124
9 UIKit 0x379b23d8 -[UIGestureRecognizer _updateGestureWithEvent:] + 388
10 UIKit 0x37b9f474 ...
I work for Shinobi and we've been investigating this - it's partly due to Apple's map code keeping hold of our GL-Context. As a temporary workaround, you can create a subclass of a ShinobiChart and nil-out the GL context in the chart's dealloc method, like so:
- (void) dealloc {
[super dealloc];
[EAGLContext setCurrentContext:nil]; // must be after dealloc
}
or if you're using ARC, (since sending dealloc is not allowed):
#import <ShinobiCharts/SChartCanvas.h>
#interface ShinobiChartGl : ShinobiChart
#end
#implementation ShinobiChartGl
- (void) dealloc
{
[self.canvas.glView removeFromSuperview];
self.canvas.glView = nil; // force glView dealloc
[EAGLContext setCurrentContext:nil];
}
#end
Hope this helps, but do contact us directly - we'll have a full fix out in our next release.
for those who did not work even tried [EAGLContext setCurrentContext:nil]; on dealloc, try this
dispatch_async(dispatch_get_main_queue(), ^{
[EAGLContext setCurrentContext:nil];
});
EAGLContext should be set on main thread.

Help with crash log

My app is crashing on Lion when it awakes from sleep.
The problem seems to be with a background thread that is looking for weather info.
I'm not sure but I think the crash log is telling me that the autorelease pool is popping objects that are no longer there, can someone help me confirm this?
Here is the relevant details for the Crash log:
Process: myApp [14187] Identifier: myApp Version:
??? (???) Code Type: X86-64 (Native) Parent Process: launchd
[224]
Date/Time: 2011-08-24 18:58:00.581 -0400 OS Version: Mac OS
X 10.7.1 (11B26) Report Version: 9
Crashed Thread: 7
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes:
KERN_INVALID_ADDRESS at 0x0000000000000010
Application Specific Information: objc[14187]: garbage collection is
OFF
Thread 7 Crashed: 0 libobjc.A.dylib
0x00007fff9321700b (anonymous
namespace)::AutoreleasePoolPage::pop(void*) + 385 1
com.apple.CoreFoundation 0x00007fff961306a5
CFAutoreleasePoolPop + 37 2 com.apple.Foundation
0x00007fff969350d7 -[NSAutoreleasePool drain] + 154 3
com.piso13.opusDomini 0x00000001000acb91 -[Weather
internalStart] + 417 4 com.apple.Foundation
0x00007fff9698b1ea -[NSThread main] + 68 5 com.apple.Foundation
0x00007fff9698b162 NSThread_main + 1575 6 libsystem_c.dylib
0x00007fff90b068bf _pthread_start + 335 7 libsystem_c.dylib
0x00007fff90b09b75 thread_start + 13
Here is my code for Weather Internal Start:
-(void)internalStart{
pool = [[NSAutoreleasePool alloc] init];
forecast = FALSE;
liveweather = FALSE;
NSString *query = [self generateQuery];
if (query == nil) {
[pool drain];
return;
}
XmlWrapper * xmlWrapper = [[XmlWrapper alloc] initWithQuery:query delegate:self name:#"liveweather"];
[xmlWrapper release];
query = [self generateForecastQuery];
xmlWrapper = [[XmlWrapper alloc] initWithQuery:query delegate:self name:#"forecast"];
[xmlWrapper release];
[pool drain];
}
Should I even be calling [pool drain] ?
create your autorelease pools with bound lifetimes and explicit scopes.
in this case, you store your autorelease pool in an ivar (presumed).
just make it local to the method, like so:
- (void)internalStart
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//...
[pool drain], pool = nil;
}
the problems that are typically introduced are:
1) autorelease pools are stack based (pools are pushed and popped). by holding onto it, you can easily mess up the stack order.
2) if this class operates in a multithreaded context, you can easily leak pools or destroy the stack order when you push and pop pools from multiple threads.
3) you could also leak pools in multithreaded contexts
Unfortunately, autoreleasepool crashes are some of the hardest to debug. Start with the static analyzer, which can find some things.
Then turn on NSZombies.
Your XmlWrapper object is a bit strange. Why do you immediately release it as soon as you create it? Is this a wrapper around NSURLConnection? You should still hold onto the object so that you can cancel it or clear its delegate when this object is released.
Make sure you're using accessors for all your ivars rather than accessing them directly. Direct access to ivars outside of init and dealloc is the #1 cause of these kinds of crashes in my experience.

Resources