I am running a background thread to get data from a web service.
To get the settings needed for creating the URL I am using this method:
+(Settings *)getSettings
{
Settings *settings = [[Settings alloc] init];
NSString *path = [NSString stringWithFormat:@"Documents/Settings"];
NSString *settingsPath = [NSHomeDirectory() stringByAppendingPathComponent:path];
NSFileManager *fileMgr = [NSFileManager defaultManager];
if ([fileMgr fileExistsAtPath:settingsPath]) {
NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:settingsPath];
settings.username = [settingsDictionary objectForKey:@"username"];
settings.module = [settingsDictionary objectForKey:@"module"];
settings.websiteUrl = [settingsDictionary objectForKey:@"websiteUrl"];
}else
{
settings.username = @"";
settings.module = @"";
settings.websiteUrl = @"";
}
NSLog(@"Settings = u:%@ m:%@ w:%@",settings.username,settings.module,settings.websiteUrl);
return settings;
}
This works fine in the debugger but when i run it on the device i get BAD_EXCESS on the NSLog or on any class that tries to use the data with the warning:
warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn’t in the frame.
This is the code works fine on the device if I step through the code.
Any ideas?
Edit:
Backtrace –
#0 0x37a97eda in objc_retain ()
#1 0x37aa4be4 in objc_retainAutoreleasedReturnValue ()
#2 0x0000f84a in +[SettingData getSettings] (self=0x175e4, _cmd=0x11af9) at /Users/Jono/Dropbox/Uni/iOS5/Feedback At Tees/Feedback At Tees/SettingData.m:49
#3 0x0000fa86 in -[DataManager init] (self=0x3509e0, _cmd=0x30fd9f96) at /Users/Jono/Dropbox/Uni/iOS5/Feedback At Tees/Feedback At Tees/DataManager.m:19
#4 0x00003b46 in __35-[MasterViewController viewDidLoad]_block_invoke_0 (.block_descriptor=0x185f40) at /Users/Jono/Dropbox/Uni/iOS5/Feedback At Tees/Feedback At Tees/MasterViewController.m:70
#5 0x30b08d54 in _dispatch_call_block_and_release ()
#6 0x30b0b896 in _dispatch_worker_thread2 ()
#7 0x37a0e1ce in _pthread_wqthread ()
#8 0x37a0e0a4 in start_wqthread ()
I tried adding the following to the init method of settings and if i step through it is ok if i dont it crashes on the second NSLog with the error: message sent to deallocated instance 0x160d60
-(id)init
{
if ((self=[super init]))
{
NSString *path = [NSString stringWithFormat:@"Documents/Settings"];
NSString *settingsPath = [NSHomeDirectory() stringByAppendingPathComponent:path];
NSFileManager *fileMgr = [NSFileManager defaultManager];
if ([fileMgr fileExistsAtPath:settingsPath])
{
NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:settingsPath];
self.username = [settingsDictionary objectForKey:@"username"];
self.module = [settingsDictionary objectForKey:@"module"];
self.websiteUrl = [settingsDictionary objectForKey:@"websiteUrl"];
NSLog(@"Settings = u:%@ m:%@ w:%@",self.username,self.module,self.websiteUrl);
}
else
{
self.username = @"";
self.module = @"";
self.websiteUrl = @"";
}
}
NSLog(@"Settings = u:%@ m:%@ w:%@",self.username,self.module,self.websiteUrl);
return self;
}
Screenshot:
http://postimage.org/image/4vw6uq7pp/
First, the method should be
retrieveSettingsordownloadSettingsor, just,settings, but notgetSettingsasgetas a prefix has a very particular meaning regarding the argumentation of the method (pass by reference).Secondly, there is nothing obviously wrong with that code
(save for the leak of. (I see that ARC is enabled).settings, but that won’t cause this kind of a crash)Finally, if you have a crash then post the backtrace. The error message you are seeing (“USE_BLOCK_IN_FRAME”) indicates that the code you posted has nothing to do with the crash.
Odd crash, that. OK — the warning is from the debugger and doesn’t have anything to do with the actual error.
The scope boundary is often where the compiler will emit
releaseand/or drain autorelease pools.Which leads to the next question; how are
OK — so, it doesn’t work when you run at full speed and does work when running step-by-step. Smells like a concurrency crash. Can you post a screenshot of the actual crash? I.e. are you sure that particular backtrace is the backtrace of the crash and not where the debugger happened to be at the time of the crash?
(Yes, grasping at straws slightly — this crash doesn’t make sense with the evidence shown. I like puzzles.)
OK — now we are getting somewhere. Sort of. It crashes outside the if’s scope after successfully logging the same thing inside the if’s scope.
How are
username,moduleandwebsiteURLdefined? Are theystrongor, most appropriately,copy@propertydeclarations?