Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ExtremePowers · Dec 06, 2014 at 06:20 PM · errorbugnullout of range

SplatMap error

I use some code to procedurally paint the terrain. But for some reason the splatmap variable sometimes becomes smaller or I atleast get a error with the current iteration being out of range. Error:

 IndexOutOfRangeException: Array index is out of range.
 (wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
 PT+$UpdateTile$72+$.MoveNext () (at Assets/Scripts/PT.js:272)
 UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
 $:MoveNext() (at Assets/Scripts/PT.js:98)
 UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
 StartMenu:SpawnPlayer() (at Assets/Scripts/StartMenu.js:716)
 StartMenu:OnGUI() (at Assets/Scripts/StartMenu.js:273)
 

and for some reason when doing a check like the code below, it is the first line that returns the error, why doesn't that line prevent the error from occuring, since if it is out of range, it should be null right?

 if (map[z,x,0] != null) { //For some reason it is this line that gives a null
     map[z,x,0] = 1;
 }
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

Answer by tanoshimi · Dec 09, 2014 at 04:02 PM

If your map is, say, a 2x2x2 array (i.e. map[2,2,2]) and you try to access an index outside that range (i.e. map[4,5,6]), you'll get an "array index is out of range" error as you have done.

Your if map[z,x,0] != null check doesn't prevent this error - that tests whether a value at a given position in the array is null, but your array doesn't even contain that many elements.

Please paste the code where you declare map, and where you assign the values z and x.

Comment
Add comment · Show 2 · 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
avatar image ExtremePowers · Dec 09, 2014 at 10:49 PM 0
Share

@tanoshimi Something like this:

 var hw = Terrain.terrainData.heightmapWidth;
 var map = new float[hw,hw,Terrain.terrainData.AlphamapLayers];
 
 for (var z = 0; z < hw; z++) {
     for (var x = 0; x < hw; x++) {
         map[z,x,0] = 1;
     }
 }

The most weird part of this is that it is only sometimes that the error occurs. Even though the heightmapWidth never changes. So my guess would be that the AlphamapLayers is giving the error, I use this code to make the prototypes:

 var splat : Texture2D[];
 var detail : Texture2D[];
 var tree : GameObject[];
 
 private var splatPrototypes : SplatPrototype[];
 private var detailProtoTypes : DetailPrototype[];
 
 function  CreateProtoTypes() {
     splatPrototypes = new SplatPrototype[splat.Length];
     
     for (var i = 0; i < splat.Length; i++) {
         splatPrototypes[i] = new SplatPrototype();
         splatPrototypes[i].texture = splat[i];
         splatPrototypes[i].tileSize = new Vector2(15, 15);
     }
     
     detailProtoTypes = new DetailPrototype[detail.Length];
 
     for (var d = 0; d < detail.Length; d++) {
         detailProtoTypes[d] = new DetailPrototype();
         detailProtoTypes[d].prototypeTexture = detail[d];
         detailProtoTypes[d].render$$anonymous$$ode = DetailRender$$anonymous$$ode.GrassBillboard;
         detailProtoTypes[d].maxHeight = 1;
         detailProtoTypes[d].maxWidth = 1.5;
         detailProtoTypes[d].dryColor = Grass;
         detailProtoTypes[d].healthyColor = Grass;
     }
 }
avatar image Scribe · Jan 03, 2015 at 12:30 PM 0
Share

Try:

 var splatmapData = new float[Terrain.terrainData.alphamapWidth, Terrain.terrainData.alphamapHeight, Terrain.terrainData.alphamapLayers];
         
 for(var  z = 0; z < Terrain.terrainData.alphamapHeight; z++){
     for(var x = 0; x < Terrain.terrainData.alphamapWidth; x++){

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

25 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 avatar image avatar image avatar image

Related Questions

String in array is null when checking length, help bug?! 2 Answers

Unity White Screen Problem 2 Answers

In order to call GetTransformInfoExecectUpToDate 1 Answer

I'm experiencing constant crashes when the multiple game windows are open. 0 Answers

Everything in unity except for screen is black. 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