I have the Beginning 3D Game Programming book by Tom Miller
In chapter 4 page 62, he says to put code in the OnCreateDevice method in listing 4.2
adding this code causes the program to crash, with the error being Failed to create Direct3D device
public void OnCreateDevice(object sender, DeviceEventArgs e) {
SurfaceDescription desc = e.BackBufferDescription;
ExtendedMaterial[] mtrls;
levelMesh = Mesh.FromFile(MediaPath + "level.x", MeshFlags.Managed, e.Device, out mtrls);
if ((mtrls != null) && (mtrls.Length > 0)) {
levelTextures = new Texture[mtrls.Length];
for (int i = 0; i < mtrls.Length; i++) {
levelTextures
}
}
}
The error that it causes seems to be tied to dxmut.cs, because the exception is caught there, around line 2722
try
{
// If the settings dialog exists call its OnCreateDevice() and OnResetDevice()
if (State.Settings != null)
{
State.Settings.OnCreateDevice(device);
State.Settings.OnResetDevice();
}
// Call the dialog resource manager create device method
DialogResourceManager.GetGlobalInstance().OnCreateDevice(device);
// Call the resource cache created function
ResourceCache.GetGlobalInstance().OnCreateDevice(device);
// Call the applications device created callback if it's set
State.IsInsideDeviceCallback = true;
if (DeviceCreated != null)
{
DeviceCreated(this, new DeviceEventArgs(device, State.BackBufferSurfaceDesc));
}
State.IsInsideDeviceCallback = false;
State.AreDeviceObjectsCreated = true;
}
catch (MediaNotFoundException e)
{
DisplayErrorMessage(e);
success = false;
throw;
}
catch (Exception e)
{
DisplayErrorMessage(new CreatingDeviceException(e));
success = false;
throw;
}
Please help me! I'm having the worst time with my independent study this semester. if it wasn't implied by the code, this is using c# and the october 2004 release of the directx sdk

need help with code from a book
Beric Holt
I see the CreatingDeviceException wraps the actual exception thrown. If you change put a breakpoint in this line :
DisplayErrorMessage(new CreatingDeviceException(e));
and then examine e, what is the error actuall being thrown
Dave_W
Does the book have any full example projects you can run I can't help but feel that if you've copied this code right, some other previous step must be missing. Assuming that there hasn't been a change to DX since the book came out. You should also check if there are errata on any website.
I see it came with a CD, is there a full project on there you can try to build and run that uses this code
Khaja Imtiyaz
I had this problem, this forum solved it, indirectly. My problem was in the App.config file, where i missed off the trailing backslash in the media path. Took me hours to find this forum... Anyway, If anyone else wonders, device from the book should be e.Device (or put in a using block suggested on other forums) and if it compiles the exception is probably a missing file. Now i can see my program!! (well Tom's program) =)
MMatt
TheLe
i hope you're not pissed that i posted in both places.
ok, so here's the deal with his code. he's trying to show us how to render a mesh with directx from a file. if you look at his regular code (like the stuff hosted at zbuffer, which i have downloaded just so you know), he implements this differently than he does in the example, because in the full code he has other classes created already for rendering screens and menus and such. the actual code is executed elsewhere in the program.
so that you can see it, i uploaded it to my webspace for download
[removed link to copyright code]
if you'd be so kind, download it and see for yourself what's happening. thanks for your time guys
jodz
System.Object {Microsoft.DirectX.Direct3D.Direct3DXException} System.Object
_className null string
_COMPlusExceptionCode 0xe0434f4d int
_exceptionMethod <undefined value> System.Reflection.MethodBase
_exceptionMethodString null string
_helpURL null string
_HResult 0x88760389 int
_innerException { } System.Exception
_message "Error in the application." string
_remoteStackIndex 0x0 int
_remoteStackTraceString null string
_source null string
+ _stackTrace {System.Array} System.Object
_stackTraceString null string
_xcode 0xe0434f4d int
_xptrs 0x0 int
HelpLink null string
HResult 0x88760389 int
InnerException { } System.Exception
Message "Error in the application." string
Source "Microsoft.DirectX.Direct3DX" string
StackTrace " at Microsoft.DirectX.Direct3D.Mesh.FromFile(String filename, MeshFlags options, Device device, GraphicsStream& adjacency, ExtendedMaterial[]& materials, EffectInstance[]& effects)\r\n at Microsoft.DirectX.Direct3D.Mesh.FromFile(String filename, MeshFlags options, Device device, ExtendedMaterial[]& materials)\r\n at GameEngine.CreateGraphic(Object sender, DeviceEventArgs e) in c:\\test\\chap3\\gameengine.cs:line 89\r\n at GameEngine.OnCreateDevice(Object sender, DeviceEventArgs e) in c:\\test\\chap3\\gameengine.cs:line 83\r\n at Microsoft.Samples.DirectX.UtilityToolkit.Framework.Initialize3DEnvironment() in c:\\test\\chap3\\framework\\dxmut.cs:line 2722" string
+ TargetSite {System.Reflection.RuntimeMethodInfo} System.Reflection.MethodBase
let me know if you figure anything out from this, thanks for replying
Duddy
i'll try those suggestions zman. i'll have to get to them after work today, and i'll reply if its resolved or not. thanks for the help
mcory1
The 1st thing to do is to go into Debug/Exceptions and change 'When the exception is thrown' to 'break into the debugger'. The framework from the book (and the one in the SDK) have a lot of try catch statements in them so you *never* see the actual line the error happened on.
So once you have done that and you run the code you will see that its trying to load the media file. From what I can make out you have hardcoded the location of the media files in app.config to be c:\media\blockers. My guess is that its not finding the media files there because that's not the default place the CD copies them to I copied the media files from the CD into c:\media\blockers and the code works. Well I get a black screen but no exception.
You should also be very careful posting copyright files without permission. I have no idea if Tom is OK with the code and media being posted. My updates on The ZBuffer not only have permission, but I only post the changed files and no media. I've edited your posts to remove the links. You should probably remove the files.
wakawaka54
I hope this helps.
j_reins
soc_p
anyway, the code link is wrong, here it is:
[link removed - copyright code]