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

Author Topic: Don't create rendertexture if there is not enough memory left.  (Read 2472 times)

0 Members and 1 Guest are viewing this topic.

killerloader

  • Newbie
  • *
  • Posts: 28
    • View Profile
I've been testing my game on computers with little video memory, and because my game uses a lot of rendertextures, after a while an error shows up "failed to share opengl context" - or something like that
So, is there a way for me to see if there is enough video memory available to create one, or is there a way to see if it correctly got created after creating it, and then disabling the error message that gets shown when it is created.

Sorry if this question has already been answered elsewhere, i didn't quite know how to word it.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Don't create rendertexture if there is not enough memory left.
« Reply #1 on: June 08, 2015, 05:32:19 pm »
when you do this

sf::RenderTexture myTexture ;
myTexture.loadFromFile( "image.png" )

// you can do that:

if ( !myTexture.loadFromFile( "image.png" ) )
   //error or whatever you want.
  // loadFromFile can fail for several reasons, one of this reasons can be there is no more vram.
 
I would like a spanish/latin community...
Problems building for Android? Look here

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Don't create rendertexture if there is not enough memory left.
« Reply #2 on: June 08, 2015, 11:36:52 pm »
sf::RenderTextures cannot be loaded from a file.

You can use the boolean return value from renderTexture.create() to test for successful creation.
e.g.
sf::RenderTexture renderTexture;
if (!renderTexture.create(300, 200))
    std::cerr << "Render Texture of 300x200 was not successfully created." << std::endl;
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

killerloader

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Don't create rendertexture if there is not enough memory left.
« Reply #3 on: June 09, 2015, 05:46:11 am »
Thankyou,
The obvious and simple way of doing it! - Sorry for the simple question, i just didn't have time to play around and find out how.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Don't create rendertexture if there is not enough memory left.
« Reply #4 on: June 10, 2015, 09:10:24 pm »
You're welcome. Hope it helps with what you were aiming to do  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*