Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jperalta

Weird problem [C#]

This topic is 5477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The following code causes a fatal error in System.Drawing.DLL whenever I compile in Release, but not in Debug:
void LoadImages() {
	gunImage = Image.FromFile("images/gun.gif");
	for (int i = 0; i < 8; i++) {
		attackImages[i] = Image.FromFile("images/attack"+i+".gif",false);
		if (i < 7)
			ufoImages[i] = Image.FromFile("images/ufo" + i + ".gif",false);
		if (i < 4)
			explodeImages[i] = Image.FromFile("images/explode" + i + ".gif",false);
	}
}

Share this post


Link to post
Share on other sites
Advertisement
I know little of C# and it''s ways. However, that hasn''t stopped me from answering anything before, so... :\

It wouldn''t be something like the paths are relative, so they might end up pointing somewhere else in Release rather than Debug. e.g. "./Debug/images/attack0.gif" becomes "./Release/images/attack0.gif" during Release?

Ro_Akira

Share this post


Link to post
Share on other sites
Is it a fatal error? Or is an exception thrown?

Wrap the code in a try/catch block OR handel this event:

AppDomain.CurrentDomain.UnhandledException

-SniperBoB-

Share this post


Link to post
Share on other sites
That just breaks it more Basically, if the is thrown then the pictures aren't loaded and there are lots and lots of null reference exceptions

[edited by - jperalta on November 14, 2003 2:49:59 PM]

Share this post


Link to post
Share on other sites
quote:

Basically, if the exception? is thrown then the pictures aren''t loaded and there are lots and lots of null reference exceptions



Is there a need for clarification?

Ro_Akira

Share this post


Link to post
Share on other sites
Hrm... I guess the problem is actually as follows:

If I use the code above to load the images I get a System.OutofMemoryException at gunImage = Image.FromFile("images/gun.gif");

if I replace that with ''gunImage = new Bitmap("images/gun.gif");'' I get a System.ArgumentException (Invalid Parameter Used) in the same place instead of the out of memory exception.

Share this post


Link to post
Share on other sites
Again, I''d like to cover myself by declaring that I''ve never touched C#...

"If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception." - MSDN

Strange, but true. Who''d have thought an OutOfMemoryException could indicate that?!

Ro_Akira

Share this post


Link to post
Share on other sites
from the .NET framework documentation about the Image.FromFile() method:
quote:
.NET Framework Documentation
If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception.


Yes docs are your friend. I''d find out which file formats and pixel formats GDI+ supports and check your file if it matches them.

Share this post


Link to post
Share on other sites
hmm , hit quote button instead of edit. but anyways, beaten by 7 seconds

[edited by - deathtrap on November 14, 2003 3:44:36 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!