Jump to content
  • Advertisement
Sign in to follow this  
George88

Crash on fullscreen, using FAILED()

This topic is 2566 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

NOTE: this guy seems to have had the same problem I am having but never said exactly how he resolved the issue.

Hi all,

A few months back I came looking for help with some crashing I was experiencing when using full screen. I never found the solution or pushed for an answer because I began a new tutorial and started the code from scratch, and the crash just didn't happen despite the code being identical. This is what has happened so far:

As the program ran it would enter fullscreen mode where it would immediately crash and give me a box on the screen saying "Program has stopped working... Windows is searching for a solution". I was able to stop that from happening by using the FAILED() macro, but this only got rid of the crash, my program still won't work in full screen. All it will do now is load up, will resize the buffer to meet my given dimensions but will not enter full screen and my program will show up as a grey box, the same dimensions as I gave it, covering the screen. It might be worth noting I have used the Clear() function to make my buffer a purple colour, so I know something is going wrong. See a screenshot: http://img269.images...screenerror.png

Anyway, my problem lies with the CreateDevice function. The FAILED() error catcher is only being used once in my code and is giving me the error every time the program is run in debug mode. The code in question is:

void init_d3d(WINDOW_PROPERTIES* wp)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);

ZeroMemory(&d3dpp, sizeof(d3dpp));

d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames.
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // 32bit backbuffer format.
d3dpp.Windowed = wp->windowed;
d3dpp.BackBufferWidth = wp->width;
d3dpp.BackBufferHeight = wp->height;

if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
wp->hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev)))
{
MessageBox(NULL, L"The 'CreateDevice' function failed.", L"Error!", MB_OK);
PostQuitMessage(0);
}
return;
}


I just have a couple of questions regarding this code--first, is it right that the FAILED() macro will only run in debug mode? Because that's the only time it will show me my MessageBox error, when running the program normally it will just do nothing. Second, I am having trouble debugging and can't find an error being output. I am ALT-TABBING out of my program once the MessageBox comes up so I can see the debug messages, but they just disappear until I step past that line (F10).

Can anyone please tell me how I should proceed?


Thanks :)

Share this post


Link to post
Share on other sites
Advertisement
FAILED() doesn't change behavior in debug vs. release. There's probably something else in your code that behaves differently in those two modes, although without seeing more of your program it's hard to guess what that might be.

Share this post


Link to post
Share on other sites
Since I can't pinpoint any further than I have already, I have put all my code up on here. Sorry about that, it's not too long :-).

main.cpp#include "global_header.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR nCmdLine, int nCmdShow)
{
WINDOW_PROPERTIES wp;

display_window(hInstance, nCmdShow, &wp);
init_d3d(&wp);
render();
clean_d3d();
main_loop();

return 0;
}

void display_window(HINSTANCE hInstance, int nCmdShow, WINDOW_PROPERTIES* wp)
{
WNDCLASSEX win_class;

ZeroMemory(&win_class, sizeof(WNDCLASSEX));

win_class.cbSize = sizeof(WNDCLASSEX);
win_class.lpfnWndProc = (WNDPROC)WinProc;
win_class.hInstance = hInstance;
win_class.hCursor = LoadCursor(NULL, IDC_ARROW);
win_class.hbrBackground = (HBRUSH)COLOR_WINDOW;
win_class.lpszClassName = L"WinClass";

RegisterClassEx(&win_class);

wp->hWnd = CreateWindowEx(
NULL,
win_class.lpszClassName,
L"Game Engine",
wp->windowed ? WS_OVERLAPPEDWINDOW : WS_EX_TOPMOST | WS_POPUP,
s_width/2 - wp->width/2, s_height/2 - wp->height/2,
wp->width, wp->height,
NULL,
NULL,
hInstance,
NULL
);

ShowWindow(wp->hWnd, nCmdShow);


}

bool handle_messages(void)
{
static MSG message;

if(PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
if(message.message == WM_QUIT)
{
return false;
}
TranslateMessage(&message);
DispatchMessage(&message);
}
return true;
}

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{


switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}


direct3d.cpp

#include "global_header.h"

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
D3DPRESENT_PARAMETERS d3dpp;

void init_d3d(WINDOW_PROPERTIES* wp)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.Windowed = wp->windowed;
d3dpp.BackBufferWidth = wp->width;
d3dpp.BackBufferHeight = wp->height;

if(FAILED(d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
wp->hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev)))
{
MessageBox(NULL, L"The 'CreateDevice' function failed.", L"Error!", MB_OK);
PostQuitMessage(0);
}
return;
}
void render(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(150, 0, 150), 1.0f, 0);
d3ddev->BeginScene();
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}


void clean_d3d(void)
{
d3ddev->Release(); d3d->Release();
}


main_loop.cpp

#include "global_header.h"

void main_loop(void)
{
while(handle_messages())
{
// stuff goes here.
}
}


window_properties.h

struct WINDOW_PROPERTIES
{
HWND hWnd;
int width, height;
bool windowed;

WINDOW_PROPERTIES()
{
hWnd = NULL;
width = 800;
height = 600;
windowed = false;
}
};


global_header.h


#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>

#include "window_properties.h"

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

#define s_width GetSystemMetrics(SM_CXFULLSCREEN) // height and width of the screen in pixels (int).
#define s_height GetSystemMetrics(SM_CYFULLSCREEN) // ...


// main.cpp
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
bool handle_messages(void);
void display_window(HINSTANCE hInstance, int nCmdShow, WINDOW_PROPERTIES* wp);
// main_loop.cpp
void main_loop(void);


// direct3d.cpp
void init_d3d(WINDOW_PROPERTIES* wp);
void render(void);
void clean_d3d(void);

Share this post


Link to post
Share on other sites
Set a breakpoint, run in the debugger, and double-check the values of wp->width and wp->height immediately before your CreateDevice call; you may be trying to use an unsupported video mode.

Share this post


Link to post
Share on other sites
Hi, thanks,

I set some breakpoints and found the values were okay. I took some screenshots of the debugger because I'm not sure what to make of it. There is an "Error" message in there but I don't know what it is telling me or how I go about fixing it and I'm not even sure if it's related.

Debugger before CreateDevice function called: http://img443.images...redebuggerq.png
Debugger after CreateDevice function called: http://img339.images...terdebugger.png

Is this anything to go on? Are there any error catching FLAGS I can put in the parameter list to help me pinpoint the problem?

I hate these cryptic problems!! Anyway, thanks for responding :).

Share this post


Link to post
Share on other sites
Switch to the Direct3D debug runtime and look in the Output window in your IDE for any messages following the CreateDevice call.

Share this post


Link to post
Share on other sites
EDIT: didn't see your replies, thank you I will read them now.
I've noticed another weird thing happening in my program. If I put [font="Courier New"]d3dpp.windowed = false;[/font][font="Arial"] I get a windowed program and my entire windows style changes. I've taken screen shots:[/font]

[font="Arial"]d3dpp.windowed = false: http://img196.images...ndowedfalse.png[/font]
[font="Arial"]d3dpp.windowed = true: http://img834.images...indowedtrue.png[/font]

[font="Arial"]What on earth is happening?![/font]

[font="Arial"]I really am sorry to be asking so many questions in a single thread, but I just don't know what to do about this code. I'd rather find out the problem, than copy & paste my pre-written code that works (which is IDENTICAL) and not find the solution.[/font]

[font="Arial"]Thanks :).[/font]

Share this post


Link to post
Share on other sites
I know, but I put [font="Courier New"]d3dpp.windowed = false[/font] and it gave me a windowed program in a totally new style that I've never seen before.

Also just noted that my MessageBox error code only runs if I change my width & height to match the 1400*900 desktop resolution I am running.

(wow--just googled "d3dpp.windowed = false gives a windowed program" and the first result is this thread!) :angry:

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!