Sign in to follow this  
Swarmer

Running an unmanged graphics engine in managed code

Recommended Posts

I am running a directX graphics engine in a WinForm, specifically the Irrlicht engine, running in a picturebox. Everything is working fine, except that I occasionally get the following error:
An unhandled exception of type 'System.AccessViolationException' occurred in myProgram.exe

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This happens when I try to resize the window, which triggers an event, where I manually resize the engine. This call resets the engine (which is good), but after all of that I get that error. I think this is because it is managed code that shouldn't be (I think). Here is relevant code:
public ref class IrrlichtManager
{
//stuff
void Init();
}
This is my manager class that wraps up the Irrlicht stuff in a managed class (ref). This is how I use it:
irrManager = gcnew IrrManager();
irrThread = gcnew Thread(gcnew ThreadStart (irrManager, &IrrlichtManager::Init));
This is my thread. I guess I shouldn't make IrrlichtManager managed, right? But I don't know how to make a thread with an unmanaged class. ThreadStart requires its first parameter to be System::Object^, which can only be managed classes. However, it can be overloaded, although I can't figure it out: the sole parameter when overloaded is described as: ThreadStart(void (*)(void)). What is that? I tried messing around with reinterpret_cast to void* but I couldn't get it to compile. There is no documentation anywhere. Another thing I tried was to make IrrlichtManager unmanaged and make a managed wrapper class for it. This did not help (unsurprisingly). So my theory, as I said earlier, is that Irrlicht is doing it's own thing but is accidentally touching the managed heap (or maybe vice versa). I'm still new with managed C++ so I might be missing some concepts here. Do you know how I can successfully put this unmanged graphics engine into one of my winforms, without these resource access errors? Thanks.

Share this post


Link to post
Share on other sites
Well, I have considered it but I have decided not to for various reasons, such as me already having written a lot of native C++ for this project, and the reduced support for the wrapper.

Share this post


Link to post
Share on other sites
Well, I figured out the void thing, but it didn't help.

However, after doing a bit of research there's some native/managed mixing stuff out there, so I'll take a look at that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this