SFML community forums

Help => Graphics => Topic started by: SvenB on November 17, 2008, 11:32:36 am

Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: SvenB on November 17, 2008, 11:32:36 am
Hi...

Code: [Select]
sf::Image Image1 ;
Image1.Create( 100, 100, sf::Color::Blue ) ;


crashes with 0xC0000005. This holds true for several different computers running Windows XP SP2 or SP3. On _some_ pretty new machines the code runs without error.

If I create a really small image, say Create( 10, 10,...) the program doesn't crash but the image is garbage (random pixels in the image area).

The same behavior can be seen with Image.LoadFromFile():

Code: [Select]
sf::Image Image1 ;
Image1.LoadFromFile("mypic.bmp") ;


crashes on some machines, on others a garbage picture is displayed, on very new computers it works.

This whole thing seems similar to the svn: font problem
http://www.sfml-dev.org/forum/viewtopic.php?t=704

Since the created or loaded images are garbage, maybe a memory allocation problem, same could be the reason for crashes on font load.

ciao - Sven
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: zarka on November 17, 2008, 01:19:06 pm
umm see the thread 2 posts down perhaps ?...

http://www.sfml-dev.org/forum/viewtopic.php?t=726
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: SvenB on November 17, 2008, 01:59:52 pm
Quote from: "zarka"
umm see the thread 2 posts down perhaps ?...

http://www.sfml-dev.org/forum/viewtopic.php?t=726


Probably not, because
- I receive no error message 'can't load font'
- I have no ASCII-sequence in the command window

-Sven-
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: wizardofoz on November 18, 2008, 09:50:11 am
Surely I'm wrong but after some investigations I've discovered a similiar thing.
I tested normal SFML code in differents PC with NVIDIA and ATI cards with the last drivers installed:

On some PC SFML code doesn't work and crashes.

I built a simple logging system for every line of code and I discovered that the problem was in the loading of images that haven't power-of-2 dimensions.

I examined the source code of CreateTexture() function, I'm far from an expert but:


If non-power-of-2-dimensions aren't supported SFML calculates new power-of-2 bigger image sizes with the function GetValidTextureSize(unsigned int Size)
but the buffer of the image just loaded is not updated with the new size.
So when we call:...


Code: [Select]
GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, GetPixelsPtr()));


myTextureWidth and myTextureHeight are bigger than the real buffer dimension retrieved with GetPixelPtr().

Could be this the reasons of these crashes? If not I'm sorry...
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: wizardofoz on November 18, 2008, 10:10:21 am
Last news:

I tried to update the image buffer with the new power of 2 sizes before calling glTexImage2D and the code now runs ON ALL PCs without problems .

So this sort of bug can crash your program with non-power-of-2 images and even with fonts (because they are loaded into textures).
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Laurent on November 18, 2008, 10:35:18 am
That's amazing, I think you actually solved the problem.

Some time ago I found this piece of code and asked to myself "damn, why do I pass NULL and then ask for an update, instead of sending the pixels directly?". Now I know why.
I should definitely leave a comment after fixing it.

I'll apply the fix as soon as possible, thank you very much for your help. I think you'll make a lot of people happy :)
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: wizardofoz on November 18, 2008, 10:47:58 am
I'm very happy if I could help you  :)
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: katrin on November 18, 2008, 01:39:14 pm
I had these problems - programms working with one graphic card (S3 VIA Chrome9 HC IGP) and somehow crashing with another (NVIDIA GeForce4 Ti4200, Matrox G550)) (everything else same) - as well.

Even though the here mentioned problems are far beyond my programming knowledge and your solution seems to concern images, is it possible that these strange font problems http://www.sfml-dev.org/forum/viewtopic.php?t=704 might be solved as well by that?!?
I know they sound weired. But I could always get a programm running on all the older pc's when I change the font to arial size 100.

I will hopefully belong to the group of happy people as soon as you fixed it - thanx for your effort  :D
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Laurent on November 18, 2008, 01:59:54 pm
Quote
is it possible that these strange font problems http://www.sfml-dev.org/forum/viewtopic.php?t=704 might be solved as well by that?!?

Probably not, because your crash happens in wglChoosePixelFormat.
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Wizzard on November 18, 2008, 02:06:26 pm
We wizards are pretty amazing, huh?

I'm extremely happy to see one of these incompatibility bugs fixed.
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Imbue on November 18, 2008, 10:56:33 pm
I'm 99% sure this is going to fix my problem over here (http://www.sfml-dev.org/forum/viewtopic.php?t=725). It's funny how bugs like this look so obvious after someone points them out.

Good work, and thanks, wizardofoz. :D
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Laurent on November 20, 2008, 06:08:33 pm
I just fixed it. If you were previously concerned by this bug, please post your feedback :)
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Imbue on November 20, 2008, 09:17:29 pm
I've only had time to test it on one computer, but it crashed before and it doesn't crash now!

I had one place I was manually coding texture coordinates in and that's now screwed up. I fixed it with the Image::GetTexCoords() function which works like a champ. Moral of the story, don't manually code in texture coordinates.

Thanks a ton, wizardofoz and Laurent. :D


Edit: I've since had time to test more computers. It's working on all of them. :D
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: wizardofoz on November 21, 2008, 09:31:18 am
Very happy to have been helpful :)
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: SvenB on November 21, 2008, 01:47:26 pm
Yes. Yes. Yes.

I tried some image loading and image creating and it runs
perfect. I tested it on two different machines which have had
the problems. I will do some more testing but I'm pretty sure
all is okay.

AND:

This weired font-load-problem
 http://www.sfml-dev.org/forum/viewtopic.php?t=704
is gone, too.

Thanx for all the help.
-Sven-
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: Laurent on November 21, 2008, 01:53:06 pm
Great news :)
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: katrin on November 21, 2008, 02:07:44 pm
great ... ist seems to solve more things than expected, e.g. the weird font stuff, too.

thanx again wizardofoz & laurent  :D  :D
you truly made a lot of people happy
Title: svn: Image.LoadFromFile and Image.Create crashes
Post by: T.T.H. on November 25, 2008, 10:38:06 pm
Confirmed! Using revision 927 which includes Larent's fix based on wizardofoz' description solved one of my two problems (http://www.sfml-dev.org/forum/viewtopic.php?p=5028#5028), thank you so much!