Is a bug of CeguiDotNet or OgreDotNet.Cegui?

LuRenJia

12-08-2006 17:58:25

Create a FrameWindow, append it into DefaultWindow(i.e. top window), and add some buttons into it, now move mouse cursor over it once and again. About 10~20 times, application will be crash, throw a "detected CallbackOnCollectedDelegate" exception.

I tried Listbox, StaticImage... if use them as a container, application always crash.

MDA(Managed Debugging Assistant) provided some infomation: A callback was made on a garbage collected delegate of typ "CeguiDotNet!CeguiDotNet.CeguiEventDelegate::Invoke".

Any ideas about it? Is it a bug of ceguiDotNet or ogreDotNet.Cegui? :shock:

timoch

12-08-2006 19:32:33

Do you setup event handlers for the different widgets ?
If you do, you need to keep a reference to the object targetted by the event handlers. (ie the on you do myobject.KeyUp += new EventHandler() ...=

Otherwise the GC will collect the object and eventually collect the delegate obects.

My guess would be a bug in your code but I'm no expert so don't take it personnaly :-)

TiMoch

timoch

12-08-2006 19:34:10

Do you setup event handlers for the different widgets ?
If you do, you need to keep a reference to the object targetted by the event handlers. (ie the on you do myobject.KeyUp += new EventHandler() ...=

Otherwise the GC will collect the object and eventually collect the delegate obects.

My guess would be a bug in your code but I'm no expert so don't take it personnaly :-)

TiMoch

LuRenJia

12-08-2006 19:49:22

thank you very much, timoch!

I setup event handlers as following:
button.Clicked += new WindowEventHandler(button_Click);

Yes, I want to setup a event handler to serveral widgets(some buttons cause a same event). But I got the error when one widgets added.

Sorry for my poor English, I hope you can know what I say. :oops:

timoch

13-08-2006 09:42:38

I do the following to simplify things :

class MyWindow {
...
private Window mWindow = null; // the frame window
private Editbox mEditbox = null; // the editbox inside mWindow
...

...
void SetupWindow() {
mWindow = WM.CreateWindow("TaharezLook/FrameWindow", Name);
mEditbox = WM.CreateEditbox("TaharezLook/Editbox", "mEditbox");
...
mEditbox.KeyUp += new KeyEventDelegate(mEditbox_KeyUp);
}
...
}


I have a UIManager class that always keeps a reference to the instance of MyWindow which in turn keep a reference to CEGUI wrapper objects. That way they get collected only when I release the reference to MyWindow.

TiMoch

LuRenJia

16-08-2006 11:08:49

thanks.

yes, that is what I need to do. P/Invoke is weird and terrible!