Weird Resource loading bug


15-08-2012 12:20:14

Hi guys,

I have a really strange problem. I compiled Mogre and Ogre in x64 and everything has been working fine. It works from Visual Studio in Debug and Release modes, but when I try to run the file normally, I get the following error:

OGRE EXCEPTION(5:ItemIdentityException): Cannot find an archive factory to deal with archive of type in ArchiveManager::load at ...

The error does not seem to be caused by any specific file - sometimes the log cuts out in one folder, sometimes in another.

To make things stranger, I managed to stop it happening all the time (it still happens sometimes) by altering code in a parallel task that should have nothing to do with Mogre.

By commenting the last two lines of the delegate below, it stops happening so regularly. This class does not reference Mogre itself, and although some of it's child classes do, they only use the vectors and quaternions.

_mainTask = new Task(() =>
_footProvider = new ProjectionKinectFootProvider();
_footProvider.FootFrameChanged += OnFootProviderFrameChanged;
while (!_readyToShutdown) Application.DoEvents();//Comment this line
FootProvider.Dispose();//Comment this line

I think I've read all the other threads relating to this problem, but they seem to deal with problems that are occurring in the debugger - this problem goes away whenever I try to look at it. It's a genuine Heisenbug

I'm completely clueless about what could be happening here - any suggestions are welcome, no matter how outlandish.


17-08-2012 12:34:18

Dude, what your doing here with threads looks totally bizarre. Running Application.DoEvents() on any thread other than the UI thread is completely dangerous. In fact, running DoEvents any time is kinda risky if you don't know exactly how it's going impact your code.

Here's quote from the Microsoft documentation.
Calling this method causes the current thread to be suspended while all waiting window messages are processed. If a message causes an event to be triggered, then other areas of your application code may execute. This can cause your application to exhibit unexpected behaviors that are difficult to debug. If you perform operations or computations that take a long time, it is often preferable to perform those operations on a new thread. For more information about asynchronous programming, see Asynchronous Programming Model (APM).

I'm not saying you shouldn't be using DoEvents, as long as you understand the impact because at first glance I would say it's very possible to be the cause of your problem. There are loads of blog posts that should explain it pretty well. Some people think it's totally evil, but a few explain it a bit more carefully. ... n-doevents ... 48560.aspx

Hmm... taking another look at your code I notice something else a bit strange. You are creating a new instance of the _footProvider and then disposing it using FootProvider. This implies that something else might have access to it on another thread and possibly trying to access it after it's disposed. It's also not very safe to dispose something without a using block or in a try finally just in case the code in between throws an exception.

Sorry for ripping into your code, these are easy mistakes to make if you haven't done a lot with threading before.


17-08-2012 15:04:22

Hi Zarfus,

Thanks for the tips. I've taught myself threading and am only just starting to figure out what I should be doing.

I've switched things around so that I do disposal elsewhere now. Somehow it's now an intermittent problem. Feel free to rip as much code as you want - if everyone pussyfoots around, you never learn anything :)

Thanks once again for your time, and the links above - now I actually understand what I'm doing.