Search Unity

Resolved Il2CppException wasm build

Discussion in 'Project Tiny' started by Ogham, Sep 25, 2020.

  1. Ogham

    Ogham

    Joined:
    Feb 16, 2018
    Posts:
    5
    Hi all,

    I recently started working with Tiny and ECS and I'm having a lot of fun.

    I'm facing a problem after building my app with Web Wasm.

    There you can see a bit more of the error :
    upload_2020-9-25_18-2-7.png

    Here is the code that is problematic :
    Code (CSharp):
    1.  
    2. protected int PickNumber(bool isFood)
    3.         {
    4.             int nbr = -1;
    5.  
    6.             if (isFood) {
    7.                 int r = m_Random.NextInt(0, nbrFood.Count - 1);
    8.                 nbr = nbrFood[r];
    9.                 nbrFood.Remove(r);
    10.             } else {
    11.                 int r = m_Random.NextInt(0, nbrNonFood.Count - 1);
    12.                 nbr = nbrNonFood[r];
    13.                 nbrNonFood.Remove(r);
    14.             }
    15.  
    16.             return nbr;
    17.         }
    Every help is appreciated greatly
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    Hi it seems that its throwing exception while removing the element from nbrFood or nbrNonFood
    I wonder if you can provide a repro project that I can help you with
    because I don't know what are nbrFood and nbrNonFood
     
  3. Ogham

    Ogham

    Joined:
    Feb 16, 2018
    Posts:
    5
    Thanks for the quick response!

    nbrFood and nbrNonFood are both a List<int>

    Code (CSharp):
    1. private List<int> nbrFood;
    2. private List<int> nbrNonFood;
    I can provide you a repro if that info is not sufficient
     
  4. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    Thanks
    Yes, proving a repro project would be awesome
     
  5. Ogham

    Ogham

    Joined:
    Feb 16, 2018
    Posts:
    5
  6. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    So use NativeList instead of List
    I made branch but I don't have access to push it so I'll paste here what I did



    Code (CSharp):
    1.  
    2.  
    3. using Unity.Collections;
    4.  
    5.  
    6. public class SetupGameSystem : ComponentSystem
    7. {
    8. .
    9. .
    10. .
    11.   private NativeList<int> nbrFood;
    12.   private NativeList<int> nbrNonFood;
    13.  
    14. .
    15. .
    16. .
    17.  
    18. protected void PopulateSession(bool isTraining, SSTSession session, DynamicBuffer<StepStimulus> buf)
    19. {
    20.     this.nbrFood = new NativeList<int>(Allocator.TempJob);
    21.     this.nbrNonFood = new NativeList<int>(Allocator.TempJob);
    22.  
    23. .
    24. .
    25. .
    26. protected int PickNumber(bool isFood)
    27. {
    28.     int nbr = -1;
    29.  
    30.     if (isFood) {
    31.         int r = m_Random.NextInt(0, nbrFood.Length - 1);
    32.         nbr = nbrFood[r];
    33.         nbrFood.RemoveAt(r);
    34.     } else {
    35.         int r = m_Random.NextInt(0, nbrNonFood.Length - 1);
    36.         nbr = nbrNonFood[r];
    37.         nbrNonFood.RemoveAt(r);
    38.     }
    39.  
    40.     return nbr;
    41. }
    42.  
    43. .
    44. .
    45. .
    46. protected override void OnDestroy()
    47. {
    48.     base.OnDestroy();
    49.     nbrFood.Dispose();
    50.     nbrNonFood.Dispose();
    51. }
    52.  
    53.  
    54.  
     
  7. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    the issue was nbrFood.Remove(r); should be RemoveAt because r is an index if I'm not mistaken
     
    Ogham likes this.
  8. Ogham

    Ogham

    Joined:
    Feb 16, 2018
    Posts:
    5
    Thanks a lot, it worked perfectly!
    Silly me for using System.Collections.Generic; instead of Unity.Collections.
     
unityunity