SFML community forums
Help => Window => Topic started by: Howitzer21 on February 15, 2012, 02:03:16 am
-
Hello. Last week I was trying to use a pointer to my RenderWindow class inside my Engine to allow multiple parts of my program to work on it at once. Essentially one class would take care of graphics, another class would take care of events, and both would use the same RenderWindow object. However I could never get this to work right. It was like SFML was specifically designed to keep that from happening. Is there a way to do this? Thanks!
-
You don“t need a pointer to a RenderWindow. You can use a reference instead. Try something like this
void MyEntity::Draw (sf::RenderWindow &win)
-
Thanks. I'll have to wait for a while to be able to try that out. Will it work normally in that case? I'm having trouble right now remembering what went wrong, but there was some kind of severe runtime issue when using pointers, especially when doing so between threads.
-
Using a reference instead of a pointer will change nothing at runtime. It's not that references magically solve every problem.
I think you should rather try to find out why your error occurs. I suggest to read again some theory about pointer handling in detail. And as you mention threads, make sure there are no race conditions.
-
I think it's having something to do with trying to pass it around in threads? Does it have any trouble on that front?