MegaBits / SIOSocket

Realtime iOS application framework (client) http://socket.io
MIT License
494 stars 80 forks source link

I'm running into WebThread issues #36

Open dhilowitz opened 9 years ago

dhilowitz commented 9 years ago

Hi,

I'm running v0.2.2 of SIOSocket, and I'm getting an EXC_BAD_ACCESS exception in WebThread. Here's an XCode screenshot:

screenshot

I have a callback function set up so that when I receive an event called "chatMessage" I run a block of code. Something like this:

[self.socket on: @"chatMessage" callback: ^(SIOParameterArray *args) {
    [self chatMessageReceived];
}];

This in calls a function which updates a badge counter on a bar button like so:

self.chatBarButton.badgeValue = [NSString stringWithFormat:@"%d", _unreadChatMessages];

Which is accomplished in the bar button code as follows:

[UIView animateWithDuration:duration animations:^{
    [self updateBadgeFrame];
}];

Looking at the inspector, it seems as thought UIView is not defined? Is this because we are running in the wrong thread?

dhilowitz commented 9 years ago

OK. I think I've worked around the issue by forcing the contents of the callback block into the main thread:

 [self.socket on: @"chatMessage" callback: ^(SIOParameterArray *args)
 {
     [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
         [self chatMessageReceived];
     }];
 }];
jonathannorris commented 9 years ago

Checkout the discussion in #16 there are serious threading issues right now. I'll try and get a proper pull request in soon, but I have the threading issues mostly resolved in this branch: https://github.com/syrp/SIOSocket