SFML community forums

Help => General => Topic started by: Raneman on January 25, 2016, 12:10:22 am

Title: Possible overflow when using window.setView()
Post by: Raneman on January 25, 2016, 12:10:22 am
Hi there.
Well, i need multiple active views for my game. If i understood Lession section correctley, i assume i should use "window.setView()@" on every frame.
But still the red text paragraph says,
When you call setView, the render-target makes a copy of the view, and doesn't store a pointer to the one that is passed. This means that whenever you update your view, you need to call setView again to apply the modifications.
Don't be afraid to copy views or create them on the fly, they aren't expensive objects (they just hold a few floats).
So now im really afraid of views, because how can i know how much time i have till the memory get fulled with those view objects and crush the game down with an error.
Please, tell me, is there an option to free memory of previous view?
Title: Re: Possible overflow when using window.setView()
Post by: eXpl0it3r on January 25, 2016, 07:11:04 am
SFML will hold one copy of a view at a time. If you pass a new view it will overwrite the old view.

If you don't know how to handle objects in C++, you might want to go back to a good C++ book and learn it. ;)
Title: Re: Possible overflow when using window.setView()
Post by: Raneman on January 26, 2016, 04:38:52 am
Well then what does this means?
the render-target makes a copy of the view, and doesn't store a pointer to the one that is passed
Dont understand. It looks like pointer to previous class/structure is missed but it is still in memory somewhere.
Quote
If you pass a new view it will overwrite the old view.
Well its more like, "Replace a pointer" than "Replace a variable".
Title: Re: Possible overflow when using window.setView()
Post by: GraphicsWhale on January 27, 2016, 01:26:57 am
The window does not hold a pointer to a view, it holds a view object. When you set the view, it's simply copying the data. Setting the view does not allocate or free any memory.
Title: Re: Possible overflow when using window.setView()
Post by: Raneman on January 27, 2016, 09:42:25 am
Oh thanks. Well, i think this means i can than call setView() on each draw cycle.
Title: Re: Possible overflow when using window.setView()
Post by: Hapax on January 27, 2016, 02:40:25 pm
i think this means i can than call setView() on each draw cycle.
You can. In fact, you can do it multiple times each cycle.
For example, once per view (e.g. background, scene, UI):
window.clear();
window.setView(viewBackground);
window.draw(background);
window.setView(viewScene);
window.draw(scene);
window.setView(viewUi);
window.draw(ui);
window.display();
is perfectly acceptable.