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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - killerloader

Pages: 1 [2]
16
Graphics / [SOLVED] Copying texture from rendertexture.
« on: February 22, 2015, 01:08:03 pm »
I want to use one rendertexture multiple times to create different images (As i've found deleting and creating new render textures to create massive memory leaks)
Basically i want to copy the 'texture' data from the rendertexture into a new sf::Texture.
I saw that you could save a render texture's texture to file, and then load it again into a new texture, however this would be pretty inefficient for per-step events.

Sorry if there is a simple function for this, i did look for a few minutes, but found no 'completely obvious' functions that do this.
As RenderTexture.GetTexture() will change as the render-texture changes.
As i was writing this, i thought of doing:
sf::Texture TestTexture;
TestTexture = RenderTexture.GetTexture();
Would this copy the texture data? or would it also keep a pointer to the texture data. I don't exactly have time to test it right now, so, sorry for a seemingly stupid question which i should probably hold off until i test that code myself.

17
Graphics / Re: Memory leak with Sf::RenderTexture, help! [Solved]
« on: January 13, 2015, 11:03:49 am »
Thankyou for all your help guys.
I think i have to use RenderTextures, i'm using them on a grid, so a single map could have over 40 or so, i just use them so i can draw infinite blood and other things to the surface of the map without it disappearing.
The RenderTextures only get created at the first time something tries to get drawn to its grid cell.
Because of this memory leak, i've just made it so they never get destroyed, but rather, when the game loads a new map, it just clears the ones that are being used so that it doesn't have to create it again.
Overall, an entire map would not use more than 200mb of ram, so it wont make the game use too much RAM (Still not a very good way of doing it but it's to the best of my knowledge)

18
Graphics / Re: Memory leak with Sf::RenderTexture, help!
« on: January 13, 2015, 04:20:50 am »
Thankyou Jesper, i will look into using those tools, and upgrading to c++14 if i haven't already got it.
You can create your own scope without the need of a statement beforehand, so basically just a random set of curly braces yeah? never actually tried it before.

I just realized that calling delete in my code above actually uses more RAM than if i didn't call it....

I'd like to allocate this on the stack, but unfortunately it is non-copyable so it does not work well with this vector.

I suppose this question is sort of answered, but for the hell of it, why would the render texture not get deleted when calling delete on it?

19
Graphics / Re: Memory leak with Sf::RenderTexture, help!
« on: January 12, 2015, 03:19:20 pm »
Watching with task manager, and I'm testing this exact code that i posted here (After i just edited a few mistakes a few seconds ago) and it's raising my RAM usage upto 1gb (From 100mb~) in 1 minute.
Thanks i'll read the article!

20
Graphics / Memory leak with Sf::RenderTexture, help! [Solved]
« on: January 12, 2015, 03:04:36 pm »
I'm relatively new to trying to preserve memory by eliminating memory leaks.
Anyways, i was watching the memory of my program and i realized that the memory used by my RenderTextures was not getting released or cleared, so every time the map changed, more and more memory was being used up.
I've recreated my situation in this while loop statement below, as it would be too hard to write out my entire code, however using this code produces the same memory leak.

       
std::vector <sf::RenderTexture*> overlaySurfaces;
int mapWidth=2000;
int gridOverlaySquared=256;
int mapHeight=2000;
while(true){
    int Xmax_=ceil((double)mapWidth/(double)gridOverlaySquared);
    int Ymax_=ceil((double)mapHeight/(double)gridOverlaySquared);
    overlaySurfaces=vector<sf::RenderTexture*> (Xmax_*Ymax_);
    for(int i=0; i<overlaySurfaces.size(); i++)
    {
    overlaySurfaces[i]=new sf::RenderTexture;
    overlaySurfaces[i]->create(gridOverlaySquared,gridOverlaySquared);
    }
    for(int i=0; i<overlaySurfaces.size(); i++)
        delete overlaySurfaces[i];
    overlaySurfaces.clear();
    }

As i said, i'm pretty new to this, so how am i meant to properly delete the RenderTexture when they are in a pointer vector.

This code quickly uses a lot of RAM.

P.S. Now obviously this code is completely inefficient, trust me, my game is not this bad haha, even with the memory leak it would not use much ram probably. But i want to learn how to fix it, or if i can't fix it, then i can easily work around it.

21
General / Re: Problem starting SFML 2.0 with CodeBlocks
« on: January 22, 2013, 01:26:51 pm »
i downloaded 'MinGW TDM GCC 4.7.1 32bit'
But it still crashed o.o
[EDIT]

Nethermind, i forgot to rebuild... :3 it works thankyou :)

22
General / Re: Problem starting SFML 2.0 with CodeBlocks
« on: January 22, 2013, 01:16:52 pm »
'GCC 4.6 & 4.7 Series'

Yeah ok, i need the nightly builds :)

23
General / Re: Problem starting SFML 2.0 with CodeBlocks
« on: January 22, 2013, 01:09:34 pm »
Not sure, i just downloaded the latest version of codeblocks today on their website, i guess i got a too new verson then? :)

Thanks for the help, can you link me to your nightly builds please :D

24
General / Re: Problem starting SFML 2.0 with CodeBlocks
« on: January 22, 2013, 12:53:34 pm »
Thankyou for the help, unfortunatly, i still get the same error.
It compiles properly, but as soon as the program starts, it has an error. If i remove all the SFML coding from main.cpp and make a program that doesn't use SFML, it doesn't crash.

25
General / Re: Problem starting SFML 2.0 with CodeBlocks
« on: January 22, 2013, 12:14:13 pm »
where can you find the project/targets options? :P

26
General / Problem starting SFML 2.0 with CodeBlocks
« on: January 22, 2013, 09:36:28 am »
When i try to run a program using the sample code in the setup tutorial, the program starts then straight away has an error.
I am using codeblocks with SFML 2.0 made for codeblocks.
The error is the "name.exe has stopped working"
I'm using SFML_STATIC, and i linked the libraries like this in release mode:
sfml-graphics-s
sfml-window-s
sfml-system-s

I copied all the DLLs to the folder.
Here is my main.cpp:

Quote
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}


27
General / Re: Help installing SFML 2.0 in codeblocks
« on: January 22, 2013, 09:25:14 am »
Solved... I think I was using the SMFL 2.0 build for Visual Studio 2010.. :)

28
General / Help installing SFML 2.0 in codeblocks
« on: January 22, 2013, 09:24:05 am »
I've tried installing SFML 2.0 in codeblocks using the tutorial. (I can get it to work in microsoft visual studios 2010)

Heres my error log:
Quote
-------------- Build: Release in smfltest3 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -DSFML_DYNAMIC  -O2     -ID:\SFML\include  -c "G:\KE\C++ projects\Projects\codeblocks projects\smfltest3\main.cpp" -o obj\Release\main.o
mingw32-g++.exe -LD:\SFML\lib  -o bin\Release\smfltest3.exe obj\Release\main.o   -s  -lsfml-graphics -lsfml-window -lsfml-system
obj\Release\main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x1): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
obj\Release\main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x11): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
obj\Release\main.o:main.cpp:(.text.startup+0xe2): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
obj\Release\main.o:main.cpp:(.text.startup+0x11c): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE'
obj\Release\main.o:main.cpp:(.text.startup+0x14f): undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
obj\Release\main.o:main.cpp:(.text.startup+0x157): undefined reference to `_imp___ZN2sf5Color5GreenE'
obj\Release\main.o:main.cpp:(.text.startup+0x170): undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
obj\Release\main.o:main.cpp:(.text.startup+0x18a): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
obj\Release\main.o:main.cpp:(.text.startup+0x1b3): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
obj\Release\main.o:main.cpp:(.text.startup+0x1d7): undefined reference to `_imp___ZN2sf6Window5closeEv'
obj\Release\main.o:main.cpp:(.text.startup+0x207): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
obj\Release\main.o:main.cpp:(.text.startup+0x21f): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
obj\Release\main.o:main.cpp:(.text.startup+0x225): undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
obj\Release\main.o:main.cpp:(.text.startup+0x23e): undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
obj\Release\main.o:main.cpp:(.text.startup+0x24d): undefined reference to `_imp___ZN2sf6Window7displayEv'
obj\Release\main.o:main.cpp:(.text.startup+0x27d): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x2e8): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
17 errors, 0 warnings (0 minutes, 0 seconds)

Most of my settings can be seen in the error message above, tell me if I'm missing anything :)

Pages: 1 [2]
anything