c++ogre3d

unhandled exception widget with sdkTrays in Ogre


I have some serious issues with sdkTrays in Ogre.

I have my OgreKinectGame that inherits from BaseApplication. BaseApplication is creating logo etc. using sdkTrayManager. I thought this mTrayMgr was inherited and can be used in my application as well.

I am trying to setup widgets for a HUD, but I'm getting unhandled exception errors.

My setupWidgets() function looks like this.

void OgreKinectGame::setupWidgets()

{

if(!mTrayMgr)
    mTrayMgr = new SdkTrayManager("InterfaceName", mWindow, mMouse);

    //mTrayMgr->destroyAllWidgets(); this caused exceptions as well
    // create check boxes to toggle the visibility of our particle systems
    const int WIDTH_UI = 160;
    // main menu
    mTrayMgr->createLabel(TL_CENTER, "mMainMenuLabel", "Main Menu", WIDTH_UI);
    mTrayMgr->createButton(TL_CENTER, "mOptionButton", "Option");
    mTrayMgr->createButton(TL_CENTER, "mCreditButton", "About");
    mTrayMgr->createButton(TL_CENTER, "mQuitButton", "Quit");

    mTrayMgr->showAll();

} Unhandled exception


Solution

  • First, where did you initialize your setupWidgets()? , on BaseApplication class, they have setup(), you can create a virtual of this setup() to your main class and then initialize your setupWiget() there, e.g.,

    bool OgreKinectGame::setup(void)
    {
       if (!BaseApplication::setup()) {
        return false;
       }
       // Load fonts for tray captions
       FontManager::getSingleton().getByName("SdkTrays/Caption")->load();
       setupWidgets();//initialize here for your setupWidget()
    } 
    

    second, I think your setupWidget() should be like this,

    void OgreKinectGame::setupWidgets()
    {
        const int WIDTH_UI = 160;
        // main menu
        mTrayMgr->createLabel(TL_CENTER, "mMainMenuLabel", "Main Menu", WIDTH_UI);
        mTrayMgr->createButton(TL_CENTER, "mOptionButton", "Option");
        mTrayMgr->createButton(TL_CENTER, "mCreditButton", "About");
        mTrayMgr->createButton(TL_CENTER, "mQuitButton", "Quit");
    }
    

    Can you try this solution and back again if still get crash?