singleton class problem

This is a discussion on singleton class problem within the C++ Programming forums, part of the General Programming Boards category; i have a class for managing tilesets for games. it is a singleton class ( see here for info on ...

  1. #1
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465

    singleton class problem

    i have a class for managing tilesets for games. it is a singleton class ( see here for info on singletons ), and i am getting some weird problems

    here is my class decleration:

    Code:
    class TileSetManager
    {
    private:
    
    	static TileSetManager * m_pSingletonPointer;
    
    	int tilesetID;
    
    	// private constructors
    	TileSetManager(void){}
    	TileSetManager(TileSetManager&){}
    	TileSetManager&operator=(TileSetManager&){ return *this; }
    
    public:
    	
    	virtual ~TileSetManager(void);
    
    	static TileSetManager *GetInstance()
    	{
    		if ( ! m_pSingletonPointer )
    		{
    			m_pSingletonPointer = new TileSetManager;
    		}
    		return m_pSingletonPointer;
    	}
    };
    and my program crashes on this line:

    m_pSingletonPointer = new TileSetManager;

    i have about 20 singleton classes in this project and never had this problem. in my watch window of the debugger, it says "error symbol 'this' not found"... ive tried everything i can think of. i dont have a clue what the problem could be. any ideas?
    I came up with a cool phrase to put down here, but i forgot it...

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,671
    >> static TileSetManager *m_pSingletonPointer;
    Did you instantiate this guy?

    IE.
    >> TileSetManager * TileSetManager::m_pSingletonPointer;

    gg

  3. #3
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    yes i did
    Code:
    TileSetManager *TileSetManager::m_pSingletonPointer = NULL;
    I came up with a cool phrase to put down here, but i forgot it...

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,671
    Nothing wrong with what you've posted so far.
    So there's either a problem in the constructor (that wasn't posted) or you're program is already hosed when it gets to the "new" statement (meaning new has detected that the heap is out of whack and asserted).

    gg

    [EDIT]
    1000 posts!!! WOOO HOOO
    [/EDIT]

  5. #5
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    its not an assert... the error i get is:

    Unhandled exception at 0x005f2e40 in TSM.exe: 0xC0000005: Access violation reading location 0x00000000.

    its giving me that on the call to new.
    I came up with a cool phrase to put down here, but i forgot it...

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,671
    My best guess is heap is hosed - you got problems elsewhere.

    gg

  7. #7
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    i think youre right... i started commenting out a lot of other code and it seems to work fine...

    ill check elsewhere.. thanks.
    I came up with a cool phrase to put down here, but i forgot it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singleton template problem
    By cloudy in forum C++ Programming
    Replies: 14
    Last Post: 01-11-2009, 04:40 AM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  3. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 12:29 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 12:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21