Search code examples
c++listsegmentation-faultpush-back

Segfault on push_back


In piece of code below, I get a segfault on the line calling push_back():

CTrigger CTriggerManager::AddTrigger(const std::wstring& eventName)
{
    CTrigger trigger(eventName);
    m_Triggers.push_back(trigger);
    return trigger;
}

In case it is not clear from the code, I am trying to initialize an object trigger push it onto the back of a list m_Triggers. Can anyone please tell me why this might cause a segfault?

If needed, see the code in full context here.


Solution

  • Where is the TriggerManger being used and declared? I am betting that since it is crashing on the push_back, that the actual instance of CTriggerManager is null and the first access into a member variable (m_Triggers) is causing an access violation.

    I see one declared here, but never instantiated: world.cpp:

    CTriggerManager* pTriggerManager = NULL;