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

Author Topic: problem when sf::RenderWindow is noncopyable  (Read 714 times)

0 Members and 1 Guest are viewing this topic.


  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
problem when sf::RenderWindow is noncopyable
« on: May 01, 2016, 09:55:25 pm »
i'm recently working on new game design that reply on boost::any. the idea is simple, storing all update and draw methods for each game entities in appropriate container and call those methods when it is needed. sound simple and it can be done. also i went further and implemented my own any class similar to boost::any. my attempting seems work fine when i tested against primitives type (int, float and so on) even i tested with user-types. all previous tests went smoothly but when time come to test it with sfml i got some issues. for example, sf::Drawable::draw takes two parameters and it can be call through (sfml magic) by instance of any sf::RenderTarget. this doesn't work on my design. i solved it by make game entity non-drawable.

the issue that i can't find any solution for it is when sf::RenderWindow is noncopyable so, whenever, i tried to cast it down from boost::any or from my own any class, i got always bad cast assertion says "sf::RenderWindow& is deleted object". the only cheep solution that i come up with it, is to turn off assert checking, since i don't have access to boost::any, i changed my own any class and comment assert. the test code run fine but i not quite conformable with it.

here my code:
(click to show/hide)

my Questions:
how to solve noncopyable issue?
is my design reliable in game dev?
« Last Edit: May 03, 2016, 12:18:49 am by MORTAL »


  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: problem when sf::RenderWindow is noncopyable
« Reply #1 on: May 02, 2016, 03:53:28 am »
i manage to solve it, the problem wasn't with sf::RenderWindow being noncopyable. it actually with with for-loop in call() function, for unknown reason it modifies the type of std::function signature when it calls cast() function. the solution was by using std::move to sf::Time instance (dt) instead of passing the object itself to call() function. so to run the code in main post safely, i need to change it to this:
really i can't explain it more, because i don't know why this happen in first place! :-\

to make the insert function more generic to allow more function parameters, the lambda would be handy here.
template <typename T, typename R, typename... Ts>
void insert(T&& t, R(T::*method)(Ts...))
                [source = std::forward<T>(t), method](Ts&&... ts) mutable
« Last Edit: May 03, 2016, 12:18:17 am by MORTAL »