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

Author Topic: Possible overflow when using window.setView()  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

Raneman

  • Newbie
  • *
  • Posts: 5
    • View Profile
Possible overflow when using window.setView()
« 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?
« Last Edit: January 25, 2016, 12:59:52 am by Raneman »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10863
    • View Profile
    • development blog
    • Email
Re: Possible overflow when using window.setView()
« Reply #1 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raneman

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Possible overflow when using window.setView()
« Reply #2 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".
« Last Edit: January 26, 2016, 04:41:11 am by Raneman »

GraphicsWhale

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: Possible overflow when using window.setView()
« Reply #3 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.

Raneman

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Possible overflow when using window.setView()
« Reply #4 on: January 27, 2016, 09:42:25 am »
Oh thanks. Well, i think this means i can than call setView() on each draw cycle.

Hapax

  • Hero Member
  • *****
  • Posts: 3362
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Possible overflow when using window.setView()
« Reply #5 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*