Question about exc_bad_acces

608 views
Skip to first unread message

Charles Leonhart

unread,
Feb 2, 2011, 4:54:18 AM2/2/11
to ASIHTTPRequest
I made some demo to retrieve some text from the server using
Asinetworkqueue, and show it on the UITableView (Using UINavigation).
Let's say i have one table for showing all the text and when i click
the row, it goes to some view (Using UIView)
the program look like this :

/**** Code here *****/
NSURL *url = [NSURL URLWithString:@"http://test.myasianhobby.com/"];
ASIFormDataRequest *request = [ASIFormDataRequest
requestWithURL:url];
[request setDelegate:self];
[request setRequestMethod:@"POST"];
[request setPostValue:"4" forKey:@"message_id"];
[request setPostValue:"1" forKey:@"user_id"];


[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];

if (!networkQueue2)
{
networkQueue2 = [[ASINetworkQueue alloc] init];
}

[networkQueue2 reset];
[networkQueue2
setRequestDidFinishSelector:@selector(getReplyDataCompleted:)];
[networkQueue2
setRequestDidFailSelector:@selector(getReplyDataFailed:)];
[networkQueue2 setDelegate:self];
[networkQueue2 addOperation:request];
[networkQueue2 go];
/*************************/

I handling the finish selector by doing this :
/******** Code here ********/

- (void) getReplyDataCompleted : (ASIHTTPRequest*)request
{
NSError *error;
SBJSON *json = [[SBJSON new] autorelease];
NSString *response = [request responseString];
etc..
}

/************************/

This code running perfectly fine but i got the error when i tap back
and forth between the table content and the uiview...
The error is like this :


#0 0x33479466 in objc_msgSend
#1 0x00018e22 in -[ASIHTTPRequest reportFinished] at ASIHTTPRequest.m:
1951
#2 0x33a5ebbe in -[NSObject(NSObject) performSelector:withObject:]
#3 0x33639794 in __NSThreadPerformPerform
#4 0x33a767dc in
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
#5 0x33a485b6 in __CFRunLoopDoSources0
#6 0x33a47e5a in __CFRunLoopRun
#7 0x33a47c86 in CFRunLoopRunSpecific
#8 0x33a47b8e in CFRunLoopRunInMode
#9 0x33b0e4aa in GSEventRunModal
#10 0x33b0e556 in GSEventRun
#11 0x32099328 in -[UIApplication _run]
#12 0x32096e92 in UIApplicationMain
#13 0x00002ef6 in main at main.m:14

when i look at it..it is out of scope..can someone help me how to
handle this...
I already tried to retain all the variable, and release it when the
request is finished..but still cannot getting the solution.
I hope someone can help me..thanks in advance

Best Regards,

Charles

Joseph Heenan

unread,
Feb 2, 2011, 7:32:25 AM2/2/11
to asihttp...@googlegroups.com
On 02/02/2011 09:54, Charles Leonhart wrote:
I made some demo to retrieve some text from the server using
Asinetworkqueue, and show it on the UITableView (Using UINavigation).
Let's say i have one table for showing all the text and when i click
the row, it goes to some view (Using UIView)
the program look like this :

/**** Code here *****/
NSURL *url = [NSURL URLWithString:@"http://test.myasianhobby.com/"];
	ASIFormDataRequest *request = [ASIFormDataRequest
requestWithURL:url];
	[request setDelegate:self];
	[request setRequestMethod:@"POST"];
	[request setPostValue:"4" forKey:@"message_id"];
	[request setPostValue:"1" forKey:@
"user_id"];
/*************************/

I handling the finish selector by doing this :
/******** Code here ********/

- (void) getReplyDataCompleted : (ASIHTTPRequest*)request
{
	NSError *error;
	SBJSON *json = [[SBJSON new] autorelease];
	NSString *response = [request responseString];
	etc..
 }

/************************/

This code running perfectly fine but i got the error when i tap back
and forth between the table content and the uiview...
The error is like this :

It looks like ASIHTTPRequest is trying to call your delegate after it has been freed.

You need to make sure that, in the delegate's dealloc method, the delegate is removed from any ASIHTTPRequests.

The normal way to do this is to retain the request in a member variable, and in dealloc call:
   [request clearDelegatesAndCancel];
   [request release];

There are other possible approaches, eg. you could remove the delegates for all items in your queues.



Joseph



Charles Leonhart

unread,
Feb 2, 2011, 7:57:26 AM2/2/11
to ASIHTTPRequest
Thx for your reply Joseph.
I'll try it right now..
Thx, i really appreciate it.
I'll post the result later.

Best regards,
Charles Hariyadi

charles leonhart

unread,
Feb 6, 2011, 9:37:54 AM2/6/11
to ASIHTTPRequest
After trying so many ways, i even made a cleardelegate to the request but i cannot find how to fix the error..

Could someone help me to sove it here is the report i got..
The getReplyDataCompleted is the method called for the setrequestDidFinishSelector

****************************** error message ******************************
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextMagnifierRanged getReplyDataCompleted:]: unrecognized selector sent to instance 0x180260'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x33ac0987 __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x3347b49d objc_exception_throw + 24
    2   CoreFoundation                      0x33ac2133 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x33a69aa9 ___forwarding___ + 508
    4   CoreFoundation                      0x33a69860 _CF_forwarding_prep_0 + 48
    5   CoreFoundation                      0x33a5ebbf -[NSObject(NSObject) performSelector:withObject:] + 22
    6   FeatureFive                         0x0001aec3 -[ASINetworkQueue requestFinished:] + 98
    7   CoreFoundation                      0x33a5ebbf -[NSObject(NSObject) performSelector:withObject:] + 22
    8   FeatureFive                         0x0000eb99 -[ASIHTTPRequest reportFinished] + 112
    9   CoreFoundation                      0x33a5ebbf -[NSObject(NSObject) performSelector:withObject:] + 22
    10  Foundation                          0x33639795 __NSThreadPerformPerform + 268
    11  CoreFoundation                      0x33a767dd __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
    12  CoreFoundation                      0x33a485b7 __CFRunLoopDoSources0 + 382
    13  CoreFoundation                      0x33a47e5b __CFRunLoopRun + 230
    14  CoreFoundation                      0x33a47c87 CFRunLoopRunSpecific + 230
    15  CoreFoundation                      0x33a47b8f CFRunLoopRunInMode + 58
    16  GraphicsServices                    0x33b0e4ab GSEventRunModal + 114
    17  GraphicsServices                    0x33b0e557 GSEventRun + 62
    18  UIKit                               0x32099329 -[UIApplication _run] + 412
    19  UIKit                               0x32096e93 UIApplicationMain + 670
    20  FeatureFive                         0x00002a49 main + 48
    21  FeatureFive                         0x00002a14 start + 40
)


Thanks for replying,
Best Regards,
Charles hariyadi

--
You received this message because you are subscribed to the Google Groups "ASIHTTPRequest" group.
To post to this group, send email to asihttp...@googlegroups.com.
To unsubscribe from this group, send email to asihttpreques...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/asihttprequest?hl=en.




--
regards,
Charles Hariyadi
v_ne...@yahoo.co.id
Informatics Engineering
School of Electric and Informatics Engineering

Joseph Heenan

unread,
Feb 6, 2011, 10:07:43 AM2/6/11
to asihttp...@googlegroups.com
Hi Charles,

Looks like the same kind of problem but with the queue instead - try clearing the delegate for all the queues too.

Regards,

Joseph

charles leonhart

unread,
Feb 6, 2011, 10:30:06 AM2/6/11
to asihttp...@googlegroups.com
Dear Joseph,

I already tried to release the networkqueue (there's no cleardelegate for queue) and then i got the error :
Program received signal:  “EXC_BAD_ACCESS”.
Are there something error with my code?
I just go back and forth between two navigation controller view.
The first view use some queue to post request to server (asynchronously)
and the second view also use some queue (local to that view) to post and get something from the server (asynchronously too).
and sometimes between this transition (it means the queue loaded..it got crashed).
Btw, thx for your kind response Joseph

Best regards,
Charles Hariyadi

Joseph Heenan

unread,
Feb 6, 2011, 10:32:45 AM2/6/11
to asihttp...@googlegroups.com
Hi Charles,

On 06/02/2011 15:30, charles leonhart wrote:
>
> I already tried to release the networkqueue (there's no cleardelegate
> for queue) and then i got the error :

> Program received signal: �EXC_BAD_ACCESS�.


> Are there something error with my code?

Try adding [queue setDelegate:nil]; before you release the network queue.

Cheers,

Joseph

charles leonhart

unread,
Feb 6, 2011, 10:44:35 AM2/6/11
to asihttp...@googlegroups.com
Dear Joseph

in the dealloc i add this...
    [networkQueue setDelegate:nil];
    [networkQueue release];


after trying for 1-2 minutes.. going between one view controller and another
i got the error again :

- (void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders
{
    if ([self error] || [self mainRequest]) {
        return;
    }

    if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) {
        [delegate performSelector:didReceiveResponseHeadersSelector withObject:self withObject:newResponseHeaders]; <-- out of scope.
    }

the didReceiveResponseHeadersSelector go out of scope.

Best regards,

Charles

On Sun, Feb 6, 2011 at 10:32 PM, Joseph Heenan <jos...@heenan.me.uk> wrote:
Hi Charles,


On 06/02/2011 15:30, charles leonhart wrote:

I already tried to release the networkqueue (there's no cleardelegate for queue) and then i got the error :
Program received signal:  “EXC_BAD_ACCESS”.

Are there something error with my code?
Try adding [queue setDelegate:nil]; before you release the network queue.

Cheers,


Joseph

--
You received this message because you are subscribed to the Google Groups "ASIHTTPRequest" group.
To post to this group, send email to asihttp...@googlegroups.com.
To unsubscribe from this group, send email to asihttpreques...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/asihttprequest?hl=en.

Joseph Heenan

unread,
Feb 6, 2011, 10:50:10 AM2/6/11
to asihttp...@googlegroups.com
Hi Charles,

On 06/02/2011 15:44, charles leonhart wrote:
> Dear Joseph
>
> in the dealloc i add this...
> [networkQueue setDelegate:nil];
> [networkQueue release];
>

Looks right.


>
> after trying for 1-2 minutes.. going between one view controller and
> another
> i got the error again :
>
> - (void)requestReceivedResponseHeaders:(NSMutableDictionary
> *)newResponseHeaders
> {
> if ([self error] || [self mainRequest]) {
> return;
> }
>
> if (delegate && [delegate
> respondsToSelector:didReceiveResponseHeadersSelector]) {
> [delegate performSelector:didReceiveResponseHeadersSelector
> withObject:self withObject:newResponseHeaders]; <-- out of scope.
> }
>
> the didReceiveResponseHeadersSelector go out of scope.

This seems to be a different error again - this looks like you're back
to a problem with a request delegate not being cleared.

If you're already calling clearDelegateAndCancel in the dealloc, then
all check any other places you assign to the "request" member variable
and/or property - each time you assign to it, you must clear the
delegate for the old value first.

Joseph

charles leonhart

unread,
Feb 6, 2011, 12:07:40 PM2/6/11
to asihttp...@googlegroups.com
Dear Joseph,

I already try to release all the request ( i use ASIFormDataRequest and i don't retain the request because i initialize it and allocate it locally inside the method), i put it inside the method where it initializes and then i still get the error. Always goes to the EXC_BAD_ACCESS. Thanks for your kind reply.

Best Regards,

Charles Hariyadi.



Joseph

--
You received this message because you are subscribed to the Google Groups "ASIHTTPRequest" group.
To post to this group, send email to asihttp...@googlegroups.com.
To unsubscribe from this group, send email to asihttpreques...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/asihttprequest?hl=en.

Joseph Heenan

unread,
Feb 6, 2011, 12:22:44 PM2/6/11
to asihttp...@googlegroups.com
Hi Charles,

If you're still seeing the crash happen in the same place then you still have the same issue: there is an instance of ASIHTTPRequest (or ASIFormDataRequest) that is running and where the delegate field is set to a class that no longer exists.

There are lots of different ways you can guarantee that this doesn't occur (and it's very difficult to advise on what design pattern you should follow as it will depend on how you've designed the rest of your application) but fundamentally you need to make sure that you never end up with the ASIHTTPRequest delegate field point to an invalid object.

One way would be to retain the requests and then in the dealloc method for your class clear the delegate before releasing the request - that is the way I usually use.

If you change your code so that your code is providing the above guarantee, then ASIHTTPRequest will not crash any more.

Regards,

Joseph

charles leonhart

unread,
Feb 6, 2011, 12:31:47 PM2/6/11
to asihttp...@googlegroups.com
Dear Joseph,

I'll try to look my code again. I'll post the result later.Thanks for your kind advice

Best regards,
Charles

charles leonhart

unread,
Feb 6, 2011, 12:34:45 PM2/6/11
to asihttp...@googlegroups.com
Dear Joseph,

Oh yeah, i always got the error when i'm running the code on iphone and using 3g connection. With WIFI sometime it crashes, with 3g always crashes and with simulator never crashes.

Best regards,
Charles

charles leonhart

unread,
Feb 7, 2011, 5:34:18 PM2/7/11
to asihttp...@googlegroups.com
Dear Joseph,

Ok, solved the problem,

use the setnetworkqueue:nil
and never set delegate to your request.
Thanks for your response Joseph.

Best regards,
Charles
Reply all
Reply to author
Forward
0 new messages