• 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
1
Question by sargunster · Jun 25, 2014 at 08:21 PM · arrayarrays

IndexOutOfRangeException only on Mac OS X Standalone

I'm getting an IndexOutOfRange exception in my game, but only in a standalone build on Mac OS X. It works fine in the Unity editor on both Windows and OSX, and works fine as a standalone on Windows and Android. On OSX however, I get the following exception:

 IndexOutOfRangeException: Array index is out of range.
   at WorldController.InstantiateChunk (Vector2i pos, .MeshBuildInfo[] meshes) [0x00072] in /Users/sargunster/Code/Unity Projects/block-game/Assets/Scripts/World/Objects/WorldController.cs:226 
   at WorldController.FixedUpdate () [0x00060] in /Users/sargunster/Code/Unity Projects/block-game/Assets/Scripts/World/Objects/WorldController.cs:79 

Here's the relevant function:

 void InstantiateChunk(Vector2i pos, MeshBuildInfo[] meshes)
 {
     float worldX = pos.x * World.CHUNK_SIZE - .5f;
     float worldZ = pos.z * World.CHUNK_SIZE - .5f;

     // for each chunk in the column
     for (int y = 0; y < World.WORLD_HEIGHT; y++)
     {
         float worldY = y * World.CHUNK_SIZE - .5f;

         // instantiate the chunk
         Vector3 position = new Vector3(worldX, worldY, worldZ);
         string name = System.String.Format(" Chunk at ({0}, {1}, {2})", pos.x, y, pos.z);
         
         // THIS IS WHERE IT HAPPENED
         ChunkRenderer opaque = MakeChunk(position, "Opaque" + name, meshes[y].opaque, opaqueMaterial);
         
         ChunkRenderer transparent = MakeChunk(position, "Transparent" + name, meshes[y].transparent, transparentMaterial);
         Vector3i chunkPos = new Vector3i(pos.x, y, pos.z);
         opaqueInstances.Add(chunkPos, opaque);
         transparentInstances.Add(chunkPos, transparent);
     }
 }

I followed the references to find where meshes was instantiated, and it should have a length of WORLD_HEIGHT.

 MeshBuildInfo[] meshes = new MeshBuildInfo[World.WORLD_HEIGHT];

So, I went in to the debugger to see the exact value of the variable when the exception happened. Debugger output:

 > meshes
 Evaluation failed.
 > 2+2
 4
 > meshes.Length
 Evaluation failed.
 > y
 0
 > position
 {(-7168.5, -0.5, 4079.5)}

The index is 0, I can evaluation expressions just fine... except for the array that's not working. I can't get the length of it or its value.

I don't know how to solve this issue. What does "Evaluation Failed" mean? How can the index be out of bounds? Why is this only happening on OSX? How do I fix it?

World.WORLD_HEIGHT is a constant with a value of 16.

Comment
Add comment · Show 2
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
avatar image AndyMartin458 · Jun 26, 2014 at 12:15 AM 0
Share

Well it doesn't make sense to iterate through those things based on y, without checking that meshes is also of length y. This could be due to asset serialization being different on that particular platform.

avatar image sargunster · Jun 26, 2014 at 01:10 AM 0
Share

@Andy$$anonymous$$artin458 I tried using meshes.Length but the exception still happened. I don't see what this has to do with asset serialization.

1 Reply

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

Answer by sargunster · Jun 26, 2014 at 01:36 AM

After days of being frustrated by this issue, I've finally solved it (sort of). It only occurs when the game is built as x86_64 or Universal. Changing the architecture setting to x86 solved it. Must be a Unity bug.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random an Array to push to another Array 0 Answers

Making objects follow each other in a line, and objects ignoring minimum follow distance. 2 Answers

How to merge an arrays into arrays inside an array? 3 Answers

adding classes to arrays 2 Answers

Array of variable-length arrays (JS) 1 Answer


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