Check datablock in use by another item

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
Lax
Orc
Posts: 476
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Check datablock in use by another item

Post by Lax »

Hi,

Is it possible somehow to check if a datablock is used by another item or entity?
I have the issue, that when an entity is deleted its datablock will be deleted. Yet there is another entity, that uses the same datablock when this being deleted, of course I get a crash, because the datablock pointer is crap.

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

zxz
Gremlin
Posts: 160
Joined: Sat Apr 16, 2016 9:25 pm
x 12

Re: Check datablock in use by another item

Post by zxz »

You can use the HlmsDatablock::getLinkedRenderables() function to find all uses of the datablock.

Lax
Orc
Posts: 476
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Check datablock in use by another item

Post by Lax »

Ok thanks!
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

zxz
Gremlin
Posts: 160
Joined: Sat Apr 16, 2016 9:25 pm
x 12

Re: Check datablock in use by another item

Post by zxz »

For reference, a function like this is useful:

Code: Select all

    void destroyDatablock(Ogre::HlmsDatablock* block)
    {
      auto hlms = block->getCreator();
  
      for (auto renderable : block->getLinkedRenderables())
        renderable->setDatablock(hlms->getDefaultDatablock());
  
      hlms->destroyDatablock(block->getName());
    }

Post Reply