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

Author Topic: Passing the RenderWindow's address around.  (Read 1798 times)

0 Members and 1 Guest are viewing this topic.

Howitzer21

  • Newbie
  • *
  • Posts: 16
    • View Profile
Passing the RenderWindow's address around.
« 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!

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Passing the RenderWindow's address around.
« Reply #1 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)
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

Howitzer21

  • Newbie
  • *
  • Posts: 16
    • View Profile
Passing the RenderWindow's address around.
« Reply #2 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Passing the RenderWindow's address around.
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Howitzer21

  • Newbie
  • *
  • Posts: 16
    • View Profile
Passing the RenderWindow's address around.
« Reply #4 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?

 

anything