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

Author Topic: sf::Image.LoadFromFile might be causing invalid pointers?  (Read 3335 times)

0 Members and 1 Guest are viewing this topic.

Jedimace1

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::Image.LoadFromFile might be causing invalid pointers?
« on: February 25, 2010, 02:04:17 am »
Hello,

I'm getting this really weird problem in my SFML/OpenGL application. I've created my application, which should render a triangle in multiple colors and then a square with a texture on it. I used SFML's texture loading for my texture, but then I ran into this really weird problem. I'm sure it's this line specifically because I commented out everything else and it still happened. When I run my program, it beeps once about ever third of a second, and shows a bunch of stuff in the console, and then it crashes saying that the OpenGL buffer got overrun (even when I don't use OpenGL). Here's my code:

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main() {
sf::Window window(sf::VideoMode(800, 600), "Rendering", sf::Style::Close);

sf::Image image;

        //Problem line....
if(!image.LoadFromFile("Texture.png")) {
return 1;
}

GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.GetWidth(), image.GetHeight(),
0, GL_RGB, GL_UNSIGNED_BYTE, image.GetPixelsPtr());

glClearDepth(1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, 1.0f, 1.0f, 500.0f);

while (window.IsOpened()) {
sf::Event evnt;
while(window.GetEvent(evnt)) {
switch(evnt.Type) {
case sf::Event::Closed:
window.Close();
}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(-1.5f,0.0f,-6.0f);

glBegin(GL_TRIANGLES);
glColor4f(0.0f,255.0f,255.0f,255.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);

glColor4f(255.0f,0.0f,255.0f,255.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);

glColor4f(255.0f,255.0f,0.0f,255.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();

glTranslatef(3.0f,0.0f,0.0f);
glRotatef(-25.0f, 0.0f, 1.0f, 0.0f);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);

glBegin(GL_QUADS);
glTexCoord2f(1.0f,1.0f);
glVertex3f( -1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-1.0f,0.0f, 0.0f);
glTexCoord2f(1.0f,0.0f);
glVertex3f( 0.0f,0.0f, 0.0f);
glTexCoord2f(1.0f,1.0f);
glVertex3f( 0.0f,1.0f, 0.0f);
glEnd();

glDisable(GL_TEXTURE_2D);

window.Display();
}
}

return EXIT_SUCCESS;
}


And here's the error I get in a pop-up window asking me to break/continue the program.

Code: [Select]
Unhandled exception at 0x737a84b4 in OpenGL render.exe: 0xC0000005: Access violation reading location 0x003e9000.

I'm running a Radeon HD 5850 with SFML 1.5 prebuilt. Thanks for any help.
-Jedimace1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image.LoadFromFile might be causing invalid pointers?
« Reply #1 on: February 25, 2010, 08:29:41 am »
Are you using release SFML libraries in debug mode?
Laurent Gomila - SFML developer

Jedimace1

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::Image.LoadFromFile might be causing invalid pointers?
« Reply #2 on: February 25, 2010, 12:30:15 pm »
Release. Should I try the debug ones?
-Jedimace1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image.LoadFromFile might be causing invalid pointers?
« Reply #3 on: February 25, 2010, 12:36:11 pm »
You must use the libraries that match your configuration. Debug libraries (suffix "-d") in debug mode, release ones in release mode.
Laurent Gomila - SFML developer

Jedimace1

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::Image.LoadFromFile might be causing invalid pointers?
« Reply #4 on: February 25, 2010, 12:38:24 pm »
Wow, thanks. It worked. =)
-Jedimace1

 

anything