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

Author Topic: Class Destructed on Function Return?  (Read 1640 times)

0 Members and 1 Guest are viewing this topic.

NameUser

  • Newbie
  • *
  • Posts: 30
    • View Profile
Class Destructed on Function Return?
« on: August 22, 2012, 05:03:42 am »
Hi. I've been following a really helpful tutorial recently. It's a bit outdated though. I've already fixed a few issues due to that myself, but now I'm stumped. That is, if this is even the result of it's outdatedness.

I keep getting an access violation, which you can see for yourself by simply clicking the top of the screen twice. (sorry about not including the graphics, SFML is experiencing an odd glitch for me right now where it starts it's branch at C: as opposed to the folder the program is running from.)

Upon further investigation I narrowed it down to the recently added dynamic_cast in GameBall.cpp. Upon even further experimentation, it appears that whenever GameObjectManager runs one of it's functions, it's destructed on Return, thus causing access violations when it's referenced later. I can't for the life of me figure out why though.

If anyone could look at my solution and tell me what I'm missing, it would be greatly appreciated.

http://www.sendspace.com/file/gr753l

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Class Destructed on Function Return?
« Reply #1 on: August 22, 2012, 06:07:42 am »
I want to yell profanities at you :), you included worthless compiled debug exe but didn't include the images so I had to comment out all of your trolly asserts.  ;D
Anyway, the problem is your GetGameObjectManager(); returns a copy(define a copy c-tor to see for yourself) and you probably wanted a reference, these are two changes that seem to fix the problem:
Line 14 of Game.h should be this:
static GameObjectManager& GetGameObjectManager();
Line 107 of Game.cpp should be this:
GameObjectManager& Game::GetGameObjectManager()
Back to C++ gamedev with SFML in May 2023

NameUser

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Class Destructed on Function Return?
« Reply #2 on: August 22, 2012, 01:19:09 pm »
Dammit. Sorry, I completely forgot about the asserts.

You are absolutely correct however, so thank you very much.