[2.2] Exception after light baking + PCC probes update

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
rujialiu
Goblin
Posts: 215
Joined: Mon May 09, 2016 8:21 am
x 20

[2.2] Exception after light baking + PCC probes update

Post by rujialiu » Tue Jun 11, 2019 5:26 am

Hi!

I got this exception:

Code: Select all

11:09:07: OGRE EXCEPTION(1:InvalidStateException): Last frame called map( bAdvanceFrame = false ) but didn't call advanceFrame!!!. in BufferPacked::map at C:\ogremygui\OGRE\OgreMain\src\Vao\OgreBufferPacked.cpp (line 190)
Detail:

Code: Select all

if( //This is a different frame from the last time we called map
                mLastFrameMapped != currentFrame &&
                //map was called, but bAdvanceFrame was not.
                (int)(mLastFrameMapped - mLastFrameMappedAndAdvanced) > 0 )
            {
                OGRE_EXCEPT( Exception::ERR_INVALID_STATE,
                             "Last frame called map( bAdvanceFrame = false ) but "
                             "didn't call advanceFrame!!!.", "BufferPacked::map" );
            }
When the exception occurs, mLastFrameMapped=150, mLastFrameMappedAndAdvanced=149, currentFrame=153 and the next function in the call stack is:

Code: Select all

float* RESTRICT_ALIAS_RETURN HlmsBufferManager::mapNextTexBuffer( CommandBuffer *commandBuffer,
                                                                      size_t minimumSizeBytes )
    {
...

        mRealStartMappedTexBuffer   = reinterpret_cast<float*>(
                                            texBuffer->map( mTexLastOffset,
                                                            texBuffer->getNumElements() - mTexLastOffset, /////////// here
                                                            false ) );
This happens when I do some light bakings and THEN update PCC probes. The light baking loop is something like:

Code: Select all

 for (const auto& action : mLightmapBakingActions) {
	beforeLightBakingAction(action); // change visilibty mask, move camera etc

        sceneManager->updateSceneGraph();

        auto bakingWorkspace = action.worspace;
        bakingWorkspace->_beginUpdate(false);
        bakingWorkspace->_update();
        bakingWorkspace->_endUpdate(false);
        sceneManager->clearFrameData();

        afterLightBakingAction(idx); // restore changed things
    }
Back to the exception-rasing code. In the first bake, currentFrame=150 so mLastFrameMapped changed to 150 too, but mLastFrameMappedAndAdvanced is still 149.

In the second bake in the loop (I have 5 actions in the loop), although (int)(mLastFrameMapped - mLastFrameMappedAndAdvanced) > 0 is true (150>149), but mLastFrameMapped == currentFrame (both 150) so the exception was not raised.

However, after all the baking actions, when updating PCC probes:

Code: Select all

void ParallaxCorrectedCubemap::updateExpensiveCollectedDirtyProbes( uint16 iterationThreshold )
    {
        RenderSystem *renderSystem = mSceneManager->getDestinationRenderSystem();
        HlmsManager *hlmsManager = mRoot->getHlmsManager();

        const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask();
        mSceneManager->setVisibilityMask( 0xffffffff );

        for( size_t i=0; i<mNumCollectedProbes; ++i )
        {
            if( (mCollectedProbes[i]->mDirty || !mCollectedProbes[i]->mStatic) &&
                mCollectedProbes[i]->mNumIterations > iterationThreshold )
            {
                setFinalProbeTo( i );

                for( int j=0; j<mCollectedProbes[i]->mNumIterations; ++j )
                {
                    renderSystem->_beginFrameOnce();
                    mCopyWorkspace->_beginUpdate( true );
                        if( j == 0 )
                            mCollectedProbes[i]->_clearCubemap();
                        mCopyWorkspace->_update();
                        mCollectedProbes[i]->_updateRender(); //////////////////////////////////////here
                    mCopyWorkspace->_endUpdate( true );
the _updateRender() eventually enter HlmsBufferManager::mapNextTexBuffer() again, and then BufferPacked::map() and raised an exception because (int)(mLastFrameMapped - mLastFrameMappedAndAdvanced) > 0 is still true (again 150>149), BUT now currentFrame is 153 so mLastFrameMapped != currentFrame is also true.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4044
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 218
Contact:

Re: [2.2] Exception after light baking + PCC probes update

Post by dark_sylinc » Wed Jun 12, 2019 7:26 am

Looks like HlmsBufferManager::postCommandBufferExecution didn't get called, or HlmsBufferManager::frameEnded got called too early.
Alternatively, it may be possible to fix this issue by calling VaoManager::_update in between.
0 x

Post Reply