Crash in the ControllerManager::updateAllControllers

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
altren
Gnome
Posts: 334
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 26

Crash in the ControllerManager::updateAllControllers

Post by altren »

So I was having segfault in the ControllerManager::updateAllControllers because nullptr object was used.
Debugging showed me that mControllers vector was modified inside range based loop and then ci object was 0. I tested and found that ControllerManager::createController was called within loop.
Modifying container we are iterating over must cause problems, but what I'm not sure if such modification is expected.
Changes below fixes the issue, but I want to double check that calling ControllerManager::createController from update() is possible. And I'm totally unfamiliar with all this controllers and what they can do.

Code: Select all

    void ControllerManager::updateAllControllers(void)
    {
        // Only update once per frame
        unsigned long thisFrameNumber = Root::getSingleton().getNextFrameNumber();
        if (thisFrameNumber != mLastFrameNumber)
        {
            // master version
            //for (auto *ci : mControllers)
            //{
            //    ci->update();
            //}
            for (size_t i = 0; i < mControllers.size(); ++i)
            {
            	mControllers[i]->update();
            }
            mLastFrameNumber = thisFrameNumber;
        }
    }
Image
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 479
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 165

Re: Crash in the ControllerManager::updateAllControllers

Post by sercero »

Hello @altren is this an issue with OGRE?

Perhaps it would be better if you opened a pull request with your changes so that @paroj can see what is the problem in context.
:D

User avatar
altren
Gnome
Posts: 334
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 26

Re: Crash in the ControllerManager::updateAllControllers

Post by altren »

Image