Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

A lot of OverflowException from IAP plugin

Discussion in 'Unity IAP' started by YuriBazila, Jan 28, 2019.

  1. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    Hi,

    From Jan 8 there are a lot of exceptions from IAP plugin in my project.
    I've used Unity 2018.3.2 and now I'm using 2018.3.3. IAP plugin is up to date

    Code (JavaScript):
    1. OverflowException: Value was either too large or too small for a character.: java.lang.Throwable:
    2. System.Convert.ToChar (System.Int32 value) (at <00000000000000000000000000000000>:0)
    3. UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace () (at <00000000000000000000000000000000>:0)
    4. UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken () (at <00000000000000000000000000000000>:0)
    5. UnityEngine.Purchasing.MiniJSON.Json+Parser.Parse (System.String jsonString) (at <00000000000000000000000000000000>:0)
    6. UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions (System.String json) (at <00000000000000000000000000000000>:0)
    7. UnityEngine.Purchasing.JSONStore.OnProductsRetrieved (System.String json) (at <00000000000000000000000000000000>:0)
    8. UnityEngine.Purchasing.Extension.UnityUtil.Update () (at <00000000000000000000000000000000>:0)
    9.  
    10.     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    11.     at com.unity3d.player.UnityPlayer.c(Unknown Source)
    12.     at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source)
    13.     at android.os.MessageQueue.next(MessageQueue.java:207)
    14.     at android.os.Looper.loop(Looper.java:123)
    15.     at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
    Code (JavaScript):
    1. OverflowException: Value is greater than Char.MaxValue or less than Char.MinValue: java.lang.Throwable:
    2. System.Convert.ToChar (Int32 value)
    3. UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace ()
    4. UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken ()
    5. UnityEngine.Purchasing.MiniJSON.Json+Parser.Parse (System.String jsonString)
    6. UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions (System.String json)
    7. UnityEngine.Purchasing.JSONStore.OnProductsRetrieved (System.String json)
    8. UnityEngine.Purchasing.Extension.UnityUtil.Update ()
    9.  
    10.     at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    11.     at com.unity3d.player.UnityPlayer.c(Unknown Source)
    12.     at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source)
    13.     at android.os.MessageQueue.next(MessageQueue.java:207)
    14.     at android.os.Looper.loop(Looper.java:123)
    15.     at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
     
  2. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    Devices stat:
     
  3. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    android versions stat:
     
  4. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    It's still happening and I can't find the reason why. Looks like the issue in the IAP plugin on some old devices.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    What happened on Jan 8, did you have a new release go out by chance? Some of those look like Chinese devices, and they would not necessarily be expected to have Google Play installed, but I would expect different error in that case ("class not found"). A Google search did bring up this https://github.com/googlesamples/unity-jar-resolver/issues/135 but it looks like it would not apply in your case.
     
  6. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    Thank you for the respose!
    I'm sorry for Jan 8, it was earlier too. It's happening from the release date.
    Countries where it is happening are very different. We had a lot of installs from China two weeks ago, but the number of exceptions not increased a lot. So I don't think google play is a problem.
    We can't even reproduce that exception, so that is also a problem.
     
  7. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    Is Unity IAP open source? Can we look inside UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions for example?
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    Sorry it is not open source. Can you list what your product descriptions look like?
     
  9. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    We have 7 inapp purchases.

    Titles and descriptions are just a strings without any special chars, emodjes etc.

    Special WINTER PACK
    Coins Storage
    Handful of Coins
    Pile of Coins
    Pinch of Coins
    Stack of Coins
    Starter Pack

    We have only English-US localization of products
     
  10. YuriBazila

    YuriBazila

    Joined:
    Feb 1, 2013
    Posts:
    46
    We don't use IAP catalog from Unity IAP. We initialize products in code

    Code (CSharp):
    1. public void Init()
    2.         {
    3.             // If we have already connected to Purchasing ...
    4.             if (IsInitialized())
    5.             {
    6.                 // ... we are done here.
    7.                 return;
    8.             }
    9.  
    10.             // Create a builder, first passing in a suite of Unity provided stores.
    11.             var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    12.  
    13.             foreach (var p in Core.GameData.AppStoreData.products)
    14.             {
    15.                 builder.AddProduct(p.PlatformStoreId, p.productType);
    16.             }
    17.  
    18.             // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration
    19.             // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed.
    20.             UnityPurchasing.Initialize(this, builder);
    21.         }
     
  11. Vasiliy-V-V

    Vasiliy-V-V

    Joined:
    Dec 9, 2013
    Posts:
    6
    I have many exceptions with "OverflowException" too. Did you find a solution? I'm on Unity 2018.3.6f1 and InAppPurchasing 2.0.6.

    Screen with stats from Unity Dashboard: https://monosnap.com/file/CsP1PMjN15JqZobeIBEPZoR6pLJY0x

    It's started after updating the app.

    Example of stacktrace with error:

    OverflowException: Value was either too large or too small for a character.
    System.Convert.ToChar (System.Int32 value) (at <44c33aa1c27b467bb7db82cd2e404e81>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.get_PeekChar () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.ParseValue () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.Parse (System.String jsonString) (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json.Deserialize (System.String json) (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJson.JsonDecode (System.String json) (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions (System.String json) (at <608cd934032f415995a47e21f14f1980>:0)
    UnityEngine.Purchasing.JSONStore.OnProductsRetrieved (System.String json) (at <608cd934032f415995a47e21f14f1980>:0)
    UnityEngine.Purchasing.ScriptingUnityCallback+<>c__DisplayClass4_0.<OnProductsRetrieved>b__0 () (at <608cd934032f415995a47e21f14f1980>:0)
    UnityEngine.Purchasing.Extension.UnityUtil.Update () (at <608cd934032f415995a47e21f14f1980>:0)

    @JeffDUnity3D please help.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    Make sure you are using Unity IAP 1.20.1. Go to the Services window in Unity (menu Window/Services or Window/General/Services) and click on the In App Purchasing tab to confirm. And as a test, compare to the Sample Project here: https://forum.unity.com/threads/sample-iap-project.529555/
     
  13. Vasiliy-V-V

    Vasiliy-V-V

    Joined:
    Dec 9, 2013
    Posts:
    6
    Thanks for the answer. I have made some investigations on my changes. And I have changed in Unity Scripting Runtime Version from "NET 3.5(Deprecated)" to "NET 4.x". After that innaps stopped working. I have tried to update Unity IAP to 1.20.1 and last Unity 2018.3.8f1, but error the same.
    Today I have changed Scripting Runtime Version back to "NET 3.5(Deprecated)" and error is gone and innaps start working correctly.
    Does Unity IAP must working with "NET 4.x"? (Scripting Backed is Mono, Api Compatibility Level is .NET 2.0)
    EDIT: Forgot to say that this problem only on Android 5.1 and earlier.
     
    Last edited: Mar 13, 2019
  14. mkg2w

    mkg2w

    Joined:
    Aug 19, 2013
    Posts:
    38
    We also came across the same issue and discovered we had to downgrade to .net 3.5 to support devices such as Galaxy J2.
    is there a fix planned for Unity IAP ?
     
  15. Zamaroht

    Zamaroht

    Joined:
    Nov 4, 2013
    Posts:
    9
    We have been receiving a lot of exception reports with this same stacktrace after releasing to production. We are building with Unity 2018.3 and .Net 4.x
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    Are you using IAP 1.22?
     
  17. Tomi-Tukiainen

    Tomi-Tukiainen

    Joined:
    Jun 8, 2013
    Posts:
    15
    Hi, I've noticed that MiniJSON produces JSON that it has problems parsing in the .NET 4.x Equivalent Scripting Runtime version. In some cultures it can use "," as the decimal separator and that breaks JSON parsing. An example JSON output would be {"t":2,"v":8,0505771636962891}.

    Test code to deserialize this...

    object test = MiniJSON.Json.Deserialize("{\"t\":2,\"v\":8,0505771636962891}");

    ...will produce an Exception:

    OverflowException: Value was either too large or too small for a character.
    System.Convert.ToChar (System.Int32 value) (at <44c33aa1c27b467bb7db82cd2e404e81>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.get_PeekChar () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken () (at <df6ad794a9e84e21b2a1e28d0e640cbf>:0)
    ...


    Fixing this:

    - In earlier Unity versions Thread's CurrentCulture was always InvariantCulture, that's why MiniJSON (and a lot of other code) worked. Quick fix for all is the following somewhere in your initialization code:

    System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

    - For the new Unity Runtime, MiniJSON should be patched so that it formats decimal numbers using InvariantCulture, currently it uses ToString("R") which is culture specific. Replace these with ToString("R", System.Globalization.CultureInfo.InvariantCulture).
     
    Last edited: May 22, 2019
  18. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    Thanks for the info, I will pass it along!
     
  19. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
    Is there a fix for this issue?

    I'm using .NET 3.5 Equivalent, and getting this OverflowException as well.



    Non-fatal Exception: java.lang.Exception: OverflowException : Value is greater than Char.MaxValue or less than Char.MinValue
    at System.Convert.ToChar(System.Convert)
    at UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace(UnityEngine.Purchasing.MiniJSON.Json+Parser)
    at UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken(UnityEngine.Purchasing.MiniJSON.Json+Parser)
    at UnityEngine.Purchasing.MiniJSON.Json+Parser.Parse(UnityEngine.Purchasing.MiniJSON.Json+Parser)
    at UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions(UnityEngine.Purchasing.JSONSerializer)
    at UnityEngine.Purchasing.JSONStore.OnProductsRetrieved(UnityEngine.Purchasing.JSONStore)
    at UnityEngine.Purchasing.Extension.UnityUtil.Update(UnityEngine.Purchasing.Extension.UnityUtil)


    98% Android 5.X.
     
  20. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    What country locale? Can you confirm it is non-US?
     
  21. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
    @JeffDUnity3D Unfortunetely I don't have data to confirm it's non-US (or US).
    Worse ratings in the store are from Russia and Germany (a lot worse!), so I assume it's connected...
     
  22. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
    I managed to find a Android 5.0 device with polish language set (game is also translated to polish) and can't find the way to make it work. OverflowException is there no matter what I do.
     
  23. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    Got it, we will take a look. Sounds like an issue with non-US locale.
     
  24. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
    @JeffDUnity3D Is there any ETA for the fix?
    I'm really getting a lot of bad reviews as well as losing players due to unplayable game :/
     
  25. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
  26. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    269
    We found that having emoji in the name of app may cause this problem. This could happen on devices with Android versions equal to or less than 5.

    Do you have any emoji in your app name? You can follow these steps to confirm or change it:

    Go to Google Developer Console -> Choose app - > Store presence -> Store listing -> Title.

    upload_2019-6-19_15-47-2.png
     
  27. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
    I do have emoji in the title. I'll try to remove it and find out if it helps.

    Is there any fix coming in the future? I really like my emoji in the title :)

    EDIT:
    It seems to be working. I don't see this exception on my test device anymore. Thank you for your help.
    I still think you should fix it so we can use emoji in the app name ;)
     
    Last edited: Jun 19, 2019
  28. cometa93

    cometa93

    Joined:
    Mar 5, 2014
    Posts:
    27
    Up^^ is there update under the issue? We encountered the same problem.
     
  29. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    269
    Hello, this issue has been reported and is in the process of being fixed. So far there is no expected time, if there is any progress I will post here. To avoid this issue, please do not include emojis in the name of the application at this time.
     
  30. TpakTop16

    TpakTop16

    Joined:
    Nov 20, 2017
    Posts:
    5
    I have many exceptions with "OverflowException" too. Did you find a solution? I'm on Unity 2019.1.2f1 and Unity IAP 1.23.1.

    It's started after updating the app.

    Example of stacktrace with error:

    OverflowException: Value was either too large or too small for a character.: java.lang.Throwable: System.Convert.ToChar (System.Int32 value) (at <00000000000000000000000000000000>:0) UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace () (at <00000000000000000000000000000000>:0) UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken () (at <00000000000000000000000000000000>:0) UnityEngine.Purchasing.MiniJSON.Json+Parser.Parse (System.String jsonString) (at <00000000000000000000000000000000>:0) UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions (System.String json) (at <00000000000000000000000000000000>:0) UnityEngine.Purchasing.JSONStore.OnProductsRetrieved (System.String json) (at <00000000000000000000000000000000>:0) System.Action.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Purchasing.Extension.UnityUtil.Update () (at <00000000000000000000000000000000>:0) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.c(Unknown Source) at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:145) at com.unity3d.player.UnityPlayer$e.run(Unknown Source)

    Product id in store has style id_money_1000, and not have emoji.
    Geographic location of buyers is mainly Russia.

    @JeffDUnity3D or @SamOYUnity3D please help.
     
  31. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    @TpakTop16 can you share a screenshot of your products as defined on Google Play, and in your app? You mentioned you updated your app, what components did you upgrade? Did it have a previous version of IAP?
     
  32. Prophet1111

    Prophet1111

    Joined:
    Mar 16, 2016
    Posts:
    20
    Does your app name contain emoji? This was the issue in my case.
     
  33. TpakTop16

    TpakTop16

    Joined:
    Nov 20, 2017
    Posts:
    5
    Errors appeared before the update since January 17 of this year. This is clearly visible on the chart.
    Since January 28, I released 2 new versions, in which I updated Unity IAP from 1.20.1 to 1.23.1. Also, of course, I added new functionality, which in no way affects the operation of IAP. I substitute my products from the code. On all test devices, purchases work well and without errors.
     

    Attached Files:

  34. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    So it sounds like you are not able to reproduce, you mentioned the issue is limited to users in Russia? It could be a bug how we are handling the locale, to be determined however. Do you have any information on the device/models?
     
  35. TpakTop16

    TpakTop16

    Joined:
    Nov 20, 2017
    Posts:
    5
    The file contains a list of devices on which errors occurred. Almost all devices distinguished once.
     

    Attached Files:

  36. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
    Can you share a link to your app? Is there any chance you could show your Google Play developer console in English?
     
  37. TpakTop16

    TpakTop16

    Joined:
    Nov 20, 2017
    Posts:
    5
  38. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,587
  39. matiasticbits

    matiasticbits

    Joined:
    Jan 3, 2017
    Posts:
    28
    We have encountered the same issue and are trying to fix this. It started suddnely without a new version release. I am currently investigating the possibility that Google Play Billing API is returning an empty description for specific localization and MiniJSON fails to parse that.

    Looking at MiniJSON code here: https://gist.github.com/darktable/1411710#file-minijson-cs-L304
    json
    being a
    StringReader
    the
    Peek
    method will return -1 if the string is an empty one and that will cause
    Convert.ToChar
    to throw an error.
    Code (CSharp):
    1. void EatWhitespace() {
    2.     while (Char.IsWhiteSpace(PeekChar)) {
    3.         json.Read();
    4.  
    5.         if (json.Peek() == -1) {
    6.             break;
    7.         }
    8.     }
    9. }
    10.  
    11. char PeekChar {
    12.     get {
    13.         return Convert.ToChar(json.Peek());
    14.     }
    15. }
    I cannot find any change logs if we happened to add a new localization exactly when the problems started. Testing if adding all localizations to all IAPs we have setup.
     
  40. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    269
    Are there any changes to the app's title, description, or language settings of the new release?

    Could you provide the device log for further investigation? Did you update the IAP version in the new release? What the IAP version are you using?
     
    Last edited: Apr 27, 2020
  41. matiasticbits

    matiasticbits

    Joined:
    Jan 3, 2017
    Posts:
    28
    The issue for us started 26th of March and we updated Unity IAP 1.23.1 to production in middle of January. We didn't do any new releases around that time when the issue started.

    All the logs we have currently is from Unity Dashboard and Firebase Crashlytics and match the ones reported here.
    Code (CSharp):
    1. System.Convert.ToChar (System.Int32 value) (at <00000000000000000000000000000000>:0)
    2. UnityEngine.Purchasing.MiniJSON.Json+Parser.EatWhitespace () (at <00000000000000000000000000000000>:0)
    3. UnityEngine.Purchasing.MiniJSON.Json+Parser.get_NextToken () (at <00000000000000000000000000000000>:0)
    4. UnityEngine.Purchasing.MiniJSON.Json+Parser.Parse (System.String jsonString) (at <00000000000000000000000000000000>:0)
    5. UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions (System.String json) (at <00000000000000000000000000000000>:0)
    6. UnityEngine.Purchasing.JSONStore.OnProductsRetrieved (System.String json) (at <00000000000000000000000000000000>:0)
    7. UnityEngine.Purchasing.Extension.UnityUtil.Update () (at <00000000000000000000000000000000>:0)
     
  42. matiasticbits

    matiasticbits

    Joined:
    Jan 3, 2017
    Posts:
    28
    We went through the Google Play Console's activity log and the only changes around +-2 days from the start of this issue were for app's title and short description. Can this have an impact? No changes to IAP configurations.

    And yes that change introduced an emoji to the app's title, will change it.
     
    Last edited: Apr 27, 2020
    SamOYUnity3D likes this.
  43. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    269
    What Locale / Country is the phone using, when it threw the exception? This could indicate the numeric formatting of the price, e.g $1.29 or "1,29", or some other format.

    What are the possible product descriptions and product titles you added to the game? Do you have any character in that data that may be unsupported?
     
  44. matiasticbits

    matiasticbits

    Joined:
    Jan 3, 2017
    Posts:
    28
  45. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    269
    Thanks for the information, this can help us better investigate.
     
unityunity