ID3DXFileSaveObject::Save() crashes when using DeclData template
What could cause ID3DXFileSaveObject::Save() to crash?
I have an exporter that works fine; it exports a variety of geometry. However, if I register the XEXTENSIONS_TEMPLATES templates, and add data of type DeclData to the file, I get no error when adding the data, but the call to Save() crashes. The DeclData contains a single declaration, for a float2 coordinate stream at texture coordinate index 1. Just removing the call to add the data removes the crash.
I'm using April 2006 SDK (d3dx_30.dll).
The code I'm using to add the DeclData is:
vector2<char> mapcoords;
DWORD d = 1;
mapcoords.append((char const *)&d, sizeof(d));
DX_VertexDecl vd;
vd.type = D3DDECLTYPE_FLOAT2;
vd.method = D3DDECLMETHOD_DEFAULT;
vd.usage = D3DDECLUSAGE_TEXCOORD;
vd.index = 1;
mapcoords.append((char const *)&vd, sizeof(vd));
d = DWORD(texcoords.size()*sizeof(DX_Coord2)/sizeof(DWORD))-1;
mapcoords.append((char const *)&d, sizeof(d));
mapcoords.append(&texcoords[sizeof(DWORD)],
texcoords.size()-sizeof(DWORD));
CHECK( stored->AddDataObject(DXFILEOBJ_DeclData, 0, 0,
mapcoords.size(), &mapcoords[0], &temp) );
"vector2" is just a wrapper around std::vector<>, and "texcoords" contains regular texture coordinates in .X file format (DWORD count + Coord2 data array), which saves and loads fine by itself.
Again, note: this code works fine. It's when calling save->Save() that D3DX crashes.
I have to admit to not doing any work with the interface you are, but in my experience its been fairly easy to confuse/crash D3DX by passing it invalid (pointer/raw) data. I've done it quite a lot with D3D10 lately [lol]
Probably a bit obvious, but are you definitely sure there are no uninitialized variables, incorrect offsets/dimensions etc...?
I suppose the other possibility is to go digging around in the source code for things like MeshViewer/dxviewer/dxops and the various exporter plugins in the SDK. Maybe, if you're lucky, you'll find a similar example you can use as a reference?
Jack
Probably a bit obvious, but are you definitely sure there are no uninitialized variables, incorrect offsets/dimensions etc...?
I suppose the other possibility is to go digging around in the source code for things like MeshViewer/dxviewer/dxops and the various exporter plugins in the SDK. Maybe, if you're lucky, you'll find a similar example you can use as a reference?
Jack
In addition to what Jack suggested, are you linking to d3dx9d.lib (the debug version)? It does more parameter checking.
I'm using the SDK headers, which magically link against the right version -- yes, I'm seeing this in the debug version.
Am I _absolutely_ sure my data is right? Of course not. But I'm as sure as I can be. I guess my next step is to create a small, 4-vertex isolated example and see if I can get that to crash, too.
Am I _absolutely_ sure my data is right? Of course not. But I'm as sure as I can be. I guess my next step is to create a small, 4-vertex isolated example and see if I can get that to crash, too.
Actually, the behavior in debug mode is slightly different -- the call to Save() works the first time around (and seems to generate acceptable data), and crashes the second time.
Turns out I was calculating the "number of DWORDS" part of the DeclData template wrong, making the save object run off the end of the data I provided it for the template. Weird that they don't do any error checking internally...
Now, next question: why doesn't this mesh load into the DirectX Viewer when DeclData is present? (I'm building that tool from source to find out)
Now, next question: why doesn't this mesh load into the DirectX Viewer when DeclData is present? (I'm building that tool from source to find out)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement