Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by lassevestergaard · Oct 24, 2016 at 02:15 PM · liststructindexoutofrangeexception

Runtime IndexOutOfRangeException when testing on iPhone

I have a script that fetches JSON data from a REST api, and translates it using "JsonUtility.FromJson". The scripts is the following:

 UnityWebRequest www = UnityWebRequest.Get("http://my_url/getNearPlanes?longitude="+myLocation.y+"&latitude="+myLocation.x+"&altitude="+myLocation.z+"&maxDistance=300");
         yield return www.Send();
 
         if(www.isError) {
             Debug.Log(www.error);
         }
         else {
             MyPlanes planeList = JsonUtility.FromJson<MyPlanes>(www.downloadHandler.text);
 
             for (int i = 0; i < planeList.planes.Count; i++) {
                 MyPlane mp = planeList.planes [i];
 
                 float tempLat = mp.latitude - myLocation.x;
                 float tempLong = mp.longitude - myLocation.y;
                 float tempAlt = mp.altitude - myLocation.z;
 
                 Instantiate(airPlane, new Vector3 (tempLat,tempAlt,tempLong), Quaternion.identity, this.transform);
             }
         }

I have a MyPlanes object:

 [Serializable]
 public class MyPlanes{
     public List<MyPlane> planes;
 }

and a MyPlane struct:

 [Serializable]
 public struct MyPlane{
     public string icao24;
     public string callsign;
     public string origin_country;
     public float time_position;
     public float time_velocity;
     public float longitude;
     public float latitude;
     public float altitude;
     public bool on_ground;
     public float velocity;
     public float heading;
     public float vertical_rate;
     public int[] sensors;
 }

When running this code within Unity it all works fine. The problem is that, when I build for iOS Xcode gives me the following error:

 IndexOutOfRangeException: Array index is out of range.
   at System.Collections.Generic.List`1[T].get_Item (Int32 index) [0x00000] in <filename unknown>:0 
   at AirPlanesController+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
   at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0 
  
 (Filename: currently not available on il2cpp Line: -1)

When I write print(planeList.planes.Count) I get the correct number of elements (list is not empty). The error seems to occur when I want to fetch a specific element in the list: planeList.planes[i].

I guess the issue relates to something around the struct type. Any suggestions?

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by lassevestergaard · Oct 25, 2016 at 08:09 AM

I have now done some further investigations, and it seems to work now. I have no real idea why, but what I did is essentially only replacing public List<MyPlane> planes; with public MyPlane[] planes; in the MyPlanes class.

I also changed MyPlane to class instead of struct (it didn't make any difference, but I just didn't really understand the need for a struct here).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How to add an item to a list with a class/uJS struct? 1 Answer

Show and Edit Attributes of my list of structs in EditorWindow. 0 Answers

Individualize variables in elements on list. 0 Answers

Function throws 'argument out of range, parameter: index' error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges