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.

ID3DXFileSaveObject::Save() crashes
gadams00