c# - MissingFieldException: Templated field missing in constructor -


i'm trying create 2d array class allows large data sets breaking data , storing non-contiguously. however, missingfieldexception inside constructor fundamentally don't understand. i'm using c# unity.

this offending call:

 chunkarray<int> lastdata = new chunkarray<int>(texturewidth, textureheight); 

the exception "missingfieldexception: field '.chunkarray`1.data' not found." class follows:

using system.collections; using system.collections.generic;  public class chunkarray<t>  {     private const int defaultsidedivision = 16;      t[,][,] data;      int xchunks;     int ychunks;      int subwidth;     int subheight;      public int w;     public int h;      public chunkarray(int width, int height, int sidedivision = defaultsidedivision)      {         w = width;         h = height;         subwidth = width / sidedivision;         subheight = height / sidedivision;          int widthremainder = width % sidedivision;         int heightremainder = height % sidedivision;          xchunks = (widthremainder == 0) ? sidedivision : sidedivision + 1;         ychunks = (heightremainder == 0) ? sidedivision : sidedivision + 1;          data = new t[xchunks, ychunks][,];          (int = 0; < xchunks; i++)          {             (int j = 0; j < ychunks; j++)              {                 int x = (i < sidedivision) ? subwidth : widthremainder;                 int y = (j < sidedivision) ? subheight : heightremainder;                 data[i, j] = new t[x,y];             }         }                }      public t get(int x, int y)     {         return data[x / subwidth, y / subheight][x % subwidth, y % subheight];     }      public void set(int x,int y, t value) {         data[x / subwidth, y / subheight][x % subwidth, y % subheight] = value;      } } 

any appreciated stumped. hope formatted correctly.

this looks bug in mono: fails instantiate generic multi-dimensional array of multi-dimensional arrays. however, when tried replace t[,][,] t[][] worked, suggest emulating two-dimensional arrays single-dimensional ones:

public class chunkarray<t> {     private const int defaultsidedivision = 16;      t[][] internaldata;      int xchunks;     int ychunks;      int subwidth;     int subheight;      public int w;     public int h;      public chunkarray(int width, int height)     {         int sidedivision = defaultsidedivision;         w = width;         h = height;         subwidth = width / sidedivision;         subheight = height / sidedivision;          int widthremainder = width % sidedivision;         int heightremainder = height % sidedivision;          xchunks = (widthremainder == 0) ? sidedivision : sidedivision + 1;         ychunks = (heightremainder == 0) ? sidedivision : sidedivision + 1;          internaldata = new t[xchunks * ychunks][];          (int = 0; < xchunks; i++)         {             (int j = 0; j < ychunks; j++)             {                 internaldata[getfirstindex(i,j)] = new t[subwidth * subheight];             }         }     }      private int getfirstindex(int i, int j)     {         return + j * xchunks;     }      private int getsecondindex(int i, int j)     {         return + j * subwidth;     }      public t get(int x, int y)     {         return internaldata[getfirstindex(x / subwidth, y / subheight)][getsecondindex(x % subwidth, y % subheight)];     }      public void set(int x, int y, t value)     {         internaldata[getfirstindex(x / subwidth, y / subheight)][getsecondindex(x % subwidth, y % subheight)] = value;     } } 

for sake of simplicity, i've set data chunks same size, last chunks have unused space.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -