Jump to content
  • Advertisement
Sign in to follow this  
Swarmer

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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!