Friday, November 16, 2018

Windows Form code not executing?


Ok, I've got a weird one here. I'm trying to make a basic tile engine using a windows form, but some of my code is just...not happening. I'll post the chunks in question.


private void MapEditor_Load(object sender, EventArgs e)
{
LoadImageList();
FixScrollBarScales();
cboCodeValues.Items.Clear();
cboCodeValues.Items.Add("ENEMY");
cboCodeValues.Items.Add("CHEST");
cboCodeValues.Items.Add("NPC");


for (int x = 0; x < 100; x++)
cboMapNumber.Items.Add(x.ToString().PadLeft(3, '0'));

cboMapNumber.SelectedIndex = 0;
TileMap.EditorMode = true;
backgroundToolStripMenuItem.Checked = true;
}

This should be called when the form loads, right? The code dives into LoadImageList(), which contains:



private void LoadImageList()
{
string filepath = Application.StartupPath + @"\Content\Textures\IndoorTileSet.png";
Bitmap tileSheet = new Bitmap(filepath);
int tilecount = 0;
for(int y = 0; y < tileSheet.Height / TileMap.TileHeight; y++)
{
for(int x = 0; x < tileSheet.Width / TileMap.TileWidth; x++)
{
Bitmap newBitmap = tileSheet.Clone(new System.Drawing.Rectangle(x * TileMap.TileWidth, y * TileMap.TileHeight,

TileMap.TileWidth, TileMap.TileHeight), System.Drawing.Imaging.PixelFormat.DontCare);
imgListTiles.Images.Add(newBitmap);
string itemName = "";
if(tilecount == 0)
itemName = "Empty";
if(tilecount == 1)
itemName = "Floor";
listTiles.Items.Add(new ListViewItem(itemName, tilecount++));
}
}

}

The bitmap loads correctly, but then the entire MapEditor_Load method just stops working. tileCount seems to be a local variable in the debugger, and its value is 0, but the debugger never executes the breakpoint on the line which it is assigned. I have absolutely no idea why it would do this, and it's driving me nuts. Any help? Oh, I put the bitmap load in a try/catch block just to see if it was handling an exception in a weird way, but I had no luck. It's not throwing an exception. I began having this problem immediately after replacing my IndoorTileSet with an updated version.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...