ios - Collection mutated while being enumerated crash in a switch case -
i'm using library srwebsocket , have following crash: there seems no loop except main srwebsocket loop calling handlemessage:
fatal exception: nsgenericexception *** collection <_nsfaultingmutableset: 0x14f60ced0> mutated while being enumerated. fatal exception: nsgenericexception 0 corefoundation 0x181e0ae38 __exceptionpreprocess 1 libobjc.a.dylib 0x18146ff80 objc_exception_throw 2 corefoundation 0x181e0a86c -[nsexception name] 3 appname 0x1002507b0 -[websocketclient notification:] (websocketclient.m:534) 4 appname 0x10024fa68 -[websocketclient websocket:didreceivemessage:] (websocketclient.m:223) 5 appname 0x10017c260 __30-[srwebsocket _handlemessage:]_block_invoke (srwebsocket.m:741) 6 libdispatch.dylib 0x1818554bc _dispatch_call_block_and_release 7 libdispatch.dylib 0x18185547c _dispatch_client_callout 8 libdispatch.dylib 0x18185ab84 _dispatch_main_queue_callback_4cf 9 corefoundation 0x181dc0dd8 __cfrunloop_is_servicing_the_main_dispatch_queue__ 10 corefoundation 0x181dbec40 __cfrunlooprun 11 corefoundation 0x181ce8d10 cfrunlooprunspecific 12 graphicsservices 0x1835d0088 gseventrunmodal 13 uikit 0x186fbdf70 uiapplicationmain 14 appname 0x1003201e4 main (appdelegate.swift:18) 15 libdispatch.dylib 0x1818868b8 (missing)
first call in srwebsocket:
- (void)_handlemessage:(id)message { srfastlog(@"received message"); [self _performdelegateblock:^{ [self.delegate websocket:self didreceivemessage:message]; }]; }
- delegate class websocketclient -
first function call:
- (void)websocket:(srwebsocket *)websocket didreceivemessage:(id)message { nsdictionary *dict = [message objectfromjsonstring]; int code = [[dict objectforkey:@"msgcode"] intvalue]; messagetype messagetype = [[dict objectforkey:@"msgtype"] intvalue]; if (self.loginblock != nil && _autologining == no) { [self feedbackloginblock:dict]; [self sendtoken]; }else{ switch (messagetype) { case messagetypereply: { nsstring *matchidentify = [dict objectforkey:@"msgid"]; [self checkwaitingblockqueue:matchidentify code:code message:dict]; } break; case messagetypereceivemessage:{ [self parsereadmessagefeedback:dict]; nsinteger receiveint = self.receivenumber.intvalue; receiveint ++; self.receivenumber = [nsnumber numberwithinteger:receiveint]; } break; case messagetypeaddgroup:{ [self addmembertogroup:dict]; } break; case messagetypedeletegroup:{ [self deletememberfromgroup:dict]; } break; case messagetypenotifymsgtype:{ nsdictionary *content = [dict objectforkey:@"datacontent"]; [self notification:content]; <<< line 223 } } }
second call:
- (void)sendmessage:(message *)message resultblock:(messagereplyblock )block { messageblock *messageblock = [self createmessageblock:block]; [_waitingblockqueue addobject:messageblock]; nsnumber *push; if(message.belongtosession.withsomebody) { push = [nsnumber numberwithint:1]; }else{ push = [nsnumber numberwithint:0]; } nsmutabledictionary *dict = [nsmutabledictionary dictionarywithobjectsandkeys: messageblock.matchmessageid, @"matchid", message.messagetype, @"msgtype", message.sourcetype, @"msgsourcet", message.textcontent, @"msgtextcontent", _currentuser.contactid, @"from", push, @"push", nil]; messagetype messagetype = [message.messagetype integervalue]; messagesourcetype sourcetype = [message.sourcetype integervalue]; nsnumber *tocontactid = message.touser.contactid; if (tocontactid == nil) { return; } if ([message.whispertype isequaltonumber:@1]) { [dict setobject:@1 forkey:@"option"]; [dict setobject:message.whispertimecount forkey:@"msgtimer"]; } switch (messagetype) { case messagetypeimage: { [dict setobject:message.bigimagepath forkey:@"msgbigsrc"]; [dict setobject:message.smallimagepath forkey:@"msgsmallsrc"]; <<< line 534 } break; case messagetypeofflineaudio: { [dict setobject:message.websourcepath forkey:@"msgurl"]; [dict setobject:message.voicetime forkey:@"msgvoicetime"]; } break; case messagetypemap: { nsstring *latitude = [message.latitude stringvalue]; nsstring *longitude = [message.longitude stringvalue]; if (latitude.length > 0 && longitude.length > 0) { [dict setobject:latitude forkey:@"lat"]; [dict setobject:longitude forkey:@"lng"]; } } break; default: break; } switch (sourcetype) { case messagesourcetypep2p: { [dict setobject:tocontactid forkey:@"to"]; } break; case messagesourcetypegroup: { [dict setobject:tocontactid forkey:@"gid"]; } break; default: break; } nsdata *data = [nsjsonserialization datawithjsonobject:dict options:0 error:nil]; if(isconnected) [_websocket send:data]; else [self reconnect]; }
update notification: method
- (void)notification:(nsdictionary *)dict { [[notificationmanager sharedmanager] reloadrequestscount]; [[notificationmanager sharedmanager] reloadnotificationcount]; if (dict != nil) { notificationtype type = [[dict objectforkey:@"notificationtype"] intvalue]; nsnumber *contactid = [dict objectforkey:@"notificationcreatorid"]; if ([contactid iskindofclass:[nsstring class]]) { contactid = [nsnumber numberwithlonglong:[contactid longlongvalue]]; } [[settingmanager sharedsettingmanager] playsoundwhenmessagereceived:contactid]; switch (type) { case notificationtypeaddfriend: case notificationtypeacceptfriend: { friend *myfriend = [fetchreq fetchfriendwithfriendid:contactid owneruserid:_contactid]; if (myfriend == nil){ if(type == notificationtypeacceptfriend) { nsnumber *notificationid = [dict objectforkey:@"notificationid"]; [fetchreq notificationwithnotificationid:notificationid]; } }else{ myfriend.sendingrequest = @no; myfriend.friend.sendingrequest = @no; [appdelegate savecontext]; } } break; case notificationtypedeletefriend: { user *user = [fetchreq fetchuserwithuserid:contactid]; userentity *entity = [[userentity alloc] initwithuser:user]; entity.user = user; [entity removewithrelated]; break; } default: { nsnumber *notificationid = [dict objectforkey:@"notificationid"]; [fetchreq notificationwithnotificationid:notificationid]; } break; } } [appdelegate savecontext]; }
Comments
Post a Comment