Sign in to follow this  
Lord Caius

[.net] Problem initializing MDX

Recommended Posts

I have a feeling I'm not the only one who has had this problem... I have started coding a game engine in Visual C# w/ MDX (that I originally designed for straight C++, but I wanted to take advantage of .NET). My setup is as follows: (VS 2005, February 2007 DX SDK) -Solution ___-Project: Game Engine (DLL) ______-MyForm that extends Windows.Forms.Form _________-InitializeD3D() method for initializing DirectX Graphics (!!) ___-Project: Game (EXE) that has Game Engine as a reference ______-Program.cs that contains the Main() method _________-Main() instantiates MyForm _________-Main() calls InitializeD3D() method No build errors, but on running I get an error (!!) as follows: "DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang." What is it that I'm doing wrong? I've looked at every resource (samples, SDK docs) that I could find, but I'm not doing anything differently - with ONE exception. I've set up my engine as a DLL, not an EXE. Which makes the most sense if I'm going to reuse/distribute/update my engine. Any help at all is greatly appreciated! (Oh, and if there's something wrong with my overall design, don't hesitate to correct me - I'm doing this as much to learn as to create...)

Share this post


Link to post
Share on other sites
That is a known MDX problem. Here's how you fix it:
in Vs2005, go to the Debug Menu, thene Exception, then find "LoaderLock". You should find this "LoaderLock" exception under the "Managed Debugging Assistant" submenu. Un-throw it and it should complain no more. As for the reasons for why it is throwing that exception I don't recall right now, but maybe Google or someone else will be able to shed some more light!

Share this post


Link to post
Share on other sites
Quote:
Original post by AvengerDr
As for the reasons for why it is throwing that exception I don't recall right now, but maybe Google or someone else will be able to shed some more light!
The short version is that there was a mistake made in Managed C++ for the 1.x frameworks that puts code using MC++ at risk of deadlocking the application against itself. This was discovered too late, and VS 2005 uses that LoaderLock MDA to try and inform you what's going on.

To date, I have not seen any evidence that the LoaderLockException is a false positive. I also have not seen any evidence of applications deadlocking themselves, though such a nondeterministic deadlock is easily written off as the computer "being weird".

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
To date, I have not seen any evidence that the LoaderLockException is a false positive. I also have not seen any evidence of applications deadlocking themselves, though such a nondeterministic deadlock is easily written off as the computer "being weird".


Has this problem been fixed in SlimDX? Speakin of which, I saw that there's no equivalent for Vector2.Empty in SlimDX. Is there some sort of design guideline that advises against this? I don't know why but I've this habit of using it instead of new Vector2 for example :)

Share this post


Link to post
Share on other sites
Quote:
Original post by AvengerDr
Quote:
Original post by Promit
To date, I have not seen any evidence that the LoaderLockException is a false positive. I also have not seen any evidence of applications deadlocking themselves, though such a nondeterministic deadlock is easily written off as the computer "being weird".


Has this problem been fixed in SlimDX?
Yeah, it's gone. The bug was fixed for C++/CLI and framework 2.0.
Quote:
Speakin of which, I saw that there's no equivalent for Vector2.Empty in SlimDX. Is there some sort of design guideline that advises against this? I don't know why but I've this habit of using it instead of new Vector2 for example :)
I've been unable to find any advantage to Vector2.Empty over new Vector2(). As far as I can tell, they do the same exact thing. The only "downside" to new Vector2() is that it won't be obvious to people unfamiliar with the language that the vector is already (0, 0). Personally though, I don't believe in designing things for people that are unfamiliar with the language/platform in question.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit

I've been unable to find any advantage to Vector2.Empty over new Vector2(). As far as I can tell, they do the same exact thing. The only "downside" to new Vector2() is that it won't be obvious to people unfamiliar with the language that the vector is already (0, 0). Personally though, I don't believe in designing things for people that are unfamiliar with the language/platform in question.


It may be just sugar coating, but I found it quite useful. Having static fields available like Empty/Zero, Up (0,1,0) etc makes reading through the code a wee bit easier. Sure, you can see from the parameters what the vector represents, but using these fields you can tell this instantly without inspection.

And with intellisense it can shave a few seconds of your coding time [wink]

Share this post


Link to post
Share on other sites
Well I agree, using Vector2.Empty is also in some ways less prone to errors than using new Vector2(). Imagine a case where someone insists on using new Vector2(0,0,0) because of some arbitrary self-imposed rule. The moment he make a typo and writes new Vector2(0,0,1) and doesn't realize it... It could take a while to fix the resulting bugs. Whereas, by using Vector2.Empty it wouldn't happen. Maybe don't call it empty, call it zero, or something like that. But I guess that in the end it could be useful.

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