IGUIElements and IReferenceCounted

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Ayre Morberos
Posts: 2
Joined: Sun Mar 03, 2024 9:03 pm

IGUIElements and IReferenceCounted

Post by Ayre Morberos »

Hi folks, I've got this snippet:

Code: Select all

	if( _image )
	{

		_image->remove();

	} else
	{

		dimension2du center = _guienvironment->getVideoDriver()->getScreenSize() / 2;

		_image= _guienvironment->addImage( recti( center.Width - 100, center.Height - 200, center.Width + 100, center.Height + 200 ), 0, -1, 0, false );

	}
_image is IGUIImage. The IGUIElement s do your the IReferenceCounted but internally so you don't have to grab and drop them. At least as far as I understood.

Using the snippet I have two problems:
1. With scenenodes and sorts I'd like to use {... if( sn->drop() ) sn = 0; ...}, nulling the member. How should I do this with gui elements?
2. When the image is create in the else block, the reference is 1. But before remove() it is 4 although nowhere inmy code _image is grabbed. So what going on here?

Thanks,
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IGUIElements and IReferenceCounted

Post by CuteAlien »

Hm, it could have focus and still be hovered. Hovered can have 2 grabs. So next mouse-event the hovered should be gone. Focus can stay until you clear focus or something else gets it (sadly remove doesn't handle this in Irrlicht, very old todo...).

So to be really safe with current Irrlich you should probably check before remove if the element or any of it's children have focus. Then setFocus(0). Then remove(). But hovered element even more tricky... no easy way to set that directly.

Although you still can do the drop() and set to 0 if you did grab() yourself (otherwise you shouldn't call it). Or just do remove() and set to 0. It should at least not show up anymore. And rest will be cleared up once the other parts which grab()'ed will give it up.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ayre Morberos
Posts: 2
Joined: Sun Mar 03, 2024 9:03 pm

Re: IGUIElements and IReferenceCounted

Post by Ayre Morberos »

That hovering and focusing could explain it, and would most likely terrible to debug. Especially if you not sure (yet) where to look. When they will be removed then it is fine.
Thanks.
Post Reply