Search code examples
c++visual-studiowxwidgets

wxGenericDirCtrl error "wxTheFileIconsTable was nullptr"


I started using wxWidgets and everything seemed to work fine until I wanted to use "wxGenericDirCtrl". When I create an object of wxGenericDirCtrl my program throws an exception stating that "wxTheFileIconsTable was nullptr" in Release mode and "this was nullptr" in Debug mode. I've tried using different versions of wxWidgets (3.0.4 - 3.1.3) but none of them worked.

Here's a screenshot of an error that I get


Solution

  • I was initializing frame in the application's constructor instead of doing it in OnInit function.

    My code looked like this:

    App::App()
        : m_Frame(new Frame) { }
    
    bool App::OnInit()
    {
        m_Frame->Show();
    
        return true;
    }
    

    and it should've looked like this:

    bool App::OnInit()
    {
        m_Frame = new Frame;
        m_Frame->Show();
    
        return true;
    }