Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:54:33+00:00 2026-05-27T19:54:33+00:00

I’m getting this error in C# while trying to build an importer for a

  • 0

I’m getting this error in C# while trying to build an importer for a tilemap. It’s supposed to read files formatted like this;

DatMapName!
6|4
SpritePageID:SpriteID:OffsetX:OffsetY|SpritePageID:SpriteID:OffsetX:OffsetY SpritePageID:SpriteID:OffsetX:OffsetY
SpritePageID:SpriteID:OffsetX:OffsetY|SpritePageID:SpriteID:OffsetX:OffsetY SpritePageID:SpriteID:OffsetX:OffsetY

into a data structure built up like this;

map
    MapTile[MapSizeX, MapSizeY]
        Tile[Sprites on tile]
        - string SpritePageID
        - int SpriteID
        - Vector2 Offset

Basically it has the map name on the first line, X/Y size on the second, and then it has SpritePageID, spriteID, offsetx, offsetY separated by :, and multiple sprites per tile separated by |. Spaces delimit the different tiles.

However, during processing I get the following error;

Error   1   Building content threw NullReferenceException: Object reference not set to an instance of an object.
at LibTilePipelineExtension.LevelProcessor.Process(String input, ContentProcessorContext context) in C:\Projects\C#\XNA1\TileWorld\LibTilePipelineExtension\LevelProcessor.cs:line 45
at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings)
C:\Projects\C#\XNA1\TileWorld\TileWorld\TileWorldContent\tileworldtest1.tilemap TileWorld

Here’s the code that’s throwing this error.

string[] lines = input.Split(new char[] { '\n' });
// ------
// Clear out commented lines from the array. Turn it to a list, remove indices, turn back to array.
List<string> derp1 = new List<string>(lines);
for (int derp2 = 0; derp2 < derp1.Count; derp2++) {
    if (derp1[derp2][0] == ' ' || derp1[derp2][0] == ';') {
        derp1.RemoveAt(derp2);
        derp2--;
    }
}
lines = derp1.ToArray();
// ------
int rows = Convert.ToInt32(lines[1].Split('|')[0]);
int columns = Convert.ToInt32(lines[1].Split('|')[1]);

MapTile[,] res = new MapTile[rows, columns];

for (int i0 = 2; i0 < (rows + 2); i0++) {
    string[] tiles = lines[i0].Split(' ');

    for (int i1 = 0; i1 < columns; i1++) {
        string[] tileSprites = tiles[i1].Split('|');
-->     res[i0 - 2, i1].sprites = new Tile[tileSprites.Length];   <-- Exception

        for (int i2 = 0; i2 < tileSprites.Length; i2++) {
            string[] spriteData = tileSprites[i2].Split(':');

            res[i0 - 2, i1].sprites[i2] = new Tile(spriteData[0], Convert.ToInt32(spriteData[1]), new Vector2(Convert.ToInt32(spriteData[2]), Convert.ToInt32(spriteData[3])));
        }
    }
}
return new Map(res, lines[0]);

These are the classes I use to make this tree. I removed the using statements to shorten this question.

//Map.cs
namespace LibTile {
    public class Map {
        public MapTile[,] grid { get; set; }
        public string MapName { get; set; }

        public Map(MapTile[,] value) {
            grid = value;
        }
        public Map(MapTile[,] value, string name) {
            grid = value;
            MapName = name;
        }

        public MapTile GetTile(int row, int col) {
            return grid[row, col];
        }

        public int Rows {
            get {
                return grid.GetLength(0);
            }
        }

        public int Columns {
            get {
                return grid.GetLength(1);
            }
        }
    }
}

.

//MapTile.cs
namespace LibTile {
    public class MapTile {
        public Tile[] sprites { get; set; }

        public MapTile(Tile[] value) {
            sprites = value;
        }
    }
}

.

//Tile.cs
namespace LibTile {
    public class Tile {
        public String SpritePageID;
        public int SpriteID;
        public Vector2 Offset;

        public Tile(String spid, int sid, int ox, int oy) {
            SpritePageID = spid;
            SpriteID = sid;
            Offset = new Vector2(ox,oy);
        }
        public Tile(String spid, int sid, Vector2 o) {
            SpritePageID = spid;
            SpriteID = sid;
            Offset = o;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:54:33+00:00Added an answer on May 27, 2026 at 7:54 pm

    You create a new array of MapTile but you never initialize the individual elements. Try this:

    res[i0 - 2, i1] = new MapTile(new Tile[tileSprites.Length]);
    

    This will create a new MapTile object in each poition of the array. Not doing this was causing your null reference exception. I would also consider changing the constructor of MapTile to be parameterless and then just set MapTile.sprites as you were doing before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.