• Advertisement
Sign in to follow this  

Program crashing immediately

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

So first I'd like to thank anyone who holds this forum up. Such a help :) Problem is when I open my program, then it crashes right away. Code should be fine, because everyone using it when looking from google, but this thing haven't happened yet. Code
// include the basic windows header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
// global declarations
LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class

// function prototypes
void initD3D(HWND hWnd);    // sets up and initializes Direct3D
void render_frame(void);    // renders a single frame
void cleanD3D(void);    // closes Direct3D and releases memory
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam);

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    // the handle for the window, filled by a function
    HWND hWnd;
    // this struct holds information for the window class
    WNDCLASSEX wc;

    // clear out the window class for use
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    // fill in the struct with the needed information
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass1";

    // register the window class
    RegisterClassEx(&wc);

    // create the window and use the result as the handle
    hWnd = CreateWindowEx(NULL,
                          L"WindowClass1",    // name of the window class
                          L"Our First Windowed Program",    // title of the window
                          WS_OVERLAPPEDWINDOW,    // window style
                          300,    // x-position of the window
                          300,    // y-position of the window
                          640,    // width of the window
                          480,    // height of the window
                          NULL,    // we have no parent window, NULL
                          NULL,    // we aren't using menus, NULL
                          hInstance,    // application handle
                          NULL);    // used with multiple windows, NULL

    // display the window on the screen
    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    initD3D(hWnd);
    // enter the main loop:

    // this struct holds Windows event messages
    MSG msg;

    // Enter the infinite message loop
    while(TRUE)
    {
          // find out the starting time of each loop
          DWORD starting_point = GetTickCount();

          // Check to see if any messages are waiting in the queue
          if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
          {
              // If the message is WM_QUIT, exit the while loop
              if (msg.message == WM_QUIT)
                  break;

              // translate keystroke messages into the right format
              TranslateMessage(&msg);

              // send the message to the WindowProc function
              DispatchMessage(&msg);
          }
		  render_frame();
          // Run game code here
          // ...
          // ...

          // wait until 1/40th of a second has passed
          while ((GetTickCount() - starting_point) < 25);
    } 
    // clean up DirectX and COM
    cleanD3D();
    // return this part of the WM_QUIT message to Windows
    return msg.wParam;
}

// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch(message)
    {
        // this message is read when the window is closed
        case WM_DESTROY:
            {
                // close the application entirely
                PostQuitMessage(0);
                return 0;
            } break;
    }

    // Handle any messages the switch statement didn't
    return DefWindowProc (hWnd, message, wParam, lParam);
}

// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D


    // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);

    return;
}
// this is the function used to render a single frame
void render_frame(void)
{
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen

    return;
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
    d3ddev->Release();    // close and release the 3D device
    d3d->Release();    // close and release Direct3D

    return;
}



When cutting this a part, I found out that the problem comes up, if calling out
render_frame();


If i delete
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen


from the function, then window will appear. Otherways I can see my window(without colored background) and closing it in some milliseconds. I made some experiments with other compilers and visual cpp 6 gave me this error. http://www.marxxx.pri.ee/kraam/pildid/dxbug.png Unfortunately I couldn't get it compiled in devcpp, because it gave some errors with opening bin directory. But its old and I don't know if works with directx. The tutorial I got this code is here ( http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B1.aspx#still ). In control panel->system->advanced->enviroment variables->Path i got this
C:\Program Files\Microsoft DirectX SDK (April 2007)\Utilities\Bin\x86


While installing dx SDK it edited that place itself, so I guess I dont need to edit that. Thank you :) Marko [Edited by - marxxx on October 31, 2007 3:59:23 AM]

Share this post


Link to post
Share on other sites
Advertisement
From what i can tell, your d3ddev is NULL pointered (address 0x00000000), do


if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev))
//Treat error;



To be sure. If it fails, then the problem is probably in d3d, it may also be a NULL pointer.

Good luck!

Share this post


Link to post
Share on other sites
Hey, firstly nice work posting lots of information.

I can't see anything wrong from quickly looking over the code, it seems fairly standard. However, the exception your getting in vc6 has gotta be a clue, one of your pointers is NULL.

Since if you take render_frame() out and it works, the only thing your referencing there is d3ddev, so maybe that hasn't initialised properly for some reason? Try looking at the return code from d3d->CreateDevice and see what it is..

Share this post


Link to post
Share on other sites
Im not really good at these things, because I don't know a lot, but I made this
    if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev)))
{
MessageBox(NULL,
L"d3d->CreateDevice",
L"Failed creating device",
MB_ICONEXCLAMATION | MB_OK);
return;
}




If I execute program now, then message box appears. Something wrong with CreateDevice() then? So what can I do?


e. While searching google I found this
	HRESULT hResult;
hResult = d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);

if(FAILED(hResult))
{
throw hResult;
return;
}



When running program witch was created by vcppexpress, then following error appeared.
www.marxxx.pri.ee/kraam/pildid/newerror.png
Basicly It doesn't show anything new, but just incase :)
Pressing abort, retry or ingore, nothing happens. Just closes program

[Edited by - marxxx on October 29, 2007 4:13:55 AM]

Share this post


Link to post
Share on other sites
Ok cool. it's weird that it's failing at this point..

Now try having a look at d3d after you call Direct3DCreate9(D3D_SDK_VERSION)

like

d3d = Direct3DCreate9(D3D_SDK_VERSION);

if( d3d == NULL )
{
MessageBox(....);
return;
}

if that's failing then somethings really wrong.. !

and if it isn't, then it must be something about the d3dpp that is wrong..


Share this post


Link to post
Share on other sites
This doesn't show MessageBox:
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

if( d3d == NULL )
{
MessageBox(NULL, L"error", L"Yess", MB_OK);
return;
}



and this does:
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

if( d3d != NULL )
{
MessageBox(NULL, L"error", L"Yess", MB_OK);
return;
}



So probably something wrong with d3ddpp.

I got to go at the moment so I answer here later.

Share this post


Link to post
Share on other sites
You really need to check all of your return values from D3D functions. Particularly ones that create resources (E.g. CreateDevice()). If they fail (Which they can do for multiple reasons), you've got a null pointer which will blow up as soon as you try to use it.

Another thing to do is install the debug runtimes from the DirectX control panel. If you have a recent SDK, it'll be in Start Menu -> Programs -> DirectX SDK -> Utilities -> DirectX Control Panel. If you have an older SDK, it'll be in the Windows control panel.
Go to the DirectX control panel, on the Direct3D tab, and select "Use Debug Version of Direct3D". Now whenever any D3D function fails, you'll get a useful error message spat out to the debug output window in your IDE.

Also, a little off topic - you probably want to use D3DCREATE_HARDWARE_VERTEXPROCESSING, unless you have a pre-GeForce graphics card or you're using complex vertex shaders.

Share this post


Link to post
Share on other sites
Debugging gave me this:
'directx.exe': Loaded 'C:\Documents and Settings\Marx\Desktop\allkindsofprojects\c++\directx\debug\directx.exe', Symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\mscoree.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\d3d9.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\d3d8thk.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\version.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\MsgPlusLoader.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\msvcr80.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll', No symbols loaded.
'directx.exe': Unloaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'
'directx.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\2c9986f0f331440ff369f300d6a64d51\mscorlib.ni.dll', No symbols loaded.
'directx.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', No symbols loaded.
'directx.exe' (Managed): Loaded 'c:\Documents and Settings\Marx\Desktop\allkindsofprojects\c++\directx\debug\directx.exe', Symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll', No symbols loaded.
'directx.exe' (Managed): Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\f9e0cc41d4708780bfbd7858d0ad6d6f\System.ni.dll', No symbols loaded.
'directx.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\msctf.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\d3d9d.dll', No symbols loaded.
'directx.exe': Loaded 'C:\WINDOWS\system32\d3dx9d_33.dll', No symbols loaded.
Direct3D9: :====> ENTER: DLLMAIN(0344e6e0): Process Attach: 000007ec, tid=00000528
Direct3D9: :====> EXIT: DLLMAIN(0344e6e0): Process Attach: 000007ec
Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
Direct3D9: (ERROR) :DX9 driver doesn't report DX9 DDI version - reverting to DX8 driver
Direct3D9: (ERROR) :Driver succeeded GETEXTENDEDMODECOUNT request but didn't set dwModeCount. Driver error.
Direct3D9: (WARN) :****Direct3D DRIVER DISABLING ERROR****:First call to DdQueryDirectDrawObject failed!
Direct3D9: (ERROR) :No hardware acceleration is available in the current mode
Direct3D9: (ERROR) :DX9 driver doesn't report DX9 DDI version - reverting to DX8 driver
Direct3D9: (ERROR) :Driver succeeded GETEXTENDEDMODECOUNT request but didn't set dwModeCount. Driver error.
Direct3D9: (WARN) :****Direct3D DRIVER DISABLING ERROR****:First call to DdQueryDirectDrawObject failed!
Direct3D9: (ERROR) :No hardware acceleration is available in the current mode
Direct3D9: (ERROR) :No hardware acceleration is available in the current mode
Direct3D9: (ERROR) :No ddraw acceleration is available in the current mode
D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO
Direct3D9: (ERROR) :DX9 driver doesn't report DX9 DDI version - reverting to DX8 driver
Direct3D9: (ERROR) :Driver succeeded GETEXTENDEDMODECOUNT request but didn't set dwModeCount. Driver error.
Direct3D9: (WARN) :****Direct3D DRIVER DISABLING ERROR****:First call to DdQueryDirectDrawObject failed!
First-chance exception at 0x7c812a5b in directx.exe: Microsoft C++ exception: long at memory location 0x0012eff8..
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in directx.exe
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in directx.exe

Additional information: External component has thrown an exception.

The thread 'Win32 Thread' (0xd90) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x268) has exited with code 0 (0x0).
The program '[2028] directx.exe: Managed' has exited with code 0 (0x0).
The program '[2028] directx.exe: Native' has exited with code 0 (0x0).






Share this post


Link to post
Share on other sites
I know my computer is bad, but I never tought it could interput programming.
I got SiS 650_651_M650_740 and I got latest drivers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement