Sign in to follow this  

Saving a STRING to an *.x file

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

Heyas: Saving out to an *.x file and all is smooth sailing except for the SkinWeights template object requires a STRING for the first variable. I tried passing in a buffer with: A. the string "joint1" without a NULL terminator; B. the string "joint1" with a NULL terminator; C. the string "joint1" with two NULL terminators; D. the string "joint1" padded with 10 bytes(== 16B); E. the string "joint1" padded with 26 bytes(== 32B); F. the string "joint1" padded with 58 bytes(== 64B); G. the address of the string "joint1"; All of the above recorded the following into the file and corrupted all templated objects that followed: SkinWeights { "join\253\««\253\««\253\««\253\««\356\îþ\356\îþ"; 0; ; ; 0.000000,563018672898048.000,0.000000,3697363374899095100, 0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,368934881474191030,0.000000, 0.000000,0.000000,0.000000,0.000000;; } * One point of interest is that it consistently contains the first four bytes. This made me reason that perhaps it might want an address. When I tried option 'G' I found that the program would crash if the pointer was out of scope. Anyhoo, ID3DXFileSaveData::AddDataObject() returns S_OK so I'm kinda at a loss. Any help would be much appreciated. ty

Share this post


Link to post
Share on other sites
The problem persists but I have new info:

If the string is less than 4 bytes in length it crashes on save.

Any help would be a huge benefit.

I have searched the msdn->directx newsgroups and no info relevant to the problem(nothing even about the api file saving interface at all) has been found.

Currently, I'm trying to locate an email from someone on the DirectX development team to either clarify the sdk documentation- which does not cover how to do this, or to find an alternative route to adding the template.

ty

Share this post


Link to post
Share on other sites
What methods are you using to read/write to your file? I have yet to do anything fancy with file IO yet, but I too need to learn how to store strings, because I will need this aspect for resource management in my game engine.
*Humbleness evaporates*
What I am going to attempt is using a string with a NULL terminator using the <fstream> class.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It sounds like you are using the version of the x file lib or dll that requires you to pass it a LPCSTR* not an LPCSTR.
I would suggest that you create a string cache while saving so that you can reserve your pointer to pointers, otherwise, depending on how you do your save calls the x file system could dereference invalid data.

PS this also explains why someone was having problems if the string was less than 4 character

Share this post


Link to post
Share on other sites
Unfortunately, as noted in the original post (option G) the address of a pointer crashes the app when ID3DXFileSaveObject::Save(void) is called.
Just as a test I created the string globally to see if that would stop the crash but it doesn't. It seems like it wants a pointer and the X-File template reference in the SDK requests a null-terminated string so in that regard the two conflict. Either way it doesn't work (even when the data type is global).

Since there are other reasons that it could crash I create an x-file that duplicates a working x-file but it still crashes. I have been unable to locate any further documentation in the SDK and the msdn.directx newsgroups. I have also been unsuccessful finding an email address of one of the DirectX developers, one of whom should certainly know if the problem lies somewhere else.

For the record I write all these other templates to the same file successfully:
- template AnimTicksPerSecond
- template Frame
- template Matrix4x4
- template FrameTransformMatrix
- template Vector
- template MeshFace
- template Mesh
- template MeshNormals
- template Coords2d
- template MeshTextureCoords
- template ColorRGBA
- template IndexedColor
- template MeshVertexColors
- template ColorRGB
- template Material
- template MeshMaterialList
- template VertexDuplicationIndices
- template XSkinMeshHeader
// template SkinWeights == this is the problem one
- template Animation
- template AnimationSet
- template FloatKeys
- template TimedFloatKeys
- template AnimationKey

If anyone has a solution I would love to hear from you.

TY in advance

Share this post


Link to post
Share on other sites

This topic is 4586 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.

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