ForwardPlusBase::getCachedGridFor returned wrong grid Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Shimayama
Halfling
Posts: 74
Joined: Sat Apr 25, 2009 2:20 pm
Location: Norway
x 1

ForwardPlusBase::getCachedGridFor returned wrong grid

Post by Shimayama »

I manage to sometimes trigger this assert in OgreForwardPlusBase.cpp:

assert( upToDate && "You must call ForwardPlusBase::collectLights first!" )

when switching between some multiple viewports setups and multiple compositor nodes on some of them.

After some debugging I think this might be the cause:

It seems that ForwardPlusBase::getCachedGridFor sometimes returns the wrong cached grid (in my case one that is one frame behind, and therefore upToDate == false because for the wrong cache the statement (itor->lastFrame == mVaoManager->getFrameCount()) is false ).

There can be two reasons why it returns the wrong one:
  • The cached aspectRatio is less than the cameras aspect ratio, because there is a missing Abs in this check:

Code: Select all

(itor->aspectRatio - camera->getAspectRatio()) < 1e-6f
  • If there are two viewports with very similar aspectRatio but not completely equal.
In my case I actually have viewports with very similar aspect ratio, but by judging of the image below it seems that it is because of the missing Abs check (cache 0 is selected, which is a frame behind, instead of cache 1 which should have been selected):

Image

Suggested fix:

Either add an abs() around the left part of the less than, or just skipping the threshold completely and do a pure equals comparison instead? Maybe the less-than-epsilon isn't needed in this case?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: ForwardPlusBase::getCachedGridFor returned wrong grid

Post by dark_sylinc »

Fixed! Thanks for the report.
Shimayama wrote: Thu Mar 08, 2018 6:56 pm Maybe the less-than-epsilon isn't needed in this case?
I wish that too. Unfortunately the compiler would have to guarantee us the floating point values come from the same place (RAM vs registers) and the rounding modes have been preserved.
Shimayama
Halfling
Posts: 74
Joined: Sat Apr 25, 2009 2:20 pm
Location: Norway
x 1

Re: ForwardPlusBase::getCachedGridFor returned wrong grid

Post by Shimayama »

Thanks! The fix worked well.
Post Reply