Jump to content
  • Advertisement
Sign in to follow this  
Pero83

Need help with error

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

I'm trying to use D3DXCreateMeshFVF to create a simple mesh, and while it does render, i get error on exiting. So, in general too, i'm just looking for some tips, how to know in future, what exactly is causing a problem.

First, my code:


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DX 6 - working with meshes
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Defines
#define CUSTOMFVF (D3DFVF_XYZ|D3DFVF_DIFFUSE)

// Includes
#include <fstream>
#include <string>
#include <iostream>
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>

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

// Defines
#define SCREEN_WIDTH 1680
#define SCREEN_HEIGHT 1050

using namespace std;

// Functions
bool init_window(HINSTANCE hInstance);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void init_d3d(HWND hWnd);
void setup_VMIB(void);
void render_frame(void);
void clean_d3d(void);

// Variables
HINSTANCE hInstance;
HWND hWnd;

// D3D variables
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPD3DXMESH mesh;

D3DXMATRIX matProj, matView;

// Structs
struct CustomVertex
{
float x,y,z;
DWORD color;
};


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Win Main
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
if(!init_window(hInstance))
return 0;

MSG msg;
ZeroMemory(&msg, sizeof(msg));

init_d3d(hWnd);
D3DXCreateMeshFVF(12, 8, D3DXMESH_VB_DYNAMIC, CUSTOMFVF, d3ddev, &mesh);
setup_VMIB();

while(true)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (msg.message == WM_QUIT)
break;
render_frame();
}
clean_d3d();
return msg.wParam;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init Window
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool init_window(HINSTANCE hInstance)
{
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(wc));

wc.cbSize = sizeof(wc);
wc.hInstance = hInstance;
wc.lpszClassName = "OBJ import Class";
wc.lpfnWndProc = WindowProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.style = CS_HREDRAW|CS_VREDRAW;

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL, "OBJ import Class", "OBJ import Window", WS_EX_TOPMOST|WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);
if (!hWnd)
return false;

ShowWindow(hWnd, SW_SHOW);
return true;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Window Proc
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY|WM_KEYDOWN:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// init D3D
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void init_d3d(HWND hWnd)
{

d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

d3d->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);
d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//setup Vertex Buffer / Index Buffer
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup_VMIB(void)
{


// vertices for the vertex buffer
CustomVertex g_Vertices[ ] = {
// X Y Z U V
{-1.0f,-1.0f,-1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 0
{-1.0f, 1.0f,-1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 1
{1.0f, 1.0f,-1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 2
{ 1.0f,-1.0f,-1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 3
{-1.0f,-1.0f, 1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 4
{1.0f,-1.0f, 1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 5
{ 1.0f, 1.0f, 1.0f, D3DCOLOR_ARGB(0,0,255,255)}, // 6
{-1.0f, 1.0f, 1.0f, D3DCOLOR_ARGB(0,0,255,255)} // 7
};

// index buffer data
WORD IndexData[ ] = {
0,1,2,
2,3,0,
4,5,6,
6,7,4,
0,3,5,
5,4,0,
3,2,6,
6,5,3,
2,1,7,
7,6,2,
1,0,4,
4,7,1
};

// prepare to copy the vertices into the vertex buffer
VOID* pVertices;
// lock the vertex buffer
mesh->LockVertexBuffer(D3DLOCK_DISCARD, &pVertices);

// copy the vertices into the buffer
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );

// unlock the vertex buffer
mesh->UnlockVertexBuffer();

// prepare to copy the indexes into the index buffer
VOID* IndexPtr;
// Lock the index buffer
mesh->LockIndexBuffer( 0, &IndexPtr );

// Copy the indexes into the buffer
memcpy( IndexPtr, IndexData, sizeof(IndexData)*sizeof(WORD) );

// unlock the buffer
mesh->UnlockIndexBuffer();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// render_frame
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 55, 155), 1.0f, 0);
d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 55, 155), 1.0f, 0);

d3ddev->BeginScene();
d3ddev->SetFVF(CUSTOMFVF);
D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(45), (float)SCREEN_WIDTH/(float)SCREEN_HEIGHT, 1.0f, 1000.0f);
d3ddev->SetTransform(D3DTS_PROJECTION, &matProj);

D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(20.0f, 20.0f, 20.0f), &D3DXVECTOR3(0, 0, 0), &D3DXVECTOR3(0, 1.0f, 0));
d3ddev->SetTransform(D3DTS_VIEW, &matView);

mesh->DrawSubset(0);

d3ddev->EndScene();

d3ddev->Present(NULL,NULL, NULL, NULL);
}



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






And here's what output window provides:




Direct3D9: (ERROR) :************************************************************
Direct3D9: (ERROR) :ASSERTION FAILED! File s:\gfx_aug09\windows\directx\dxg\inactive\d3d9\d3d\fw\lhbatchfilter.cpp Line 3466: pArgs->Flags.Discard
Direct3D9: (ERROR) :************************************************************
Direct3D9: (ERROR) :************************************************************
Direct3D9: (ERROR) :ASSERTION FAILED! File s:\gfx_aug09\windows\directx\dxg\inactive\d3d9\d3d\fw\lhbatchfilter.cpp Line 3466: pArgs->Flags.Discard
Direct3D9: (ERROR) :************************************************************
Direct3D9: (ERROR) :************************************************************
Direct3D9: (ERROR) :ASSERTION FAILED! File s:\gfx_aug09\windows\directx\dxg\inactive\d3d9\d3d\fw\lhbatchfilter.cpp Line 3466: pArgs->Flags.Discard
Direct3D9: (ERROR) :************************************************************
Direct3D9: (WARN) :Ignoring redundant SetRenderState - 7

Direct3D9: (WARN) :Indexbuffer created with POOL_DEFAULT but WRITEONLY not set. Performance penalty could be severe.
Direct3D9: (WARN) :Vertexbuffer created with POOL_DEFAULT but WRITEONLY not set. Performance penalty could be severe.
Direct3D9: (INFO) :DDI threading stopped

Direct3D9: (WARN) :INVALID FREE! cookie=3f800000, ptr = 00dddd00
Direct3D9: (WARN) :00dddd00: lAllocID=150 dwSize=0000ffff, lpAddr=6901a22b
Critical error detected c0000374
Windows has triggered a breakpoint in DX_5_Meshes.exe.

This may be due to a corruption of the heap, which indicates a bug in DX_5_Meshes.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while DX_5_Meshes.exe has focus.

The output window may have more diagnostic information.
First-chance exception at 0x777ee653 in DX_5_Meshes.exe: 0xC0000374: A heap has been corrupted.
Unhandled exception at 0x777ee653 in DX_5_Meshes.exe: 0xC0000374: A heap has been corrupted.
HEAP[DX_5_Meshes.exe]: Heap block at 00DDDC58 modified at 00DDDCE4 past requested size of 84
Windows has triggered a breakpoint in DX_5_Meshes.exe.

This may be due to a corruption of the heap, which indicates a bug in DX_5_Meshes.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while DX_5_Meshes.exe has focus.

The output window may have more diagnostic information.
HEAP[DX_5_Meshes.exe]: Invalid address specified to RtlFreeHeap( 00DD0000, 00DDDC60 )
Windows has triggered a breakpoint in DX_5_Meshes.exe.

This may be due to a corruption of the heap, which indicates a bug in DX_5_Meshes.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while DX_5_Meshes.exe has focus.

The output window may have more diagnostic information.
The thread 'Win32 Thread' (0xb34) has exited with code 0 (0x0).
'DX_5_Meshes.exe': Unloaded 'C:\Windows\SysWOW64\nvd3dum.dll'
Direct3D9: :====> ENTER: DLLMAIN(68ffd9a0): Process Detach 00000494, tid=000017bc
Direct3D9: (INFO) :MemFini!
Direct3D9: (ERROR) :Memory Address: 00dddd1c lAllocID=150 dwSize=0000ffff, ReturnAddr=6901a22b (pid=00000494)
Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 65535 bytes
Direct3D9: :====> EXIT: DLLMAIN(68ffd9a0): Process Detach 00000494
The program '[1172] DX_5_Meshes.exe: Native' has exited with code 0 (0x0).






So, any idea what can be wrong? And how can i "read" this message to understand it?

From what i see, perhabs i maybe forgot to free some resources. And what is the:

Direct3D9: (ERROR) :ASSERTION FAILED! File s:\gfx_aug09\windows\directx\dxg\inactive\d3d9\d3d\fw\lhbatchfilter.cpp Line 3466: pArgs->Flags.Discard

error?




Tnx for any help!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!