Hello,
I've got a class GUI_TimerComponent (all irrelevant content stripped out)
class GUI_TimerComponent
{
public:
virtual ~GUI_TimerComponent();
protected:
GUI_TimerComponent();
private:
typedef std::list < GUI_TimerComponent* > InstanceList;
static InstanceList smv_InstanceList;
};
Any TimerComponent must add a pointer to itself to the static smv_InstanceList. This is done in the c'tor (naturally). When an instance is destroyed, it's the d'tor's responsibility to find that instance's entry in the list and erase the entry.
GUI_TimerComponent::InstanceList GUI_TimerComponent::smv_InstanceList;
GUI_TimerComponent::GUI_TimerComponent()
{
// Register this instance in our global instance list.
smv_InstanceList.push_back( this );
}
GUI_TimerComponent::~GUI_TimerComponent()
{
// Kill all timers.
TimerList::const_iterator itEnd = mv_ListOfTimers.end();
TimerList::iterator itCur;
for ( itCur = mv_ListOfTimers.begin(); itCur != itEnd; ++itCur )
{
KillTimer( 0, ( *itCur ).t_nTimerId );
( *itCur ).t_nTimerId = 0;
}
// Unregister from the global instance list.
// Find the instance to which the specified timer belongs.
InstanceList::const_iterator itInstanceEnd = smv_InstanceList.end();
InstanceList::iterator itInstanceCur;
for ( itInstanceCur = smv_InstanceList.begin(); itInstanceCur != itInstanceEnd; ++itInstanceCur )
{
if ( *itInstanceCur == this ) // <----- Here I get an access violation.
{
smv_InstanceList.erase( itInstanceCur );
}
}
}
For some reason the d'tor always dies with the following message:
Unhandled exception at 0x00446a3d in ASTS_TakeTwo.exe: 0xC0000005: Access violation reading location 0xfeeefef6.
Anyone see any obvious mistakes I'm making?