[2.1] RaySceneQuery assert

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


Post Reply
Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

[2.1] RaySceneQuery assert

Post by Frankincense »

Hi all,

I am getting an assert in debug mode when attempting to use SceneQueries in 2.1:

Code: Select all

#if OGRE_DEBUG_MODE
                //Queries must be performed after all bounds have been updated
                //(i.e. SceneManager::updateSceneGraph does this for you), and don't
                //move the objects between that call and this query.
                //Ignore out of date Aabbs from objects that have been
                //explicitly disabled or fail the query mask.
                assert((!(objData.mVisibilityFlags[objData.mIndex] & VisibilityFlags::LAYER_VISIBILITY) ||
                        !(objData.mQueryFlags[objData.mIndex] & mQueryMask) ||
                        !objData.mOwner[j]->isCachedAabbOutOfDate()) &&
                        "Perform the queries after MovableObject::updateAllBounds has been called!");
#endif
I believe the problem is 'isCachedAabbOutOfDate' as I have had to change a couple of instances of 'getWorldAabb()' to 'getWorldAabbUpdated()' due to this assert:

Code: Select all

    Aabb MovableObject::getWorldAabb() const
    {
#if OGRE_DEBUG_MODE
        assert( !mCachedAabbOutOfDate );
#endif
        return mObjectData.mWorldAabb->getAsAabb( mObjectData.mIndex );
    }
Am I executing queries at the wrong time or something?


Here is the query:

Code: Select all

      Ogre::Ray mouse_ray = Camera.getCameraToViewportRay ( mouse_pos.x / static_cast <float> ( Window.getWidth () ), mouse_pos.y / static_cast <float> ( Window.getHeight () ) ) ;
      RaySceneQuery->setRay ( mouse_ray ) ;
      RaySceneQuery->setSortByDistance ( true ) ;
      RaySceneQuery->setQueryMask ( BUILDING_MASK | HUMAN_MASK | VEHICLE_MASK ) ;

      Ogre::RaySceneQueryResult           &result = RaySceneQuery->execute () ; <-- assert
Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

Re: [2.1] RaySceneQuery assert

Post by Frankincense »

Maybe its because I use:

Code: Select all

OgreSceneManager = Root->createSceneManager ( Ogre::ST_GENERIC, numThreads, Ogre::InstancingThreadedCullingMethod::INSTANCING_CULLING_THREADED ) ;
Reading some more about 'INSTANCING_CULLING_THREADED' - should it be used even when using the HLMS automatic instancing? The manual references the 'InstanceBatchHW' instancing techniques.
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: [2.1] RaySceneQuery assert

Post by dark_sylinc »

Hi!

Sorry for the long overdue reply.

You can call sceneManager->updateAllTransforms() and sceneManager->updateAllBounds to avoid this assert (or the more expensive updateSceneGraph()). It is a relatively expensive call (proportional to the number of scene nodes, Entities and Items) so avoid calling it more than needed.

Ogre already calls updateSceneGraph once per frame, if you put your ray queries in a listener FrameListener::frameRenderingQueued or another listener that gets executed afterwards (e.g. any compositor listener), you can perform your ray queries for 'free'.
If you do this, you can't modify the positions/orientation/scales though. If it's very few nodes you touch, you can call node->_getFullTransformUpdated() and MovableObject::getWorldAabbUpdated on the affected objects to keep them up to date thus rendering is performed correctly (and asserts don't trigger later on). If it's too many nodes you modify, then you should call updateSceneGraph again, which breaks the point of getting into the trouble of doing ray queries in a listener.

Regarding the performance impact, since you come from Ogre 1.10, it shall be noticed that the performance characteristics of Ogre 1.x would be that of calling updateAllTransforms + updateAllBounds twice (once before your queries, another by Ogre before rendering), since Ogre 1.10 would iterate through all objects (once for the ray query, another for rendering) while evaluating each object's transforms dirtiness with each access.
Reading some more about 'INSTANCING_CULLING_THREADED' - should it be used even when using the HLMS automatic instancing? The manual references the 'InstanceBatchHW' instancing techniques.
This is a legacy setting for Ogre 1.x instancing stuff. Both legacy and new 2.1 Hlms code is affected regardless.

For more info on this error see the Manual's Obtaining derived transforms
and Ogre asserts mCachedAabbOutOfDate or mCachedTransformOutOfDate while in debug mode

Cheers
Frankincense
Kobold
Posts: 33
Joined: Mon May 05, 2014 5:36 pm
x 3

Re: [2.1] RaySceneQuery assert

Post by Frankincense »

dark_sylinc wrote: Mon Oct 26, 2020 11:35 pm Hi!

Sorry for the long overdue reply.
Not a problem, my silly questions can always wait :)

Thanks for the info, I think I have it sorted now after making sure that the scene queries are executed in the correct frame callbacks - I swear, every time I look in the manual for a solution and can't see it, you can always find a section that describes my problem exactly :oops:
Post Reply