SmartFox.InitCrypto Method throws a non fatal exception.

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Posts: 3
Joined: 20 Dec 2022, 05:48

SmartFox.InitCrypto Method throws a non fatal exception.

Postby Sudarshan » 20 Dec 2022, 09:37

when we call

Code: Select all

, it is throwing an exception like below

Code: Select all

Message: ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
  Stacktrace: System.Buffer.BlockCopy (System.Array src, System.Int32 srcOffset, System.Array dst, System.Int32 dstOffset, System.Int32 count) (at <2e531ccb5a634d41a5f338e40371c5fd>:0)
Sfs2X.Util.ByteArray.WriteBytes (System.Byte[] data, System.Int32 ofs, System.Int32 count) (at <facfabb65458430294cb5e9a75ea8519>:0)
Sfs2X.Util.CryptoInitializer.OnHttpResponse (System.String rawData) (at <facfabb65458430294cb5e9a75ea8519>:0)
Sfs2X.Util.CryptoInitializer+<Run>d__5.MoveNext () (at <facfabb65458430294cb5e9a75ea8519>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <e0b801613d424beca89c0145453da4be>:0)

The issue is intermittent, we don't have the STR.
but in crashlytics we saw that many users are getting this nonfatal exception intermittently in production, the method was part of smartfox internal class we were not about to figure out what the issue was.
we are using smartfox for a long time and our connection flow is fine also we haven't noticed this issue while testing.
so to deal with the issue we have implemented a retry logic in case encryption fails so sometimes the following thing is happening for the user.
step 1: User-initiated connection
step 2: Connected successfully
Step 3: Called StartCoroutine(smartFox.InitCrypto());
Step 4: Encryption initialization successful
Step 5: Initiated login.
Step 6: Login successful , so started gameplay
Step 7: After around 10min of gameplay, the user minimized the app so the client manually disconnected from smartfox
Step 8: On app maximization, the client started reconnection flow where it again completed steps 1,2 but got the above nonfatal exception while trying to complete step 3.
Step 9: As step 3 got failed while reconnection our retry logic again tried to finish step 3 after a 2-sec delay and at that attempt encryption initialization was successful.

So we didn't understand why exactly it threw an exception in step 8 though.
How can we avoid this? are we doing anything wrong?

Misc info:
SFS2X version: 1.7.8
Unity API version: 2019.2.14f1
Platform: Both in Android and iOS
User avatar
Site Admin
Posts: 22603
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SmartFox.InitCrypto Method throws a non fatal exception.

Postby Lapo » 21 Dec 2022, 08:38

thanks for the information.
We noticed that you're working with pretty old software and we wouldn't be able to test under Unity 2019 as we have moved on to more recent versions.

My first recommendation would be to replace the old SFS API with the latest which don't use coroutines any longer, so please check the encyrption example here: ... yptography
(scroll down almost at the bottom)

SFS2X Unity API download here -->

It may also depend on Unity as we do recall having recevied a few complaint about issues with a specific 2019 release that were then solved by the next update. Unfortunately I don't have the details about which version of Unity broke it and which fixed it back.

If you still have problems after the API update let us know the details.

p.s. = you did not say which version of the server you're using.
...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 14 guests