Archived

This topic is now archived and is closed to further replies.

Moe

Need help finding my problem...(DX8)

Recommended Posts

Hi all, I really don''t like having to ask for help finding a problem in my own code, but I just can''t seem to figure it out myself. I am trying to write a decent Direct 3D wrapper that can do all sorts of interesting things like anisotropic filtering and multisampling. The problem is that for some reason my CreateDevice() is failing, and I can''t find out why. I tried debugging it with the debug info cranked up to the max but all it says is something like:
quote:
Direct3D8: (ERROR) :The specified mode is unsupported. CreateDevice/Reset Fails Direct3D8: (ERROR) :Failed to initialize Framework Device. CreateDevice Failed.
I can''t seem to figure out what exactly is not working. You can find my latest source code at: http://www20.brinkster.com/tyrannica/help 1.zip The code is well commented and fairly organized. The specific code that is giving me problems is in d3d.cpp. There is one other thing that is bothering me as well. Every time my program doesn''t run properly, it tells you with a nice, informative message box. The problem is that after the message box is closed, it does an illegal operation. From the little debugging that I have done, it appears that it has something to do with CD3DFont, not my code. Any ideas on whats causing this either? Moe''s site

Share this post


Link to post
Share on other sites
Your ScreenWidth/ScreenHeight should be appropriate values for a supported video mode. When I use 1024, 768 the code works.

You get access violation after MsgBox because you don''t have default constructor for FONT, and if your program tries to quit before FONT::Init is called, FONT object contains garbage which you are trying to clean in the destructor (like deleting font which is 0xcccccccc).

Another error is that it appears that my GF3 doesn''t support 32-bit depth buffer with 16-bit backbuffer, which is what you are trying to do. Using 16-bit for both helped.

Even after that program said "Init error" and quit. Good luck finding more bugs!

Share this post


Link to post
Share on other sites
Thanks very much! I will try to catch all the bugs before they propagate!

Just one thing - can I get you to post the contents of prototype.log? Its just a text based file that tells me everything that is going on and where things fail. It can be found in the logs directory of the zip file.
Moe's site

[edited by - Moe on May 4, 2002 5:53:09 PM]

Share this post


Link to post
Share on other sites
Kick ass help by indirctX! Wish all d00d3s h3re where lik3 u!
Gl man
P.S. Moe check ur e-mail
~The fastest polygons are those you don''t draw...~

[edited by - PiXeLatiOn on May 4, 2002 6:40:44 PM]

Share this post


Link to post
Share on other sites
Here goes: (with D3D fixes I mentioned)

  
---------- Logfile Created ----------
ENG - Initialize() called.
ENG - Configuration file succesfully opened
ENG - Configuration file is of correct type
ENG - Windowed mode read: 0
ENG - Resolution set to 800x600
ENG - Color depth read in as: 16
ENG - Multisample level read in as 0
ENG - Background color set to 0 0 0
ENG - ShowFPS set to 1
ENG - FPS font color set to 128 255 255 255
ENG - Configuration file closed
D3D - D3DInitialize() called
D3D - Max Number of Simultaneous textures is 4
D3D - Maximum anisotropy taps is 8
D3D - Fullscreen mode selected
D3D - D3DFMT_X8R8G8B8 supported
D3D - D3DFMT_R5G6B5 supported
D3D - 16 bit z-buffer and backbuffer supported
D3D - 32 bit z-buffer and backbuffer supported
D3D - Using 32 bit backbuffer and z-buffer
D3D - Initialization succesful.
ENG - Direct3D initialization successful.
DI - InitDirectInput() called
DI - Direct Input interface successfully created
DI - Direct Input Keyboard device created
DI - Data format set for keyboard
DI - Failed to set cooperative level for keyboard
ENG - Direct Input initialization failed. Exiting program.

Apparently, my computer can''t handle BACKGROUND|NONEXCLUSIVE flags for DI coopmode, which causes a lot of programs I see on GameDev fail to init on my machine. Did you get this flag combination from some book? It seems pretty widespread. I see no reason to use BACKGROUND coop mode for games anyway. I personally use FORE|NONEXCLUSIVE for kb and FORE|EXCLUSIVE for mouse. After changin your coopmodes to my coopmodes I got blank screen with the fps counter that was showing... well, hard to say, but around 3000 fps.

May I also suggest that you start using PCH? You won''t believe how fast your project will compile with them.

Final log file (I didn''t change log entries, ie Z is really D16):

  
---------- Logfile Created ----------
ENG - Initialize() called.
ENG - Configuration file succesfully opened
ENG - Configuration file is of correct type
ENG - Windowed mode read: 0
ENG - Resolution set to 800x600
ENG - Color depth read in as: 16
ENG - Multisample level read in as 0
ENG - Background color set to 0 0 0
ENG - ShowFPS set to 1
ENG - FPS font color set to 128 255 255 255
ENG - Configuration file closed
D3D - D3DInitialize() called
D3D - Max Number of Simultaneous textures is 4
D3D - Maximum anisotropy taps is 8
D3D - Fullscreen mode selected
D3D - D3DFMT_X8R8G8B8 supported
D3D - D3DFMT_R5G6B5 supported
D3D - 16 bit z-buffer and backbuffer supported
D3D - 32 bit z-buffer and backbuffer supported
D3D - Using 32 bit backbuffer and z-buffer
D3D - Initialization succesful.
ENG - Direct3D initialization successful.
DI - InitDirectInput() called
DI - Direct Input interface successfully created
DI - Direct Input Keyboard device created
DI - Data format set for keyboard
DI - Cooperateive level set for keyboard
DI - Keyboard acquired
DI - Direct Input Mouse device created
DI - Mouse data format set
DI - Cooperative level set for mouse
DI - Mouse acquired
DI - Direct Input initialization succesful.
ENG - Direct Input initialization succesful.
ENG - Font initialized.
ENG - EngineInitialize() successfully completed.
---------- Program Successful ----------
DI - ShutdownDirectInput() called.
D3D Shutdown called.
ENG - Shutdown() called.


Thanks PiXeLatiOn. For some reason I like to debug code sometimes. Hate to debug my own though.

Share this post


Link to post
Share on other sites
Its really good to hear that someone got this working! I still have to make a few changes to get things working. The strange thing is that I can get it to run at 1024x768 but not at 800x600 or 640x480. I will have to play around and get things running...

Thanks!

EDIT - I did a little playing around and I fixed the illegal operation problem, but I still can't get CreateDevice() to work properly! IndirectX, can I get you to e-mail me d3d.cpp (rcjbvermilion@hotmail.com).

You said I should be using PCH (Pre-Compiled Headers, right?) I really haven't seen any information on how to do this. How would I go about doing this?

As for the BACKGROUND | NONEXCLUSIVE flags, I got that from furby100 (as far as I remember). He wrote a small tutorial on Direct Input, and thats where 90% of that code comes from. I just modified it to suit my purposes. I do understand it though. If I didn't, I probably wouldn't be using it. I don't like using code that I don't understand.



[edited by - Moe on May 4, 2002 10:45:58 PM]

Share this post


Link to post
Share on other sites
Sent it your way from my other email account.

Look at project settings-(for .cpp files)-c/c++-Precompiled headers. stdafx.cpp creates pch file, other .cpp files use it.

Share this post


Link to post
Share on other sites
Hmm, I still can''t get things to work the way they are supposed to! If I manually set the resolution in the program (hard code it in) it works, but if I read it in from the .cfg file, it doesn''t work unless the resolution is something like 1024x768. I just can''t figure out why this stupid thing doesn''t want to work! I set the config file to 800x600, I check to make sure it was set to 800x600 in my logfile. Then I set the backbuffer dimensions using the read in variables, and low and behold - it doesn''t work! It has to be something in there that isn''t passing the variables on correctly or something.

Moe''s site

Share this post


Link to post
Share on other sites
I will have to do a little more debugging to find out. The strange thing is that I read them in, then I write to my logfile what was read in to make sure it was read in properly. Just by looking at the logfile, I would think that everything is fine, but it obviously doesn''t seem to be!

Moe''s site

Share this post


Link to post
Share on other sites
quote:
Original post by IndirectX
Why do you use logfile if you have an excellent IDE with a debugger?

A log file is persistant, the output in the IDE isn''t. In the event of a nasty crash, your IDE output is gone, but your logfile is still there. Also, other people (who may not have the IDE) can run your programs and when bad things happen, can send you the log. Need more reasons?


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Ok, I dropped a breakpoint onto the first of these 2 lines:

  
d3dpp.BackBufferWidth = ScreenWidth;
d3dpp.BackBufferHeight = ScreenHeight;

I checked the value of ScreenWidth, and its not what its supposed to be! Its something like 768, when I set the logfile to 600! It sounds to me like its almost trying to take the current width of the monitor (I run in 1024x768), but I have no idea why it would try doing that. Any ideas here? I am really stuck!

Moe''s site

Share this post


Link to post
Share on other sites
G''day!

I just grabbed the source and took a quick peek. This line looks wrong: (from main.cpp)
//try reading in the resolution
fscanf(pFile, "resolution %d %d %d ", &width, &height);

You''re probably trashing some memory here.

The rest of it looked okay, but I can''t run it at work (NT4). I''ll try it when I get home.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
I removed the extra %d, but it still hasn''t corrected the problem. The reason it probably doesn''t run on NT is because it uses DirectX 8.

Moe''s site

Share this post


Link to post
Share on other sites
G''day!

I didn''t expect it to work on NT4, that was just my excuse for not checking it out in more depth until now.

I found the naughty bit:

//read in whether to show the fps or not
if(fscanf(pFile, "showfps %d ", &d3d.ShowFPS) != 1)
{
logfile.LogtoFile("ENG - Unable to load showFPS\n");
return ENGINE_BAD;
} else
logfile.outfile<<"ENG - ShowFPS set to "<


ShowFPS is a bool, and maps to a byte, yet you''re passing it as if it were an int. Your width and height are directly after ShowFPS so they were getting trashed. If you change ShowFPS into an int, it runs clean.

If you''re going to use the streams for your logging, you should put some flushes in there, otherwise you''ll lose info on a crash.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
BTW, to find the problem, I set a breakpoint just before the dimensions were read in by your engine. I dragged the height & width into the little variable box thingy (whatever it''s called) and then stepped through until they changed improperly.

It''s kind of tedious, but it can be a life-saver.

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
If you look at the rest of the logfile code, I do have flushes in it, but only for regular text. I suppose I should put a few flushes in there though. I originally didn''t think about using my logfile class in the way that I do now - I originally designed it just to output text.

Moe''s site

Share this post


Link to post
Share on other sites
I would like to thank you guys for helping me find my problem. I''m sure you''re glad to know that its all running fine now! Thanks!

Moe''s site

Share this post


Link to post
Share on other sites