Runtime Error with ListBoxItem

ender81x

05-04-2006 20:06:57

I am creating a MultiColumnList, and upon the exit of my program i get:


Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at CeguiDotNet.CeguiBindingsPINVOKE.delete_ListboxTextItem(HandleRef jarg1)
at CeguiDotNet.ListboxTextItem.Dispose()
at CeguiDotNet.ListboxTextItem.Finalize()


It also occurs sometimes while my app is already running, but not at any particular point. It seems to me that possibly .NET's garbage collection is trying to clean up the ListboxTextItem resources after they have already been deleted... but I'm not sure exactly what the problem is... Is anyone else have any problems with using the MultiColumnList widget?

Also, in case it helps, everything works great as long as I don't add any items to the list (since I am then not ever creating a ListboxTextItem object)

So here is what I am doing:
-Create MultiColumnList
-Add a row
-Destroy MutliColumnList using WindowManager.Instance.destroyWindow()

And if i either exit the app, or continue using it for a bit, then I get that error...
Thanks for the help!

ender81x

05-04-2006 20:30:04

Also, I have found out that if I just create the ListboxTextItem objects, and then do not add them to the MultiColumnList using setItem() then I do not get any errors... so maybe it has something to do with the MultiColumnList destroying the resources, and then garbage collection trying to do it again... i'm looking through the source for CeguiNet to see if I can find anything...

rastaman

05-04-2006 20:46:45

Try saving a referece to each of the Itmes you create, you could addthem to an ArrayList. Then after distroing the LisBox distroy the Items.

ender81x

05-04-2006 20:58:27

Well, I think the problem is happening, I think, when the ListboxTextItem objects are being deleted from memory. The destruction of the Listbox is successful. I did try what you suggested, but it doesn't seem to make a difference.
My guess is that when the .NET instance of the object is being destroyed, it is trying to free the C++ instance, but it has already been freed by the destruction of the ListBox itself... I'm not sure if that makes any sense, but that's the first thing that comes to mind.

rastaman

05-04-2006 21:15:37

Yes that makes sense, and that is whats happening.

I was going by DemoCEGUI, thats what I did to to salve a segment falt with Mono on linux. Mono would distroy the Items as soon as it left CreateScene.

It seems that the MultiColumnList wants to distroy the ListItems but I don't think ComboBox does. Ill have to look at it more, we may have to have a function to just disconnect SWIGs managment of the items. see in my post Here the 4th code block down about RemoveOwnership. may need to do that for CeguiNet.

ender81x

05-04-2006 21:27:00

Well... that was an easy problem to fix.... ListboxItem provides a setAutoDelete(bool) function that controls wether or not the containing ListBox destroys it automatically.... once i set this to false for my ListBoxItems all is good... :oops:

rastaman

05-04-2006 22:05:36

lol :lol:

I'v added this to the wiki. A differece in .Net and c++ that people will just have to remember.

http://www.ogre3d.org/wiki/index.php/OgreDotNet_Differences

ender81x

05-04-2006 22:36:00

Great, I think that wiki page will be a great help.

A quick correction:

So when adding a ListboxTextItem to a MutliColumnList make sure you call MutliColumnList.setAutoDelete(false).


I believe that the setAutoDeleted function actually needs to be called for each ListboxItem that you are going to add to the list.

similar to:

ListboxTextItem li=new ListboxTextItem("Item Text");
li.setAutoDeleted(false);

rastaman

05-04-2006 23:24:35

:oops: should have looked that up. correct now

EagleEye

05-04-2006 23:27:14

There is an overloaded "new" that has that option at the end.

Public Sub New(ByVal text As String, ByVal item_id As System.UInt32, ByVal item_data As System.IntPtr, ByVal disabled As Boolean, ByVal auto_delete As Boolean)