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/