• 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
??????? ?????

Windows has triggered a breakpoint,error at SetFVF()

14 posts in this topic

I get the message



[quote]
Windows has triggered a breakpoint in D3D.exe.

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

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

The output window may have more diagnostic information.[/quote]

it says the error is right here at the bold line:


[CODE]
void Terrain::Render()
{
m_d3dDevice->SetMaterial( &m_material );
m_d3dDevice->SetTexture(0,NULL);
m_d3dDevice->SetStreamSource( 0, m_vb,0, sizeof(CUSTOMVERTEX) );
[u][i][b] m_d3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );[/b][/i][/u]
m_d3dDevice->SetIndices( m_ib );

m_d3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,CHUNK_VERTICES,0,CHUNK_PRIMITIVES);
}[/CODE]

I've been banging my head and I can't seem to understand what the problem could be.Here are the other methods,but as far as I know they work without errors:


[CODE]
void Terrain::CreateMaterial(float r,float g,float b,float a)
{
ZeroMemory( &m_material, sizeof(D3DMATERIAL9) );
m_material.Diffuse.r = m_material.Ambient.r = r;
m_material.Diffuse.g = m_material.Ambient.g = g;
m_material.Diffuse.b = m_material.Ambient.b = b;
m_material.Diffuse.a = m_material.Ambient.a = a;
}

void Terrain::Update()
{
int count=0;
int vIndex=0;
HRESULT hr=m_d3dDevice->CreateVertexBuffer( CHUNK_VERTICES*sizeof(CUSTOMVERTEX),D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED, &m_vb, NULL );

hr=m_d3dDevice->CreateIndexBuffer(sizeof(short)*CHUNK_PRIMITIVES*3,D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ib, NULL);

hr=m_vb->Lock( 0, 0, (void**)&pVertices, 0 );
hr=m_ib->Lock( 0, 0, (void**)&indices, 0 );

for(int i=0;i<CHUNK_HEIGHT+1;i++)
{
for(int n=0;n<CHUNK_WIDTH+1;n++)
{
pVertices->p.x = n;
pVertices->p.y = i;
pVertices->p.z = 0;
pVertices->n.x = n;
pVertices->n.y = i;
pVertices->n.z = 0;
pVertices->tu = 0;
pVertices->tv = 0;

indices[count++]=vIndex;
indices[count++]=vIndex+n;
indices[count++]=vIndex+n+1;

indices[count++]=vIndex;
indices[count++]=vIndex+n+1;
indices[count++]=vIndex+1;

vIndex++;
}
vIndex++;
}

m_vb->Unlock();
m_ib->Unlock();

}[/CODE]


and as for the custom vertex:


[CODE]
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
#define CHUNK_HEIGHT 64
#define CHUNK_WIDTH 64

#define CHUNK_VERTICES 4225
#define CHUNK_PRIMITIVES 8192

struct CUSTOMVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
float tu,tv;
};[/CODE] at the top of my code,and I don't think any of them are faulty either
0

Share this post


Link to post
Share on other sites
That error message means that at some point previous to that line of code the heap has been trashed.

Firstly, you appear to be writing data to the same vertex over and over again, which shouldn't cause any harm but it looks like a bug.

What I'd suggest doing is adding assert( [url="http://msdn.microsoft.com/en-us/library/e73x0s4b%28v=vs.80%29.aspx"]_CrtCheckMemory( )[/url] ); tests backwards from the point of the crash. That should let you work out which line of code makes that assert trigger.
0

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1335740630' post='4935924']
That error message means that at some point previous to that line of code the heap has been trashed.

Firstly, you appear to be writing data to the same vertex over and over again, which shouldn't cause any harm but it looks like a bug.

What I'd suggest doing is adding assert( [url="http://msdn.microsoft.com/en-us/library/e73x0s4b%28v=vs.80%29.aspx"]_CrtCheckMemory( )[/url] ); tests backwards from the point of the crash. That should let you work out which line of code makes that assert trigger.
[/quote][quote name='Adam_42' timestamp='1335740630' post='4935924']
That error message means that at some point previous to that line of code the heap has been trashed.

Firstly, you appear to be writing data to the same vertex over and over again, which shouldn't cause any harm but it looks like a bug.

What I'd suggest doing is adding assert( [url="http://msdn.microsoft.com/en-us/library/e73x0s4b%28v=vs.80%29.aspx"]_CrtCheckMemory( )[/url] ); tests backwards from the point of the crash. That should let you work out which line of code makes that assert trigger.
[/quote]

yeah,it's the [CODE] m_d3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );[/CODE] that's giving an error,any idea why this might happen?I passed a proper [i][b]FVF [/b][/i]argument that matches my [b][i]CUSTOMVERTEX [/i][/b]struct
0

Share this post


Link to post
Share on other sites
Your problem lies in this
[code]
#define D3DFVF_CUSTOMVERTEX(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
[/code]
This is not a properly defined FVF.

SetFVF takes a DWORD as it's parameter not a define.
[code]
//From the DX SDK documentation
HRESULT SetFVF(
[in] DWORD FVF
);
[/code]
And if you would look at the examples they use in the documentation you see that they all use "const DWORD" variables to define the custom vertex format.
The better way of doing this is to use a vertexdeclaration, which will allow you to use shaders properly as well and will make the switch from DX9 to higher much easier to achieve as the fixed function pipeline is dead. Edited by NightCreature83
-2

Share this post


Link to post
Share on other sites
What happens if you put assert( [url="http://msdn.microsoft.com/en-us/library/e73x0s4b%28v=vs.80%29.aspx"]_CrtCheckMemory( )[/url] ); right before the SetFVF() call?

You'll need to #include <crtdbg.h> and #include <assert.h> to get that to compile. Edited by Adam_42
0

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1335771694' post='4936008']
Your problem lies in this
[code]
#define D3DFVF_CUSTOMVERTEX(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
[/code]
This is not a properly defined FVF.

SetFVF takes a DWORD as it's parameter not a define.
[code]
//From the DX SDK documentation
HRESULT SetFVF(
[in] DWORD FVF
);
[/code]
And if you would look at the examples they use in the documentation you see that they all use "const DWORD" variables to define the custom vertex format.
The better way of doing this is to use a vertexdeclaration, which will allow you to use shaders properly as well and will make the switch from DX9 to higher much easier to achieve as the fixed function pipeline is dead.
[/quote]

I changed it to [b][i]const DWORD D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1); [/i][/b]
but it still gives the same error.I actualy used [i][b]#define[/b][/i] before,because that's how I saw it in [b][i]msdn[/i][/b].( [url="http://msdn.microsof...9(v=vs.85"]http://msdn.microsof...9(v=vs.85[/url]).aspx )My [b][i]CUSTOMVERTEX [/i][/b]pretty much matches the FVF,doesn't it?


[CODE]
struct CUSTOMVERTEX
{
D3DXVECTOR3 p; //D3DFVF_XYZ
D3DXVECTOR3 n; //D3DFVF_NORMAL
float tu,tv; //D3DFVF_TEX1
};[/CODE]

[quote name='Adam_42' timestamp='1335740630' post='4935924']
[left][background=rgb(250, 251, 252)]What happens if you put assert( [/background][/left]
[url="http://msdn.microsoft.com/en-us/library/e73x0s4b%28v=vs.80%29.aspx"]_CrtCheckMemory( )[/url]



[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=4][background=rgb(250, 251, 252)]); right before the SetFVF() call?[/background][/size][/font][/color][/left]
[/quote]

I attached an image of the result.

The second square of code(where the error occurs in the green code) is in [b][i]mlock.c[/i][/b]
[attachment=8553:error.png]
I also used windows symbols to get a more detailed stack heap,but I can't really figure out why setting a new vertex declaration corrupts the heap.
[attachment=8558:Call Stack.png] Edited by Bogomil
0

Share this post


Link to post
Share on other sites
You need to use another macro in your FVF as well that tells the DX9 runtime how many tex coords to expect. You have to use this macro(texcoordSizeN) as well I think
[quote]
#define Description D3DFVF_TEX0 - D3DFVF_TEX8 Number of texture coordinate sets for this vertex. The actual values for these flags are not sequential. D3DFVF_TEXCOORDSIZEN(coordIndex) Define a texture coordinate data set. n indicates the dimension of the texture coordinates. coordIndex indicates texture coordinate index number. See D3DFVF_TEXCOORDSIZEN and Texture coordinates and Texture Stages.
[/quote]
It's been a really long time since I have done anyting with the FF.

Basically the D3DFVF_TEXn flags only define how many texture cooridnate sets the runtime expects, the TexcoordSizeN flag tells the runtime the size of these texture coordinate streams. And it might be that you need to tell the runtime about this as well.

With VertexDeclarations, which you can mix with FF, this is a bit more explicit and clearer to the reader that you specify the size of the things as well. See [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb147173(v=vs.85).aspx"]this[/url] for a translation between FVF->VertexDecalaration and [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173388(v=vs.85).aspx"]this[/url] for an explanation of how the shader engine sees the FVF codes.

And seeing that callstack your runtime is converting to the shader pipeline in D3D9 anyways and probably because the TexCoordSizeN flag isn't present it is failing to create the correct VertexDeclaration. If you run the D3D9 runtime on a DX10 or greater card the runtime will convert all Fixed Function calls to shader calls on the fly, and thats exactly what that callstack is telling you with the line "CFVFToDecl::GetDeclaration" and "CVertexDeclaration::Create" this must be reading from some address it isn't allowed to and hence the crash. Edited by NightCreature83
0

Share this post


Link to post
Share on other sites
Have you tried enabling the [url="http://legalizeadulthood.wordpress.com/2009/06/28/direct3d-programming-tip-5-use-the-debug-runtime/"]D3D Debug Runtime[/url]? It usually gives a lot of clues when something fails with D3D.

[quote]You need to use another macro in your FVF as well that tells the DX9 runtime how many tex coords to expect.[/quote]

The default number of texcoords in FVF is 2 so this is not the problem here. But I agree that vertex declarations are the way to go.
0

Share this post


Link to post
Share on other sites
[quote name='froop' timestamp='1335791802' post='4936070']
Have you tried enabling the [url="http://legalizeadulthood.wordpress.com/2009/06/28/direct3d-programming-tip-5-use-the-debug-runtime/"]D3D Debug Runtime[/url]? It usually gives a lot of clues when something fails with D3D.

[quote]You need to use another macro in your FVF as well that tells the DX9 runtime how many tex coords to expect.[/quote]

The default number of texcoords in FVF is 2 so this is not the problem here. But I agree that vertex declarations are the way to go.
[/quote][quote name='froop' timestamp='1335791802' post='4936070']
Have you tried enabling the [url="http://legalizeadulthood.wordpress.com/2009/06/28/direct3d-programming-tip-5-use-the-debug-runtime/"]D3D Debug Runtime[/url]? It usually gives a lot of clues when something fails with D3D.

[quote]You need to use another macro in your FVF as well that tells the DX9 runtime how many tex coords to expect.[/quote]

The default number of texcoords in FVF is 2 so this is not the problem here. But I agree that vertex declarations are the way to go.
[/quote]

Yeah I still haven't implemented shaders in my engine,just working on models and terrain right now,so for now I'm using just SetFVF(),could the problem be in some DLL?I checked everything in the source,the D3DDevice is initialized,the FVF is properly declared and the vertex/index buffers create and lock/unlock without a problem.
0

Share this post


Link to post
Share on other sites
Could you provide us with the output window error when this happens, even if it is just a access violation. These errors can tell you quite a bit of whats gone wrong. And as Froop suggests turn the debug runtime on.
The error is happening on a memory allocation from just looking at your callstack, the address of that location would be interesting to see as that could be pointing at 0 or some other memory location thats not allowed. So please could you give us the output window text as well, which shows the error.

Also nearly every D3D call returns a HRESULT, inspect what that result is on all calls that return one, if it is not D3D_OK use the error tool in the SDK folder to figure out wha the error means. When running with the debug runtime the information it spits out and the return codes should point you into the direction of the problem. Edited by NightCreature83
0

Share this post


Link to post
Share on other sites
Hi,

how about the size of the index buffer? The size is defined as 2 * 8192 * 3 which gives 49152 bytes. However, you write 65*65*6*2 = 50700 amount of bytes.

Best regards! Edited by kauna
0

Share this post


Link to post
Share on other sites
It turned out the error is something even deeper,I commented out the entire Terrain class and everywhere it's referenced and now it won't even render the FPS counter text,which worked perfectly a while ago.It even shows the window background color as if the D3D device isn't initialized,even tho it initializes without an error.I guess I'll have to start from scratch,since it's 3000 lines of spaghetti code now and I don't know how to find the problem.
0

Share this post


Link to post
Share on other sites
When this happens it is really time to start checking every HRESULT coming from API and DX calls and when one returns different from D3D_OK or S_OK, assert and check the values you are passing to your API calls. Most API calls when they fail will give you a reason why they fail.
Also spagetti code is recoverable just requires more work, easiest is to start splitting of classes to their own files and take it from there.
0

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1335813316' post='4936153']
When this happens it is really time to start checking every HRESULT coming from API and DX calls and when one returns different from D3D_OK or S_OK, assert and check the values you are passing to your API calls. Most API calls when they fail will give you a reason why they fail.
Also spagetti code is recoverable just requires more work, easiest is to start splitting of classes to their own files and take it from there.
[/quote][quote name='NightCreature83' timestamp='1335813316' post='4936153']
When this happens it is really time to start checking every HRESULT coming from API and DX calls and when one returns different from D3D_OK or S_OK, assert and check the values you are passing to your API calls. Most API calls when they fail will give you a reason why they fail.
Also spagetti code is recoverable just requires more work, easiest is to start splitting of classes to their own files and take it from there.
[/quote]

Yeah I re-ordered everything and I think I fixed the problem,cause now D3D starts and it shows the text and reads directinput properly.I jus thave one final question that might sound a little noobish - how do you make a vertex declaration for the programmable function pipeline?The method I'm using now(CUSTOMVERTEX struct,DWORD FVF_CUSTOMVERTEX(blabla|blabla|etc),set FVF) I understand is the old method that doesn't support special effects.
0

Share this post


Link to post
Share on other sites
[quote name='Bogomil' timestamp='1335881774' post='4936426']
how do you make a vertex declaration for the programmable function pipeline?The method I'm using now(CUSTOMVERTEX struct,DWORD FVF_CUSTOMVERTEX(blabla|blabla|etc),set FVF) I understand is the old method that doesn't support special effects.
[/quote]

Look at the D3DXDeclaratorFromFVF function as a place to start - you can use it to get an array of D3DVERTEXELEMENT9 structs that can then be passed into a CreateVertexDeclaration call, so much of what you currently know is reusable. That should get you up and running quite fast with declarations, and make it easier to move on to custom declarations when the time comes.
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