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

Author Topic: sf::Image heap corruption  (Read 2195 times)

0 Members and 1 Guest are viewing this topic.

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
sf::Image heap corruption
« on: November 05, 2011, 01:57:45 pm »
Hi, I seem to have developed a problem, when closing my app I get a heap corruption error from the Image destructor.
I remember seeing that this was a fault some time ago but I thought it was fixed.
I also read that it could be an error due to me having intel graphics.
It happens with both the 1.6 version and 2.0

The program im using is quite complex but I will try and recreate the error in a simple app

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
sf::Image heap corruption
« Reply #1 on: November 05, 2011, 02:14:03 pm »
I managed to recreate the problem with this code, it mixes pure openGL and sfml as I need to be able to use both with my app.

Code: [Select]
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{

sf::RenderWindow App;
sf::Sprite backGroundSprite;
sf::Image backgroundTexture;

sf::Sprite backGroundSprite2;
sf::Image backgroundTexture2;

sf::WindowSettings Settings;
Settings.DepthBits         = 24; // Request a 24 bits depth buffer
Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = 2;  // Request 2 levels of antialiasing

App.Create(sf::VideoMode(800, 600, 32), "Window", sf::Style::Close ,Settings);

App.UseVerticalSync(true);

App.ShowMouseCursor(false);

App.PreserveOpenGLStates(true);

GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
std::cout << "Error: " << glewGetErrorString(err) << std::endl;
return false;
}
else
{
std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
}

glEnable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
// Cull triangles which normal is not towards the camera
glEnable(GL_CULL_FACE);

backgroundTexture.LoadFromFile("./Data/MenuBackground.png");
backGroundSprite =  sf::Sprite();
backGroundSprite.SetImage(backgroundTexture);
backGroundSprite.SetPosition(0.f,0.f);
sf::Vector2f scale;
scale.x = float(App.GetWidth()) / backGroundSprite.GetImage()->GetWidth();
scale.y = float(App.GetHeight()) / backGroundSprite.GetImage()->GetHeight();
backGroundSprite.SetScale(scale);

float time = 0.0f;

while(App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window
if (Event.Type == sf::Event::Closed)
App.Close();

// Escape key pressed
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();

if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}

if(!App.IsOpened())  break;

time += App.GetFrameTime();

App.SetActive();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Dark blue background
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);

App.Draw(backGroundSprite);

glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

App.Display();
}
}

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
sf::Image heap corruption
« Reply #2 on: November 05, 2011, 02:28:32 pm »
Managed to trim it down to this and still get the error:


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

int main()
{

sf::RenderWindow App;
sf::Sprite backGroundSprite;
sf::Image backgroundTexture;

App.Create(sf::VideoMode(800, 600, 32), "Window");

App.PreserveOpenGLStates(true);

backgroundTexture.LoadFromFile("./Data/MenuBackground.png");
backGroundSprite =  sf::Sprite();
backGroundSprite.SetImage(backgroundTexture);

while(App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}

App.SetActive();
App.Clear();

App.Draw(backGroundSprite);

App.Display();
}
}


However if I comment out the

Code: [Select]
App.PreserveOpenGLStates(true);

I dont get heap corruption

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image heap corruption
« Reply #3 on: November 05, 2011, 03:09:01 pm »
If you tried both SFML 1.6 and 2.0, then please provide an example that uses 2.0. I don't work on 1.6 anymore ;)
Laurent Gomila - SFML developer

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
sf::Image heap corruption
« Reply #4 on: November 05, 2011, 06:23:09 pm »
I have tried my application on my desktop with an ATI card and I didnt get any errors so it seems its due to intel drives, which is very anoying :/