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

Author Topic: Debug Assertion when using 'Texture.update(sf::Window)'  (Read 6031 times)

0 Members and 1 Guest are viewing this topic.

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 02, 2016, 06:46:59 pm »
So, I'm trying to update my texture but when I do that my game triggers a assertion which tells me :
Assertion failed: x + window.getSize().x <= m_size.x, file (long path)\Texture.cpp

In my code, this line triggers the assertion :
gResourceMgr.GetTexture(textureName)->update(gGraphics.GetWindow());

GetTexture() is this :
sf::Texture* ResourceManager::GetTexture(std::string file)
{
        if (textures.find(file) != textures.end())
        {
                return textures.find(file)->second;
        }
        else
        {
                std::cout << "Failed to get file : " << file << " from resource manager." << std::endl;
                return nullptr;
        }
}

And the textures map looks like this :
std::map<std::string, sf::Texture*> textures;

The gGraphics.GetWindow() function simply returns a reference to the games RenderWindow.

Unsure what I'm doing wrong :/
« Last Edit: December 03, 2016, 10:43:46 am by BiiXteR »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #1 on: December 02, 2016, 09:07:58 pm »
This assertion is triggered in Texture::Update(Window&). That, plus the fact that you mention gGraphics.GetWindow() without it being in your posted code, makes me think that you're not showing everything, especially the most important part.
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #2 on: December 03, 2016, 12:38:22 am »
The GetWindow  function is this :

sf::RenderWindow& Graphics::GetWindow()
{
        return mWindow;
}

and mWindow is this :

sf::RenderWindow mWindow;

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #3 on: December 03, 2016, 10:07:34 am »
But why did you mention it in your first post? And are you really really sure that the assertion is triggered by mSprite.setTexture?
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #4 on: December 03, 2016, 10:41:36 am »
But why did you mention it in your first post? And are you really really sure that the assertion is triggered by mSprite.setTexture?

Not sure what you mean by "why did you mention it in your first post" ?
Yes, that is the line that triggers the assertion (according to visual studio at least), but I have no idea why.

Ediiiit :
No, incorrect line. Pasted the wrong line in the post ._. Sorry. Edited the original post with the correct line.

And now I understand what you meant, and that's the reason I mentioned it in my post :P
« Last Edit: December 03, 2016, 10:44:37 am by BiiXteR »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #5 on: December 03, 2016, 01:03:59 pm »
You should have added the correct line in a new reply instead of editing your first post. Now the whole thread looks very confusing :P

Anyway. The assertion is clear: the size of the window is greater than the size of the texture. Now it should be pretty easy for you to figure out why.
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #6 on: December 04, 2016, 02:35:18 pm »
You should have added the correct line in a new reply instead of editing your first post. Now the whole thread looks very confusing :P

Anyway. The assertion is clear: the size of the window is greater than the size of the texture. Now it should be pretty easy for you to figure out why.

Shouldn't the size of the window be more than the texture?
If the window size is less wouldn't that result in a texture which covers the entire screen?

Or should the texture be bigger than the screen and then scaled down?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #7 on: December 04, 2016, 04:43:45 pm »
There's no scaling, it's a raw copy from the source window to the target texture. So if the source is bigger than the destination, you are out of the memory range which results in undefined behaviour. That's what the assert checks.
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #8 on: December 04, 2016, 06:46:05 pm »
There's no scaling, it's a raw copy from the source window to the target texture. So if the source is bigger than the destination, you are out of the memory range which results in undefined behaviour. That's what the assert checks.

Oh yeah, ofc theres no scaling, was thinking of sprites. lol :P

By "source > distination" you mean "texture > window" ?
If yes, I know that the texture is much smaller than the window is.
(the texture is 32.x32 pixels, and the window is 1024x720)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #9 on: December 04, 2016, 07:38:05 pm »
No. You update the texture from the window. So the source is the window and the destination is the texture. So you're doing something wrong with your 32x32 texture.
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #10 on: December 04, 2016, 08:01:55 pm »
No. You update the texture from the window. So the source is the window and the destination is the texture. So you're doing something wrong with your 32x32 texture.

Can't find out how to resize the texture so that it is the same size as my window since the texture resizes itself to the size of the loaded image.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #11 on: December 04, 2016, 08:19:39 pm »
Why would you overwrite a loaded texture with the content of the window? Usually you create an empty texture of the required size, when you want to update it from a window.

You should explain what you're trying to achieve, that will probably be faster than trying to fix whatever you think you must do ;)
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #12 on: December 04, 2016, 08:58:32 pm »
Why would you overwrite a loaded texture with the content of the window? Usually you create an empty texture of the required size, when you want to update it from a window.

You should explain what you're trying to achieve, that will probably be faster than trying to fix whatever you think you must do ;)

I was having a problem where my game would run fine but not display a sprite.
After some playing around with it I found a update function which I assumed (for some reason) was used to update the texture when a image has been assigned to it.

Now on second thought, is that even what texture.update() should be used for...?
« Last Edit: December 04, 2016, 09:00:04 pm by BiiXteR »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #13 on: December 04, 2016, 09:07:03 pm »
Not at all... As already said, and probably well explained in the documentation, all the Texture::update functions upload new content to the texture. The Texture::update(Window&) overload uploads the contents of the window (ie. what you currently see) into the texture.

Don't try random stuff, just follow the doc and tutorials. And if you have problems, just ask.
Laurent Gomila - SFML developer

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Debug Assertion when using 'Texture.update(sf::Window)'
« Reply #14 on: December 04, 2016, 09:34:15 pm »
Not at all... As already said, and probably well explained in the documentation, all the Texture::update functions upload new content to the texture. The Texture::update(Window&) overload uploads the contents of the window (ie. what you currently see) into the texture.

Don't try random stuff, just follow the doc and tutorials. And if you have problems, just ask.

Honestly not sure how, but when I read the docs, using update() seemed like the perfect solution to my problem. :P

Fixed the issue I had before I even tried using update though, for some reason SFML didn't like to render my .bmp so I made a png instead and it started working.