Strange SDL Display Problem

Started by
2 comments, last by kabbotta 9 years, 4 months ago

SOLUTION: The Camera class was not initializing its position variables, x_ and y_, so when the Manager class was instantiated it caused garbage from the stack to be pushed into those variables and offset the camera by a wild amount.

I'm in the process of setting up a basic framework in SDL and I've encountered a very strange problem. I'm building and displaying a tile map made up of chunks, and everything was displaying just fine. Then I added a GameManager class, and all of the sudden nothing displays on the screen anymore. First, I started pulling things out of the class to see when the display came back, but it never did. I got down to just a bare class with a single empty constructor and no dependencies being included. The display still didn't come back. The input still works fine, and the render methods are all still being called, but nothing shows up on the screen anymore. I got frustrated enough, that I actually just deleted the GameManager class and recreated a blank class from scratch to see if it caused the same problem and it did. The second I instantiate an object of the class, I suddenly lose the display. The weirdest part is that it still occurs even if the instantiation is put off until after the whole game loop runs.

Here is the full project for reference: https://github.com/kabbotta/last-ditch-cpp

In my main.cpp:


Game game;
 
game.init();
 
while (game.is_running())
{
    game.update();
}
 
game.cleanup();
 
// Problem class
Manager mgr;

As you can see, I've moved the Manager instantiation after the entire game loop runs, quits, and cleans up. But it still causes the display to disappear. This is all that is left in Manager:


#ifndef MANAGER_H
#define MANAGER_H
 
class Manager
{
public:
    Manager() {}
};
 
 
#endif /* MANAGER_H */
Advertisement

It appears your Manager class instance mgr is in global scope. If so, it's created before game.init() is executed.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#ifndef MANAGER_H
#define MANAGER_H

class Manager
{
public:
Manager() {}
};

I don't see an #endif. Verify that it's there.

Hello to all my stalkers.

Sorry, I left out the #endif when copying. It is there. That code should end with:


#endif /* MANAGER_H */

And it is true that I have the Manager in global scope in main.cpp, but that was just another move I did as part of debugging to see if I could get anything to work. The original problem occurred when Manager was a member of the Game class, and it was explicilty initialized in the initializer list. I've even stuck a std::cout into the constructor so I could see when it was being instantiated. The way I have it right now the message from the constructor wasn't displayed until after I quit the main game loop and everything was cleaned up.

Here is the full project for reference: https://github.com/kabbotta/last-ditch-cpp

This topic is closed to new replies.

Advertisement