Memory problems
I have some singleton class (please, don't speak about singleton usage).
class InputSystem : boost::serialization::singleton<InputSystem>
{
private:
boost::shared_ptr<sf::Window> mInputWindow;
public:
InputSystem()
{
mInputWindow = boost::shared_ptr<sf::Window>( new sf::Window(someARgs) );
开发者_JS百科someMethod();
}
void someMethod()
{
mInputWindow->...() // Calling some methods of sf::Window class
// Everything is fine here
}
const sf::Input &Handle() const
{
return mInputWindow.get()->GetInput();
}
};
void main()
{
InputSystem::get_mutable_instance().Handle(); // Here is all members of InputSystem have invalid addresses in memory (0x000)
}
What's wrong could be there?
Here is all members of InputSystem have invalid addresses in memory (
0x000
)
Either someMethod()
is zeroing your class data, or you have misdiagnosed the issue.
Change your main function to this:
InputSystem& inputSystem = InputSystem::get_mutable_instance();
inputSystem.Handle();
This puts the creation of the singleton and the first attempt to use it onto separate lines. Fire up your debugger and step through the code looking for the exact point that your singleton's data is corrupted.
精彩评论