• Advertisement
Sign in to follow this  

Segmentation Fault when using getter and setter functions...

This topic is 3026 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have a very strange problem. I have a pointer to a class like... GameEngine * gameEngine = new GameEngine; It all works fine. But whenever I try to do gameEngine -> getSomeValue(); or gameEngine -> setSomeValue(); It results in a segfault when it accesses the variable it needs for reading or writing. It doesn't happen if I comment out the line where it either does the actual setting or getting. Like if I make it return NULL or not set anything at all, no segfault. Also I can call the function from the class itself and there are no problems, which normally is pointless since the class has access to its private variables, but just as a test, it ended up working... I have absolutely no idea why this could cause a segfault or how to fix it. Also the gameEngine pointer is a global variable, which I don't know if it has anything to do with it...

Share this post


Link to post
Share on other sites
Advertisement
Ah thanks..

I debugged it with gdb and saw the pointer was NULL everywhere.

What I did is in main I created the game engine and the game engine's constructor would start all subsystems and the main loop but never return from the constructor. This is why the global pointer to the game engine never got set.

Now I create the instance and start everything from main and it works perfectly...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement