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

Author Topic: Getting a stack error using sf::Image that kills my program  (Read 3105 times)

0 Members and 1 Guest are viewing this topic.

poncho

  • Newbie
  • *
  • Posts: 7
    • View Profile
Getting a stack error using sf::Image that kills my program
« on: August 19, 2011, 12:53:23 pm »
Hi,

I've just moved from SDL to SFML to make use of the awesome multiple windows capability.

My problem is that I was loading in textures using SDL before and so now want to do it with SFML. I have the following code but when the method exits I get an error saying the program has triggered a breakpoint, with one of the possible errors being that there is corruption of the heap.

When I step through the method, I can see that for some reason the sf::Image object has about 1000000 pointers to rgba values which are all ERROR and says the width of the image is about 3200000 and the height the same amount.

What has happened to sf::Image? Is what I am doing the correct way of using it?

Thanks for your time,

Poncho

Here is my code:

Code: [Select]

sf::Image myImage;

if(myImage.LoadFromFile("testimage.png")) {
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &texture );

// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture );

// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, myImage.GetWidth(), myImage.GetHeight(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, myImage.GetPixelsPtr());
} else {
printf("ERROR: Could not load image\n");
}


EDIT: I also just tried the opengl sample code that comes in the zip of SFML and I see a spinning cube but no texture mapped to it. I've even tried creating my own texture and loading it in to be mapped to it. It seems it is doing the same this as in my program, it passes the if(image.load...) test but hasn't actually loaded anything in as nothing is initialised so the width is 3435873836 etc.

EDIT: I was just trying it again and where I get the dialog box saying "triggered a breakpoint..." I then get another dialog saying "The stack around myImage is corrupted.". Not sure if that helps.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Getting a stack error using sf::Image that kills my program
« Reply #1 on: August 19, 2011, 01:08:46 pm »
Why do you have OpenGL code? Unlike SDL, SFML is itself fast enough to draw images without forcing the user to deal with raw OpenGL.

You can just use sf::Sprite to represent images on the screen. By the way, in SFML 2 you will mostly use sf::Texture instead of sf::Image.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

poncho

  • Newbie
  • *
  • Posts: 7
    • View Profile
Getting a stack error using sf::Image that kills my program
« Reply #2 on: August 19, 2011, 01:49:04 pm »
Well I am using OpenGL many other places in the system and was just rewriting my SDL code so might change it in the future.

Thanks for the advice, but the image loading problem still stands, anyone have any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting a stack error using sf::Image that kills my program
« Reply #3 on: August 19, 2011, 01:59:49 pm »
Make sure that you're not using release libraries in debug mode, or VC++ 2008 libraries with VC++ 2010.
Laurent Gomila - SFML developer

poncho

  • Newbie
  • *
  • Posts: 7
    • View Profile
Getting a stack error using sf::Image that kills my program
« Reply #4 on: August 20, 2011, 11:09:33 am »
I just downloaded the 1.6 version from the website and am using it in VC++ 2010.

How do I tell if it is debug or release version? Because the one I downloaded from here is being used in debug mode.

Thanks for the replies,

Poncho

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Getting a stack error using sf::Image that kills my program
« Reply #5 on: August 20, 2011, 06:05:11 pm »
Quote
I just downloaded the 1.6 version from the website

So it's not a version suitable for VC++ 2010, it's either 2008 or 2005. You must recompile SFML.
Laurent Gomila - SFML developer

sfml_coder

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Getting a stack error using sf::Image that kills my prog
« Reply #6 on: August 22, 2011, 05:46:31 pm »
I had similar issues trying to code the sample about the sprites.
I was not able to understand what was going on in no way after hundred test  I understood the problem was simply I was using the "debug" configuration in VC2008 but in the linker configuration option I was using the sfml-graphics-s.lib library.. the right one to use in "debug" is sfml-graphics-d.lib instead , then once the code is ok and I want to redistribuite I simply change the vc configuration to "release" where in the linker option I have sfml-graphics-s.lib

So

Debug configuration ->  use sfml-xxx-d.lib in linker options
Release configuration-> use sfml-xxx-s.lib in linker options

obviously I'm talking about -s version because I don't want to use the .dll, this may not be your case

PS. in debug config, if you are using the debug dll version don't forget to add the "SFML_DYNAMIC" string in the C++ preprocessor definitions, else you'll get strange linker errors

 

anything