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

Author Topic: [update, bug in sfml?] Question about SFML's texture.cpp assertion fail  (Read 4243 times)

0 Members and 1 Guest are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Hi,
when I debug my app i get following assertion failed errors:

File: D:\developpement\sfmp-master\src\SFML..\Texture.cpp
Line: 315
Expression: x + width <= m_size.x
Assertion failed

File: D:\developpement\sfmp-master\src\SFML..\Texture.cpp
Line: 316
Expression: y + height <= m_size.y
Assertion failed

It happens both with static and dynamic libs on debug exe. I don't even have that D:\developpement dir on my disk.
Release build works without any problems when linked statically (however it gives error memory cant be read after exiting while using dynamic sfml libs). I don't use any other libs.
I can't give minimal code because it crashes the debugger just after opening window (it doesn't make it to draw loop, if I ignore both errors I just get white screen in my draw loop). So I have no idea how to track what's exactly wrong (I don't have experience with using debuggers), I just want to know what may be the reason of those sfml error and I will track it myself.

In one topic I found that those errors happen when texture is too big for gpu, but my gpu is 6870 and I use only 30x30 textures and 30 text size (And I don't render to texture).

Thanks

IMPORTANT EDIT:

Well, I got it. It may be sfml bug I think?
Here's the code with that error.  Compile it as debug with debug graphics, window and system libs. SFML 2 ofc.

 
 #include <SFML/Graphics.hpp>

    sf::Image emptyImage;
    sf::Texture emptyTexture;

 int main()
  {
    emptyImage.create(50, 50, sf::Color::White);
    emptyTexture.update(emptyImage);

   return 0;
  }
 

Doing this makes asserts errors in debug builds. I think that doing this shouldn't result in error. Is it meant to be this way? I checked source code and I understand why that assert is there, however I think it doesn't always work (as you see in above code). Lauren, could you look into it? Thanks

There should be function to set width and height of texture, something like setSize or overloaded constructor. Empty texture is very useful, for example resource manager (when render asks for texture which doesn't exist (ie file was deleted), it's a good idea to return empty texture rathen than crash entire application).
« Last Edit: August 27, 2012, 04:18:46 pm by netrick »

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [update, bug in sfml?] Question about SFML's texture.cpp assertion fail
« Reply #1 on: August 27, 2012, 09:21:53 pm »
Hello,

Maybe, this works better :
 #include <SFML/Graphics.hpp>

    sf::Image emptyImage;
    sf::Texture emptyTexture;

 int main()
  {
    emptyImage.create(50, 50, sf::Color::White);
    emptyTexture.create(50, 50); //< Créer la texture sur la VRAM
    emptyTexture.update(emptyImage);

   return 0;
  }

I see this in the update(const sf::Image&) method :
Quote
void sf::Texture::update(const Image & image)  

Update the texture from an image.

Although the source image can be smaller than the texture, this function is usually used for updating the whole texture. The other overload, which has (x, y) additional arguments, is more convenient for updating a sub-area of the texture.

No additional check is performed on the size of the image, passing an image bigger than the texture will lead to an undefined behaviour.

This function does nothing if the texture was not previously created.
« Last Edit: August 27, 2012, 09:24:01 pm by victorlevasseur »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [update, bug in sfml?] Question about SFML's texture.cpp assertion fail
« Reply #2 on: August 27, 2012, 10:26:40 pm »
It's not supposed to break on this assert since the size of the (empty) image is zero.

What's your compiler? OS? Version of SFML?

Are you sure that you don't use release libraries in debug mode?
Laurent Gomila - SFML developer