internal crash when parsing a message

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 15 Dec 2020, 08:02

Hi,
in the stack trace you posted I don't see any reference to an NSRangeException. Where did you get that?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 15 Dec 2020, 08:15

Code: Select all

Fatal Exception: NSRangeException
*** -[NSConcreteMutableData getBytes:range:]: range {140, 128} exceeds data length 143
Fatal Exception: NSRangeException
0  CoreFoundation                 0x192482114 __exceptionPreprocess
1  libobjc.A.dylib                0x1a5d1ecb4 objc_exception_throw
2  Foundation                     0x19365cb48 -[NSString hash]
3  BigCasino                      0x101071cf8 -[Data readUTF] + 127 (Data.m:127)
4  BigCasino                      0x10107514c -[DefaultSFSDataSerializer decodeSFSObject:] + 355 (DefaultSFSDataSerializer.m:355)
5  BigCasino                      0x10107812c -[DefaultSFSDataSerializer binary2object:] + 790 (DefaultSFSDataSerializer.m:790)
6  BigCasino                      0x101099348 +[SFSObject newFromBinaryData:] + 36 (SFSObject.m:36)
7  BigCasino                      0x10109e284 -[SFSProtocolCodec onPacketRead:] + 88 (SFSProtocolCodec.m:88)
8  BigCasino                      0x1010971f4 -[SFSIOHandler handlePacketData:] + 94 (SFSIOHandler.m:94)
9  BigCasino                      0x101098520 -[SFSIOHandler onDataRead:] + 244 (SFSIOHandler.m:244)
10 BigCasino                      0x101066590 -[BitSwarmClient stream:handleEvent:] + 466 (BitSwarmClient.m:466)
11 CoreFoundation                 0x19241d68c _signalEventSync
12 CoreFoundation                 0x19241a784 _cfstream_solo_signalEventSync
13 CoreFoundation                 0x19241a53c _CFStreamSignalEvent
14 CFNetwork                      0x192b598dc _CFStreamErrorFromCFError
15 CFNetwork                      0x192b60748 _CFStreamErrorFromCFError
16 CoreFoundation                 0x19240c478 __CFSocketPerformV0
17 CoreFoundation                 0x192402240 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
18 CoreFoundation                 0x192402140 __CFRunLoopDoSource0
19 CoreFoundation                 0x192401488 __CFRunLoopDoSources0
20 CoreFoundation                 0x1923fba40 __CFRunLoopRun
21 CoreFoundation                 0x1923fb200 CFRunLoopRunSpecific
22 GraphicsServices               0x1a8578598 GSEventRunModal
23 UIKitCore                      0x194cc4bcc -[UIApplication _run]
24 UIKitCore                      0x194cca1a0 UIApplicationMain
25 BigCasino                      0x1013b9490 gameplay::Platform::enterMessagePump() + 1720 (PlatformiOS.mm:1720)
26 BigCasino                      0x1013a0cd4 main + 135 (gameplay-main-ios.mm:135)
27 libdyld.dylib                  0x1920da588 start
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 15 Dec 2020, 15:52

Thanks, it wasn't clear what the exception was exactly.
What we could do is catch the exception and re-throw it as something different, like a custom SFS exception instead.

Would that help?
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 16 Dec 2020, 10:03

Can't you call a new callback let's say onConnectionFatalError, instead of throwing an exception?
BTW, at this point, can you send detailed info? errno? stuff like that
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 16 Dec 2020, 15:16

We'll think about it. It may be an option too, although it can also backfire, because if the client code does not listen for the event, the connection will break silently and the neither the user nor the developer will know about it.

This is a situation where an exception seems the best choice as it doesn't go unnoticed and it allows the developer to do something about it.
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 16 Dec 2020, 15:40

I don't think that throw a general exception is the best way to handle it. we will be glad if it will be done via your callbacks, then we will disconnect and do the necessary stuff.
BTW, this situation can also occur in JAVA as well?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 17 Dec 2020, 09:20

Not a general exception, a specific one.
Hiding such occurrence inside an event is pretty dangerous as I explained. If you don't remember to handle the event you will have no clue of why the application stopped working.

And yes it can happen in any language, as this is a rare runtime occurrence. If and when it happens the exception should be allowed to "bubble up" to the top level. Just like any other runtime exception or errors (a distinction that is not present in all languages, but you get the idea).

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 17 Dec 2020, 12:27

I agree with you, but you can implement the default callback to send a custom exception, and give the ability to override this callback as well.


I don't think this is doable, without breaking compatibility with previous API versions.
The way you delegate callbacks is by passing an implementation of an Objective-C Protocol, similar to a Java interface, so we don't provide a default implementation that you can override. You create the implementation itself.

We don't want to wrap all of our code with a big try/catch. as far as we know, it's a bad practice.

I don't think it's bad practice. Catching exceptions is normal coding practice.
The problem might arise if you had to "pollute" your code with try/catch blocks all over the place.

BTW, this crash (caused by the NSRangeException) completely stopped when we turned off the HRC feature.

Seems strange.
Was the exception triggered before or after the reconnection?

Thanks
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 20 Dec 2020, 18:45

Seems strange.
Was the exception triggered before or after the reconnection?

It happens when we come back from the background. I can see that onConnectionRetry was called, but onConnectionResume wasn't.

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 10 guests