• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Hawkblood

VC++ 2010 crashes on ShowWindow(..)

20 posts in this topic

I am trying to shift my project to my other computer. I think I have the compiler set up properly. Initially, I thought it was DX causing the issue, but I narrowed it down to WinMain(..). Here is the code:

int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)
 {
     HWND hWnd;
     WNDCLASSEX wc;

     ZeroMemory(&wc, sizeof(WNDCLASSEX));

     wc.cbSize = sizeof(WNDCLASSEX);
     wc.style = CS_HREDRAW | CS_VREDRAW;
     wc.lpfnWndProc = WindowProc;
     wc.hInstance = hInstance;
     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    // wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    // not needed any more
     wc.lpszClassName = "WindowClass";

     RegisterClassEx(&wc);

     hWnd = CreateWindowEx(NULL,
                           "WindowClass",
                           "Our Direct3D Program",
                           WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
                           0, 0,    // the starting x and y positions should be 0
                           int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
                           NULL,
                           NULL,
                           hInstance,
                           NULL);
//return 0;//exits without crashing
     ShowWindow(hWnd, nCmdShow);
return 0;//it will crash here
     // set up and initialize Direct3D
     GameEngine.initD3D(hWnd,hInstance);

	 //init the environment here. 

     // enter the main loop:
	 UINT ExitMessage=GameEngine.MainLoop();

     return ExitMessage;
 }



Notice the 2 return lines arround ShowWindow(..)? That's how I came to the conclusion it had something to do with showing the window. I believe it's the creation that's actually causing the problem, but I don't know what could cause it to work on one machine and not another. Perhapse I don't have the correct SDK (VC) or I don't have my compiler set up correctly????

0

Share this post


Link to post
Share on other sites

Im pretty sure it crash inside GameEngine.initD3D(hWnd,hInstance), but without further information we can't help you much. Try debuggging it and see where it really crash. ShowWindow returning 0 is perfectly normal. Is hWnd NULL or not?

Edited by jbadams
Restored post contents from history.
1

Share this post


Link to post
Share on other sites

You're not checking the return value from your CreateWindowEx call (a run in your debugger with a breakpoint set at your ShowWindow call would have told you that you didn't have a valid HWND here).  Also, some of your CreateWindowEx parameters are wrong - please review the documentation at http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680%28v=vs.85%29.aspx and correct them before continuing any further with this.

 

If it worked on one PC it was certainly by accident rather than by design.

 

 

I am trying to shift my project to my other computer. I think I have the compiler set up properly. Initially, I thought it was DX causing the issue, but I narrowed it down to WinMain(..). Here is the code:

int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)
 {
     HWND hWnd;
     WNDCLASSEX wc;

     ZeroMemory(&wc, sizeof(WNDCLASSEX));

     wc.cbSize = sizeof(WNDCLASSEX);
     wc.style = CS_HREDRAW | CS_VREDRAW;
     wc.lpfnWndProc = WindowProc;
     wc.hInstance = hInstance;
     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    // wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    // not needed any more
     wc.lpszClassName = "WindowClass";

     RegisterClassEx(&wc);

     hWnd = CreateWindowEx(NULL,
                           "WindowClass",
                           "Our Direct3D Program",
                           WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
                           0, 0,    // the starting x and y positions should be 0
                           int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
                           NULL,
                           NULL,
                           hInstance,
                           NULL);
//return 0;//exits without crashing
     ShowWindow(hWnd, nCmdShow);
return 0;//it will crash here
     // set up and initialize Direct3D
     GameEngine.initD3D(hWnd,hInstance);

	 //init the environment here. 

     // enter the main loop:
	 UINT ExitMessage=GameEngine.MainLoop();

     return ExitMessage;
 }



Notice the 2 return lines arround ShowWindow(..)? That's how I came to the conclusion it had something to do with showing the window. I believe it's the creation that's actually causing the problem, but I don't know what could cause it to work on one machine and not another. Perhapse I don't have the correct SDK (VC) or I don't have my compiler set up correctly????

If I am not wrong...WS_EX_TOPMOST is an extended style, the extended styles shoud be in the first parameter and the "normal" styles in the fourth

 

So it should be CreateWindowEx(WS_EX_TOPMOST,  "WindowClass", "Our Direct3D Program", WS_POPUP,...

 

Probably the WS_EX_TOPMOST is being interpreted wrong and there is a conflict with the WS_POPUP

Edited by Ravnock
1

Share this post


Link to post
Share on other sites

I think it was a problem with my WNDCLASSEX. I adjusted the parameters and now it doesn't crash-- it just exits. I checked hWnd and it's NULL. Shouldn't it have a value? Here is the updated code:

 int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)
 {
     HWND hWnd;



    WNDCLASSEX windowClass;
    windowClass.lpszClassName = "Main Class";
    windowClass.cbClsExtra = NULL;
    windowClass.cbWndExtra = NULL;
    windowClass.cbSize = sizeof(WNDCLASSEX);
    windowClass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(150,0,0));
    windowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
    windowClass.hIcon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION));
    windowClass.hIconSm = (HICON) LoadImage(NULL,MAKEINTRESOURCE(IDI_APPLICATION),IMAGE_ICON,16,16,NULL);
    windowClass.hInstance = hInstance;
    windowClass.lpfnWndProc = WindowProc;
    windowClass.lpszMenuName = NULL;
    windowClass.style = CS_VREDRAW | CS_HREDRAW;
    RegisterClassEx(&windowClass);

     hWnd = CreateWindowEx(WS_EX_TOPMOST,//WS_EX_TOPMOST
                           "WindowClass",
                           "Our Direct3D Program",
                            WS_POPUP,    // fullscreen values
                           0, 0,    // the starting x and y positions should be 0
                           int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
                           NULL,
                           NULL,
                           hInstance,
                           NULL);


     ShowWindow(hWnd, nCmdShow);// nCmdShow
     // set up and initialize Direct3D
     GameEngine.initD3D(hWnd,hInstance);

	 //init the environment here. 
     // enter the main loop:
	 UINT ExitMessage=GameEngine.MainLoop();

     return ExitMessage;
}

What could I be doing wrong? The exit occurs just after I d3d->CreateDevice(..) because I don't get a pointer to the device.

0

Share this post


Link to post
Share on other sites

Thanks for the advice guys/gals. Now it seems to get everything up to ShowWindow(..). I get a red screen and it crashes:

 int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)
 {
     HWND hWnd;



    WNDCLASSEX windowClass;
	ZeroMemory(&windowClass,sizeof(WNDCLASSEX));
    windowClass.lpszClassName = "WindowClass";
    windowClass.cbClsExtra = 0;
    windowClass.cbWndExtra = 0;
    windowClass.cbSize = sizeof(WNDCLASSEX);
    windowClass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(150,0,0));
    windowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
    windowClass.hIcon = LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION));
    windowClass.hIconSm = (HICON) LoadImage(NULL,MAKEINTRESOURCE(IDI_APPLICATION),IMAGE_ICON,16,16,NULL);
    windowClass.hInstance = hInstance;
    windowClass.lpfnWndProc = WindowProc;
    windowClass.lpszMenuName = NULL;
    windowClass.style = CS_VREDRAW | CS_HREDRAW;
//    RegisterClassEx(&windowClass);
    if(!RegisterClassEx (&windowClass))
    {
        MessageBox (NULL, "Class registration failed!", "Error!", MB_OK);
        PostQuitMessage (0);
        return 1;
    }

     hWnd = CreateWindowEx(WS_EX_TOPMOST,//WS_EX_TOPMOST
                           "WindowClass",
                           "Our Direct3D Program",
                            WS_POPUP,    // fullscreen values
                           0, 0,    // the starting x and y positions should be 0
                           int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
                           NULL,
                           NULL,
                           hInstance,
                           NULL);

    if(!hWnd)
    {
        MessageBox (NULL, "hWnd NULL", "Error!", MB_OK);
        PostQuitMessage (0);
        return 1;
    }
     ShowWindow(hWnd, nCmdShow);// nCmdShow
     // set up and initialize Direct3D

	 return 0;//just want to exit the program to rule out DirectX......


     GameEngine.initD3D(hWnd,hInstance);

	 //init the environment here. 
     // enter the main loop:
	 UINT ExitMessage=GameEngine.MainLoop();

     return ExitMessage;
}

As you can see, I exit just after ShowWindow(..), so there's nothing else running in the program. WHAT AM I DOING WRONG!!! This is frustrating. The original post's code worked just fine on my other computer, but somehow it doesn't work on this one.....????

0

Share this post


Link to post
Share on other sites

WHAT AM I DOING WRONG!!!!

 

You're not running in your debugger.

 

Make a debug build, run it under your debugger, and it will tell you what line of code it crashed on, let you inspect the values of variables (to help you find out what crashed it) and lots of other good stuff.

1

Share this post


Link to post
Share on other sites

I put a break at ShowWindow(..). Here is the output (image):

 

 

That is the farthest I can put a break without it crashing. When it crashes, I don't get anything but a red screen (that's the color I have for the background) and when I look at the task manager, it says the program is not responding.....

 

I was able to get a snapshot of an error. It is in "crt0dat.c". I'm thinking I have issues with my compiler.....

0

Share this post


Link to post
Share on other sites

Post your WndProc.

 

Actually make a new project and paste your code there and then post the entire code if it still crashes, don't include stuff that isn't used. Perhaps you use something from WndProc that isn't created yet. Try putting ShowWindow right before the main-loop after D3D is set up etc.

1

Share this post


Link to post
Share on other sites

That's what I did. Just finished cleaning it up so it would work. It runs but that doesn't explain what caused the issue in the first place.....

0

Share this post


Link to post
Share on other sites

Just guessing unless you post the whole code in its entirety, but when you call ShowWindow it will call your WindowProc with a couple of messages, and perhaps the D3D device was used there, before it was initialized, or similar.

2

Share this post


Link to post
Share on other sites

I don't have the code that isn't working. I moved all my files into another project and I got it to work. That's actually funny: the "solution" was the "problem"....biggrin.png

0

Share this post


Link to post
Share on other sites
Access violation reading location 0x00000000

 

You've a NULL pointer somewhere that you're trying to use.  Again, this is something that your debugger will tell you.  At this stage you're getting into fairly basic stuff and essentially asking us to debug your code for you.  I don't mean to be rude here, but you're really not showing many signs of trying very hard - or at all - yourself.  If you had run this in your debugger it would have halted execution at the offending line, enabling you to determine exactly what has happened.  If you had been using your debugger you would have stepped through line-by-line and found what you were doing wrong.  Which leads me to suspect that you haven't.

Edited by mhagain
1

Share this post


Link to post
Share on other sites

I did run the debugger. The "offending line" had something to do with the exit of the program. That didn't tell me anything. The problem was some kind of corruption in my VC++ solution file. When I started over with a new solution, the problem went away. Debug will only show me the answer if the problem is in my program. This went beyond that, so to say I wasn't trying is a bit insulting.

0

Share this post


Link to post
Share on other sites

A general advice from my experience as a programmer: every time I think the compiler/the framework is wrong, it always turns out *I* did something wrong.

 

In C++ Win32/COM programming, you have to understand the error model, which is quite different from the easy-peasy world of .NET/Java. As others said before, CreateWindow/CreateWindowEx can fail for many reasons - most probably because of incorrect arguments or WinProc. In the first case, GetLastError() and Google would help you, and in the case of WinProc - a few well-placed breakpoints at key messages would pin-point the problem. You should also absolutely always check return codes... this isn't Java/.NET where something crashes with a nice exception - return codes and/or GetLastError() are the way.

1

Share this post


Link to post
Share on other sites

I get your point. The thing is, I took my original code files and put them into a new project and it worked fine. The problem started when I transferred my project from one computer to another, something happened..... Maybe there was something wrong with the project/solution or I had some update issues with the new computer/compiler that caused it. So ultimately this problem WAS something other than my program.

0

Share this post


Link to post
Share on other sites

I don't have the code that isn't working. I moved all my files into another project and I got it to work. That's actually funny: the "solution" was the "problem"....biggrin.png

That sounds like you should learn about using a version control system to not loose code. Mercurial(hg) would be easiest to learn, but git is also widely used. (Even if you dont want to learn one of those at least start with the poor mans "version control" of copying the whole folder every time before you change anything and number those by date.)

0

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  
Followers 0