SFML community forums

Help => Window => Topic started by: Howitzer21 on February 15, 2012, 02:03:16 am

Title: Passing the RenderWindow's address around.
Post 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!
Title: Passing the RenderWindow's address around.
Post by: mateandmetal on February 15, 2012, 06:16:29 am
You don“t need a pointer to a RenderWindow. You can use a reference instead. Try something like this

Code: [Select]
void MyEntity::Draw (sf::RenderWindow &win)
Title: Passing the RenderWindow's address around.
Post by: Howitzer21 on February 15, 2012, 04:51:42 pm
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.
Title: Passing the RenderWindow's address around.
Post by: Nexus on February 15, 2012, 05:34:43 pm
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.
Title: Passing the RenderWindow's address around.
Post by: Howitzer21 on February 16, 2012, 01:20:12 am
I think it's having something to do with trying to pass it around in threads?  Does it have any trouble on that front?