Segmentation fault while setting classes local variables

Hi,
When I set a local variable to a value it causes a segmentation fault. This happens in the GameObject class in the setGame method.

I have no idea what is causing this problem so I have uploaded the entire project could you please take a look to see if you can find the problem. While your at it tell me what you think of the design. Am I on the right track? if not state why.

Here is the source: http://www.filedropper.com/snowrush

Thanks,
Dan
Rewrite your whole program if you need to. No one is going to dig through your code if you just dump it all at once. Although this is general c++, this breaks rules in the beginners rules topic http://www.cplusplus.com/forum/beginner/1/, can someone confirm that it applies to both subsections?
Its not much code that is written. It is just a template at the moment. I want to design the structure before I start using the 3d engine ect. I thought it would be a requirement for me to send all the code as I have never come across this problem in my life and have no idea what it could be. An object shouldn't have segmentation faults when setting its local variables.
Is this a runtime error? Try the debugger. That will locate where in your code the program crashes.
I have tried that already. Thats how I know it crashes when a set a local variable in the GameObject class in the setGame method.
Thats how I know it crashes when a set a local variable in the GameObject class in the setGame method.
A stack trace would be immensibly helpful here. What called said setGame()? Was the parameter a valid pointer? Was setGame() called on valid GameObject instance?

I tried to buid it and after fixing some errors, I got this in stack trace:
#0 ?? GameObject::setGame (this=0x0, game=0x5b4448) Basically you are calling setGame on null pointer.

The reason is this:
1
2
3
4
5
6
void SnowRushWorld::Init()
{
    //ctor
    auto obj = std::shared_ptr<Player>(); //This
    addObject(obj);
}
shared_ptr default constructor does not default constructs object it points to. It constructs null pointer.

Fix: auto obj = std::make_shared<Player>();
Last edited on
Oh damn what a simple mistake can't believe I missed that

Thanks for your help
Topic archived. No new replies allowed.