outofmemory exception

Aug 13, 2011 at 12:40 AM

Hey all, I was wondering if someone could shed some light on a situation I'm having.

While I create levels in Gleed I've been getting an outofmemory exception. I was wondering why this was happening? The only thing I can come up with is that maybe for every single texture, it's loading a new textureImage into memory. So if I have 50 of the same texture, it's loaded 50 different textures instead of reusing the original one.


Thoughts anyone?

Aug 13, 2011 at 4:06 AM

I figured out why I was getting the outofmemory exception.


I'm working with sprite sheets, so I've got really large textures that I pull specific areas out of. What's going on is during the level load, it's creating the pixel based collision "coldata" using the texture's full width and height instead of just the area I'm using. This is resulting in some giant allocations for every single small sprite I'm using. 


I think I just need to figure out a way for the editor to detect selection that's not per pixel collision. . .


If anyone has any suggestions or can help, lemme know -_-;;

Oct 10, 2011 at 12:51 AM

You can comment coldata stuff out.

It is not needed if you do not want per-pixel collision.

In file textureitem.editable change intersectpixels function to this:

public bool intersectpixels(Vector2 worldpos)
            Vector2 positionInB = Vector2.Transform(worldpos, Matrix.Invert(transform));
            int xB = (int)Math.Round(positionInB.X);
            int yB = (int)Math.Round(positionInB.Y);

            if (FlipHorizontally) xB = texture.Width - xB;
            if (FlipVertically) yB = texture.Height - yB;

            // If the pixel lies within the bounds of B
            if (0 <= xB && xB < texture.Width && 0 <= yB && yB < texture.Height)
                //return true;
                //   Color colorB = coldata[xB + yB * texture.Width];
                // if (colorB.A != 0)
                // {
                return true;
                //  }
            return false;

Nov 13, 2011 at 11:31 AM

Found an issue where he isn't deleted unused bmp data.

            foreach (FileInfo file in files)
                Bitmap bmp = new Bitmap(file.FullName);
                imageList48.Images.Add(file.FullName, getThumbNail(bmp, 48, 48));
                imageList64.Images.Add(file.FullName, getThumbNail(bmp, 64, 64));
                imageList96.Images.Add(file.FullName, getThumbNail(bmp, 96, 96));
                imageList128.Images.Add(file.FullName, getThumbNail(bmp, 128, 128));
                imageList256.Images.Add(file.FullName, getThumbNail(bmp, 256, 256));

                ListViewItem lvi = new ListViewItem();
                lvi.Name = file.FullName;
                lvi.Text = file.Name;
                lvi.ImageKey = file.FullName;
                lvi.Tag = "file";
                lvi.ToolTipText = file.Name + " (" + bmp.Width.ToString() + " x " + bmp.Height.ToString() + ")";



Jan 8, 2012 at 2:45 PM


I've been rewriting this tool and with the permission of zissakos, I'm now hosting it at http://github.com/stevedunn/gleed2d
The code around images and icons has been completely rewritten.  I'd be interested to see if you get any problems with the latest version.