1. Name looks suspicious - Line 5 in the deserializer implies that it's a std::string, but Line 9 seems to indicate that it is a char[] - if it's really a std::string, you need to read() it into a character array first and then copy it into Name - otherwise, the std::string will have no idea how much space to allocate - it might be running past that section on luck (or bad luck, depending on how you look at it) atm
2. you are right about that vector block - it's a mess on both sides
2a. first not that even though a vector not officially sanctioned to be one chunk of contiguous memory, so many developers have assumed so and so many compiler writers have implemented as such that it's become the the de facto standard - that means you can write the number of elements, as you have done, and then write, instead, the entire block of the array by doing the something like this:
1 2 3
|
sizebuf = (UINT)sizeof(Materials[0]) * Materials.size();
_pFile->write((char*)&sizebuf, sizeof(UINT));
_pFile->write((char*)&(Materials[0]), sizebuf);
|
in other words, you do not need to iterate with a loop - of course, this is assuming that Materials is struct-like without weird pointers or strings in it!
2b. now, reading it out into a vector will be a little tricky, but also doable - think about it a little before trying it out - you want to think of it in terms of a Materials[] (contiguous array) first and then adapt it to a vector
3. same applies to your array Parts
4. I highly recommend that you comment out most of your serialize and deserialize code and test it a little bit at a time, adding bits at a time simultaneously on both ends - that's almost the only way you can ensure that all the parts work as you expect