[Bug?] FileInfoListPtr causes Access violations


13-05-2012 19:23:21


I have some trouble with FileInfoListPtr and FileInfoList: FileInfoListPtr is a wrapper for a shared pointer to a FileInfoList instance.

Just copy and paste the code below and try it yourself. Create this class somewhere in your code and call GetList.
public class TestClass
public FileInfoListPtr GetList()
FileInfoList list = new FileInfoList();
return new FileInfoListPtr(list);
public StringVector GetList2()
StringVector list = new StringVector();
return new StringVectorPtr(list);

After closing the window, an Access violation exception will be thrown.
It does not mater, if you call:
(list is the instance of FileInfoListPtr).

Without .Dispose(), the error occurs in vector<FileInfo>::tidy() { ... this.OrphanAll(); ...}
With .Dispose(), the error occurs in std::string::_tidy() {...} (!!) [relation FileInfo <-> string?]
(debug build Mogre 1.7.4)

And with a release build, the error occurs in _free_base (in free.c).

Any idea, how to fix this? Or am I wrong and made a mistake?

Side note: FileInfoListPtr is needed because ogre sometimes wants FileInfoListPtr and not FileInfoList. I do not modified these classes, although its a compiled debug build targeting 1.7.4 .

Edit: I guess I found the problem (which is the same for StringVector and StringVectorPtr, too): The FileInfoList is "wrapped" by the shared ptr (FileInfoListPtr). If FileInfoListPtr is being destroyed, FileInfoList is destroyed (I do not know why), too. But only the native ptr of FileInfoList is destroyed, not the managed class, thus the destructor of FileInfoList will be called, too and this causes these strange errors. "Solution": call GC.supppressFinalizer(MyFileInfoList); (this is more an workaround, do not mess around with the GC!)