Weird problem [C#]

Started by
20 comments, last by jperalta 20 years, 5 months ago
Why then, does it load the file in Debug but not in Release?
Advertisement
what is gunImage? what is it defined as and where is it defined?
When I used VJ++, my programs for some reason would run faster in debug than in release form. Odd stuff.

Maybe you should try deleting all the workspace/project files or cutting and pasting the source code into a new workspace/project.
quote:
Why then, does it load the file in Debug but not in Release?


Indeed. This makes me think that it perhaps has something to do with the settings specified for a Release build?

It's not 100% clear from the MSDN docs, but I wonder does Image.FromImage throw OutOfMemoryException if the file doesn't exist at all?

The docs don't list any possible exceptions that Bitmap (String) might throw, but if your getting "Invalid Parameter Used", I'd guess that the actual path "images/gun.gif" is wrong. I'd double check yer files/paths.

quote:
what is gunImage? what is it defined as and where is it defined?

I'd guess it's of type System.Drawing.Bitmap. Bitmap (String) for example returns a System.Drawing.Image, but that's an abstract base class. Since there are exceptions emminating from both Bitmap(String), and Image.FromFile (), I think the problem lies there...

See disclaimers in above posts if you believe I'm talking rubbish.

Ro_Akira

[edited by - Ro_Akira on November 14, 2003 4:07:57 PM]

[edited by - Ro_Akira on November 14, 2003 4:08:41 PM]
I experienced an out of memory exception when messing with images but only because I did not dispose of the bitmap that I was using for double-buffering. It was like this:

loop
create a bitmap
end loop

Which obviously created a new bitmap each frame. =X Your problem may not be in LoadImages, but somewhere else where there is looping.
gunImage is a System.Drawing.Image and it is defined in the class in which LoadImages() resides.
quote:Original post by Anonymous Poster
I experienced an out of memory exception when messing with images but only because I did not dispose of the bitmap that I was using for double-buffering. It was like this:

loop
create a bitmap
end loop

Which obviously created a new bitmap each frame. =X Your problem may not be in LoadImages, but somewhere else where there is looping.


Definately in LoadImages(), that function is only called once in the program (at the beginning) and it crashes as soon as it gets to gunImage = Image.FromFile...

[edited by - jperalta on November 14, 2003 4:33:09 PM]
What it says about Image:
"An abstract base class that provides functionality for the Bitmap and Metafile descended classes" - MSDN

You should probably declare gunImage as System.Drawing.Bitmap? I don't see how it could produce the problems you're having but...

See disclaimers in above posts if you believe I'm talking rubbish.

[edit]
I think I may be talking a bit of rubbish. FromFile returns a derived class of Image, which might be Bitmap for example. But doing a gunImage.GetType().ToString(); and dumping it out will reveal it to be not really an Image, but of type 'whatever FromFile returned'. Regardless, this is all irrelevant to the problem...
[/edit]

Ro_Akira

[edited by - Ro_Akira on November 14, 2003 5:00:16 PM]
hmm, exactly where is LoadImage() being called? ..
		void Init() 		{			// Basic form setup.			this.BackColor = Color.Black;			this.Show();			// Load UFO images			LoadImages();			// Event handlers#if !(DIRECTINPUT)			this.MouseMove += new MouseEventHandler(mouseMove);			this.MouseDown += new MouseEventHandler(MousePress);#else			InitializeDirectInput();#endif			this.KeyDown += new KeyEventHandler(KeySet);			this.KeyUp += new KeyEventHandler(KeyRelease);			this.Closing += new CancelEventHandler(Stop);			// Setup DirectDraw			InitializeDirectDraw();			s = new Size(this.Width,this.Height);			// Initialize the game managers			um = new UFOManager(s,ufoImages,attackImages,explodeImages);			gm = new GunManager(s,gunImage,um.UFOS);			um.Initialize(gm);						// Start the game			start = new ThreadStart(Run);			animation = new Thread(start);			animation.Start();		}

This topic is closed to new replies.

Advertisement