Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: svn: Image.LoadFromFile and Image.Create crashes  (Read 11059 times)

0 Members and 1 Guest are viewing this topic.

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
svn: Image.LoadFromFile and Image.Create crashes
« 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

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #1 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
//Zzzarka

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
svn: Image.LoadFromFile and Image.Create crashes
« Reply #2 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-

wizardofoz

  • Newbie
  • *
  • Posts: 18
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #3 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...

wizardofoz

  • Newbie
  • *
  • Posts: 18
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #4 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).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
svn: Image.LoadFromFile and Image.Create crashes
« Reply #5 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 :)
Laurent Gomila - SFML developer

wizardofoz

  • Newbie
  • *
  • Posts: 18
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #6 on: November 18, 2008, 10:47:58 am »
I'm very happy if I could help you  :)

katrin

  • Newbie
  • *
  • Posts: 17
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #7 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
svn: Image.LoadFromFile and Image.Create crashes
« Reply #8 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.
Laurent Gomila - SFML developer

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #9 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.

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #10 on: November 18, 2008, 10:56:33 pm »
I'm 99% sure this is going to fix my problem over here. It's funny how bugs like this look so obvious after someone points them out.

Good work, and thanks, wizardofoz. :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
svn: Image.LoadFromFile and Image.Create crashes
« Reply #11 on: November 20, 2008, 06:08:33 pm »
I just fixed it. If you were previously concerned by this bug, please post your feedback :)
Laurent Gomila - SFML developer

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #12 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

wizardofoz

  • Newbie
  • *
  • Posts: 18
    • View Profile
svn: Image.LoadFromFile and Image.Create crashes
« Reply #13 on: November 21, 2008, 09:31:18 am »
Very happy to have been helpful :)

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
svn: Image.LoadFromFile and Image.Create crashes
« Reply #14 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-

 

anything