I am creating a workflow to navigate through websites, every step of the workflow has to load n frames and then knows its ready (I have to implement the timeout).
I don’t understand why [self next] is giving me this error:
* -[WebWorkflow next]: message sent to deallocated instance 0x105796ef0
Considering this delegate function:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
frameCounter++;
NSInteger frames = [(WebWorkflowStep *)[steps objectAtIndex:index] frames];
NSLog(@"Frame counter %ld of %ld", frameCounter, frames);
[self next];
}
And this next method:
-(void) next
{
if ( index < [steps count])
{
frameCounter = 0;
index = index + 1;
WebWorkflowStep *step = [steps objectAtIndex:index-1];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:step forKey:@"selector"];
[[NSNotificationCenter defaultCenter] postNotificationName:EVENT_WORKFLOW_NEXT object:nil userInfo:userInfo];
}
}
Notes:
– WebWorflow a.k.a ‘self’ has been created/binded by another class with strong
Like so:
@interface AController : NSObject <APIProtocol>
{
WebView *webview;
NSMutableArray *accounts;
WebWorkflow *workflow;
}
@property (strong) WebWorkflow *workflow;
...
I do create the workflow like this:
workflow = [[WebWorkflow alloc] initWithWebView:webview];
NSArray *getPicturesWorkflow = [NSArray arrayWithObjects:
[[WebWorkflowStep alloc] initWithSelector:@"open" andLoadFrames:0],
[[WebWorkflowStep alloc] initWithSelector:@"login" andLoadFrames:2],
[[WebWorkflowStep alloc] initWithSelector:@"getPictures" andLoadFrames:8],
nil];
[workflow setSteps:getPicturesWorkflow];
And it gets initialized like:
-(id)initWithWebView:(WebView *)webview
{
self = [ super init];
if(self) {
timeout = 10;
index = 0;
web = webview;
frameCounter = 0;
[web setFrameLoadDelegate:self];
}
return self;
}
The AController instance owns a web view and is the web view’s delegate. The AController instance is getting released (for some reason…we’d need to see how it’s owner manages it). Since it might get released during a load, it should clean up after itself as follows:
This will prevent the crash. It will also abandon the load. If you don’t want to do that, you’ll need to figure out why the AController instance is being released.
The first step in doing that would be a breakpoint in the dealloc method.