Running an unmanged graphics engine in managed code

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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();

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 on other sites
Just a little question: why are you not using the .NET-wrapper of the IRRLICHT to do this job? Maybe there such problem are already solved.

Kimmi

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 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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002295
×