UIActivityIndicatorView is bugged in the iPhoneSDK? (crashes from UIKit) - iphone

I got the following crash report from iTunesconnect. Is the UIActivityIndicatorView bugged?
Date/Time: 2009-09-26 12:33:02.034 +1000
OS Version: iPhone OS 3.0 (7A341)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x31d54964 lstat + 8
1 Foundation 0x3055baf6 _NSFileExistsAtPath
2 Foundation 0x3055f6a2 -[NSFileManager fileExistsAtPath:]
3 WinterBoard.dylib 0x0019f034 0x19c000 + 12340
4 WinterBoard.dylib 0x001a032c 0x19c000 + 17196
5 UIKit 0x30972650 +[UIActivityIndicatorView _loadResourcesForStyle:]
6 UIKit 0x30972498 -[UIActivityIndicatorView setActivityIndicatorViewStyle:]
7 UIKit 0x309723bc -[UIActivityIndicatorView initWithFrame:]
8 UIKit 0x30a113f8 -[UIActivityIndicatorView initWithActivityIndicatorStyle:]
Below is how I created it:
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act.center = CGPointMake(160, 190);
[act startAnimating];
[self addSubview:act];
[act release];

As you can see in the log, it goes wrong with -[NSFileManager fileExistsAtPath:]. Below that line in the stack trace, you see that it was being called by Winterboard.dylib.
Winterboard is an application for jailbroken iPhones to modify the appearance of the OS which is not supported by Apple. In this case, Winterboard is to blame for the crash of your application, not UIKit.
You can't do anything about that, it's probably a bug in Winterboard which only users with a jailbroken iPhone and Winterboard may have.

Related

Crashes on sizeWithFont and its replacement on iOS 7

I have the application that uses sizeWithFont method. It crashes on about 5% of launches of the application on iOS 7. The method is deprecated on SDK 7, so I replaced it with the following category:
#import "NSString+mySizeWithFont.h"
#import "Constants.h"
#implementation NSString (mySizeWithFont)
- (CGSize)mySizeWithFont:(UIFont *)font {
if (is_iOS7) {
CGSize size = CGSizeMake(MAXFLOAT, MAXFLOAT);
return [self mySizeWithFont:font constrainedToSize:size];
} else {
return [self sizeWithFont:font];
}
}
- (CGSize)mySizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size {
if (is_iOS7) {
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
CGRect frame = [self boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:attributesDictionary context:nil];
return frame.size;
} else {
return [self sizeWithFont:font constrainedToSize:size];
}
}
#end
But now I have another crashes on the same 5% of launches. There are crash reports of 2 types:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0005006f
Triggered by Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3902cb76 objc_msgSend + 22
1 CoreFoundation 0x2ec74c56 +[__NSDictionaryI __new:::::] + 358
2 CoreFoundation 0x2ec749c6 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 238
3 CoreFoundation 0x2ec794d4 +[NSDictionary dictionaryWithObjectsAndKeys:] + 372
4 *** MYAPP *** 0x000cd99e -[NSString(mySizeWithFont) mySizeWithFont:constrainedToSize:] (NSString+mySizeWithFont.m:25)
5 *** MYAPP *** 0x000cd7e6 -[NSString(mySizeWithFont) mySizeWithFont:] (NSString+mySizeWithFont.m:17)
6 *** MYAPP *** 0x000d36ae -[LiteVersionHomepageLink drawRect:] (LiteVersionHomepageLink.m:43)
And this one:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x2ed36e86 __exceptionPreprocess + 126
1 libobjc.A.dylib 0x390316c2 objc_exception_throw + 34
2 CoreFoundation 0x2ed3a7b2 -[NSObject(NSObject) doesNotRecognizeSelector:] + 198
3 CoreFoundation 0x2ed390b2 ___forwarding___ + 702
4 CoreFoundation 0x2ec87e94 __forwarding_prep_0___ + 20
5 UIFoundation 0x3660790e __NSStringDrawingEngine + 2950
6 UIFoundation 0x36606d5a -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:] + 130
7 *** MYAPP *** 0x000e89d4 -[NSString(mySizeWithFont) mySizeWithFont:constrainedToSize:] (NSString+mySizeWithFont.m:26)
8 *** MYAPP *** 0x000e87e6 -[NSString(mySizeWithFont) mySizeWithFont:] (NSString+mySizeWithFont.m:17)
9 *** MYAPP *** 0x000ee6ae -[LiteVersionHomepageLink drawRect:] (LiteVersionHomepageLink.m:43)
LiteVersionHomepageLink is inherited from UIView:
#interface LiteVersionHomepageLink : UIView {
NSString *text;
UIFont *textFont;
}
And mySizeWithFont is called from the following method:
- (void)drawRect:(CGRect)rect {
[[UIImage imageNamed:#"cal_top_back#2x"] drawInRect:rect];
if (text && textFont) {
[[UIColor whiteColor] set];
float height = [text mySizeWithFont:textFont].height / 2;
[text drawInRect:CGRectMake(0, rect.size.height / 2 - height, rect.size.width, rect.size.height / 2 + height) withFont:textFont lineBreakMode:NSLineBreakByCharWrapping alignment:NSTextAlignmentCenter];
}
}
What's wrong? How to fix crashes? Thanks a lot for any help!
It looks to me like you're calling your routine mySizeWithFont with an invalid font. Either one that has been released, or one that was never allocated. I'd put in NSLog breadcrumbs near your font allocation and just before the breadcrumbs to make sure your font is allocated first. If it is, it may be that ARC is tossing your font before you go to use it - may need #property(strong) or something like that.
My two cents: I had, in my app, an overrelease bug with a UIFont object. I'd invoke [UIFont systemFontOfSize:] and store the result in a file-static variable without retaining.
Up until iOS 7, I'd get away with it, then crashes in [sizeWithFont] started coming. Looks like iOS<7 would return font instances from a pool or a cache, so that a single unmatched release won't deallocate them. In iOS 7 - not anymore.

iDevice camera shows black instead of preview

I am developing an app that captures images from iDevice's camera and upload it to web service.
NO problem everything is working fine except the device's camera. Device's camera is driving my crazy. I am using below code to allow user to capture images. Sometimes camera shows preview and sometimes doesn't. Instead of preview is just shows complete darkness on screen. If I switch from rear to front camera is starts working fine. I have even trying deleting all background apps from device and clearing as much memory as I could; still no luck and I am stuck. :(
- (IBAction)addNewImage:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// Take picture from camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// set no to take as much pictures as user want.
imagePicker.showsCameraControls = YES;
// Show user the camera
[self presentModalViewController:imagePicker
animated:YES];
}
else
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker
animated:YES];
}
}
I have a customer who had this issue. They must have selected to not allow access to the camera. We had to change the camera privacy setting for the app in Settings. When we switched that back on, no more black camera screen.
I was facing the same issue in iOS7 for around a month, After a long long head breaking code review of the entire app, i was able to identify the problem.
I was enumerating an
IBOutletCollection(UILabel) NSArray *staticLabelsCollection;
array Concurrently updating the labels texts, which got executed simultaneously on multiple threads.
[self.labelsArr enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UILabel * label = (UILabel*)obj;
label.text=[NSString stringWithFormat:#"%d",idx+2];
}];
This created the problem of updating the UIKit elements on other than main thread.
I was able to catch the this issue by enabling the environment variable CA_DEBUG_TRANSACTIONS=1 in Xcode which generated warnings in device console
Nov 20 18:40:26 iPad2 CameraTest[1757] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0 QuartzCore 0x32a553b3 <redacted> + 266
1 QuartzCore 0x32a55269 <redacted> + 224
2 QuartzCore 0x32a56871 <redacted> + 24
3 QuartzCore 0x32a56eed <redacted> + 40
4 QuartzCore 0x32a619ed <redacted> + 412
5 QuartzCore 0x32a6184b <redacted> + 46
6 QuartzCore 0x32a61819 <redacted> + 44
7 UIKit 0x32ddfe53 <redacted> + 86
8 CameraTest 0x000923b5 __35-[ViewController blockEnumeration:]_block_invoke + 184
9 CoreFoundation 0x305aa821 <redacted> + 92
10 libdispatch.dylib 0x3b3308eb <redacted> + 134
11 libdispatch.dylib 0x3b32fd71 <redacted> + 220
12 libdispatch.dylib 0x3b32ff59 <redacted> + 56
13 libsystem_pthread.dylib 0x3b46adbf _pthread_wqthread + 298
14 libsystem_pthread.dylib 0x3b46ac84 start_wqthread + 8
Fixing these 'uncommited CATransactions' by forcing them to run on the main thread fixed the black camera issues.
I was able to fix it by removing Option: NSEnumerationConcurrent from enumeration.
The sample app which could constantly reproduce the problem can be downloaded here
Hope the sample app could give some insight and the work around for the issue.
I had faced this issue in my app. Though I never found out the what the issue was, I rewrote my code to define a property of UIIMagePickerController type and initialize it once in the getter. Used this property to initialize the camera view :
getter:
-(UIImagePickerController *) imagePicker{
if(!_imagePicker){
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
_imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
}
}
return _imagePicker;
}
- (IBAction)addNewImage:(id)sender{
if (self.imagePicker)
{
[self presentViewController:self.imagePicker animated:YES completion:^{}];
}
}
For some reason this got rid of the issue with preview sometimes showing a black screen
In ios7, you should set mainWindow.rootViewController = a class has kind is UIViewController. It's work for me.
If rootViewController is other, ex: UITabbarController, UINavigationController..., the black screen of camera will appear.

Memory Leak in libsystem_c.dylib strdup

Getting memory leak in instruments when i m trying to test app. In app when i test youtube video in UIWebView it shows malloc Memory Leak in libsystem_c.dylib responsible framse showing is strdup.
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/0Xa4bHcJu8";
//VideoViewController *videoViewController = [[[VideoViewController alloc] initWithNibName:nil bundle:nil] retain];
VideoViewController *videoViewController = [[VideoViewController alloc] init];
videoViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
videoViewController.videoURL = self.videoURL;
[self presentModalViewController:videoViewController animated:YES];
[videoViewController release];
}
EDIT:
Below is the stack trace:
0 libsystem_c.dylib malloc
1 libsystem_c.dylib strdup
2 libnotify.dylib token_table_add
3 libnotify.dylib notify_register_check
4 AVFoundation -[AVPlayer(AVPlayerMultitaskSupport) _iapdExtendedModeIsActive]
6 AVFoundation -[AVQueuePlayer init]
7 MediaPlayer -[MPQueuePlayer init]
23 MediaPlayer -[UIMoviePlayerController setAutoRotationMask:]
24 QuickTime Plugin 0x89473ce
27 QuickTime Plugin 0x894f3bc
28 libdispatch.dylib _dispatch_call_block_and_release
29 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$mp
30 CoreFoundation __CFRunLoopRun
32 CoreFoundation CFRunLoopRunInMode
33 GraphicsServices GSEventRunModal
34 UIKit UIApplicationMain
Anyone can tell why the leak is and what is the cause.
Thanks.
Tried googling for similar problems? I just did, and I found this:
iOS libsystem_c.dylib strdup memory leak NSZombie not working
To summarise, it may be a leak in a library you're not responsible for. If that's the case, and it's a tiny one-off leak, don't sweat it.

My App Crashed when trying to get Contents Of URL

my app crashed when nsstring getting contents of URL.
website = [NSString stringWithFormat:#"hidden."];
contents = [NSString stringWithContentsOfURL:[NSURL URLWithString:website] encoding:NSUTF8StringEncoding error:nil];
the crash log is:
void _WebThreadLockFromAnyThread(bool), 0x865cc40: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
2012-07-10 11:15:17.654 MyApplication[1505:19407] OK // some output
2012-07-10 11:15:17.660 MyApplication[1505:19407] bool _WebTryThreadLock(bool), 0x865cc40: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1 WebThreadLock
2 -[UITextRangeImpl isEmpty]
3 -[UITextRange(UITextSelectionAdditions) _isCaret]
4 -[UITextSelectionView setCaretBlinks:]
5 -[UIKeyboardImpl setCaretBlinks:]
6 -[UIKeyboardImpl setDelegate:force:]
7 -[UIKeyboardImpl setDelegate:]
8 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
9 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews]
10 -[UIResponder(Internal) _windowBecameKey]
11 -[UITextField _windowBecameKey]
12 -[UIWindow makeKeyWindow]
13 -[UIWindow makeKeyAndVisible]
14 -[MyApplicationAppDelegate checkLogin]
15 -[NSThread main]
16 __NSThread__main__
17 _pthread_start
18 thread_start
the code is called with [self performSelectorInBackground:#selector(checkLogin) withObject:nil]; from IBAction. what i am doing wrong?
(Xcode 4.3, Mac OS X Lion, iPhone Simulator 5.1)
According to that error message, you're trying to update a UIKit object from a background thread, and the UI can only be updated from the main thread.
Instead, use self performSelectorOnMainThread to call back to the main thread to update your UI with whatever information you received when your web call returns.
From your main thread:
[self performSelectorInBackground:#selector(checkLogin) withObject:nil];
In the background:
- (void)checkLogin {
// Do web stuff
...
[self performSelectorOnMainThread:#selector(updateUI)
withObject:nil
waitUntilDone:NO];
}
- (void)updateUI {
[statusLabel setText:#"Done!"];
}
Try using
- (id)performSelector:(SEL)aSelector withObject:(id)anObject.

UITextView textViewShouldBeginEditing crashes when tapped more than once

I have a UIViewController. In this controller I programmatically create a UITextView and set its delegate as my controller. I do this because I dont want to start editing the textView when I tap it.
ViewDidLoad method
UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(9, 10, 302, 200)];
[textView setDelegate:self];
[self.view addSubview:textView];
[textView release];
I implemented the textViewShouldBeginEditing method to return NO here to disable the keyboard from showing up.
textViewShouldBeginEditing method
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(#"Shouldbegin");
return NO;
}
The problem that appears
When I tap the textView it works once, but if i tap it again it will crash the application without any log. The weird thing when I hold the textView and release it, it will work like I want it to work. A normal single tap on the other hand doesn't work a second time.
Edit
Single tapping quickly after each other also seems to work, so it seems that it wont work after i wait x seconds.
After some testing I found out it seems to be an iOS 5.X > bug. When running my App in a 4.3 device/simulator it works like it should. The error log on a iOS 5.1 device says the following:
Date/Time: 2012-04-17 14:00:49.497 +0200
OS Version: iPhone OS 5.1 (9B176)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000014
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 TextInput 0x36bf69e8 TI::Favonius::BeamSearch::choose_hit_test_node(WTF::RefPtr<TI::Favonius::SearchNode> const&, WTF::RefPtr<TI::Favonius::KeyAreaNode> const&, WTF::RefPtr<TI::Favonius::SearchNode> const&, WTF::RefPtr<TI::Favonius::SearchNode> const&) + 12
1 TextInput 0x36bf6d1e TI::Favonius::BeamSearch::update_for_touch(unsigned int, WTF::PassRefPtr<TI::Favonius::KeyAreaNode>) + 602
2 TextInput 0x36bfb5c2 TI::Favonius::StrokeBuildManager::update_search_for_touch(unsigned int, int) + 66
3 TextInput 0x36bfb97c TI::Favonius::StrokeBuildManager::key_down_or_drag_hit_test_for_UI(bool, CGPoint, double, int, int, float, bool, ZT::LayoutDictionaryContext&, bool, int) + 216
4 TextInput 0x36bddf54 TIInputManagerZephyr::simulate_touches_for_input_string() + 344
5 TextInput 0x36bed8ba -[TIKeyboardInputManagerZephyr candidates] + 214
6 UIKit 0x31066616 -[UIKeyboardImpl generateAutocorrectionReplacements:] + 82
7 UIKit 0x31108a96 __71-[UITextInteractionAssistant scheduleReplacementsForRange:withOptions:]_block_invoke_0 + 370
8 UIKit 0x3110ec62 -[UITextSelectionView calculateAndShowReplacements:] + 6
9 Foundation 0x3762192c __NSFireDelayedPerform + 408
10 CoreFoundation 0x361a1a2c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
11 CoreFoundation 0x361a1692 __CFRunLoopDoTimer + 358
12 CoreFoundation 0x361a0268 __CFRunLoopRun + 1200
13 CoreFoundation 0x3612349e CFRunLoopRunSpecific + 294
14 CoreFoundation 0x36123366 CFRunLoopRunInMode + 98
15 GraphicsServices 0x324e3432 GSEventRunModal + 130
16 UIKit 0x30e70e76 UIApplicationMain + 1074
I did find a solution. I don't really like working around Apple bugs but sometimes you have to. It is three steps...
1) replace the default keyboard with an invisible view
- (void)viewDidLoad
{
[super viewDidLoad];
myTextView.inputView = customKeyboard;
}
2) answer YES to allow editing
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
return YES;
}
3) In textViewDidChangeSelection resign the first responder to hide the cursor
- (void)textViewDidChangeSelection:(UITextView *)textView{
[textView resignFirstResponder];
}
If you don't want to start editing of UITextView when you tapped it:
UITextView* textView = ...;
textView.editable = NO;
After some testing I found out it seems to be an iOS 5.X > bug. When running my App in a 4.3 device/simulator it works like it should.
Look in my main post where i edited the logfile.
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
[txtView resignFirstResponder];
}
and release txtView in dealloc method
Swift 4.2
The best and easy way to solve this just make undo manager as false
textView.undoManager?.disableUndoRegistration()
This error appears if you have change the view at run time like within the table, and cell will be reloaded on tapping,