Extremely odd Serialization error
This one has me stumped big time. I'm in the process of serializing all my dialogs and objects to disk and everything was going well until.....attempting to serialize the layers dialog information to disk.
I have a layers dialog that tells you how many tile maps you have in the final map. The actual list box has nothing to do with the class that manages the maps except that when you click add, it tells the map manager to add a map. The map size is determined by the options dialog data members which is a member of the main frame window.
Now when I only have 2 layers, the movement layer (always layer 0) and one draw layer (layer 1) it works fine. When you add a layer and then save it all goes to hell.
For some reason this code is not working right when more than 2 layers are available.
Now get this. Even when you add a map and save, the dialog box in the storing section prints out the correct value. When you then attempt to load the same file, the temp variable in the loading section prints out the horizontal size of the map, which happens to be the first piece of data in the entire project file.
void LayersDlg::Serialize(CArchive &ar)
// storing code
ar << size;
// loading code
ar >> temp;
text.Format("NumLayers in file: %u",temp);
for (DWORD i=0;i<temp;i++)
if (i>1) AddLayer();
I cannot for the life of me see where the CArchive is being rest to the front of the file.
And it is not writing the correct value. I can start from scratch with a fresh compile and the number does not change. So why is the storing section writing a totally different number than is being displayed and why does it only work with 2 layers?
Seems I may have a serious memory problem here.
Anyone please help.
Add button code:
Add layer code:
CMainFrame *ptrFrame=(CMainFrame *)AfxGetMainWnd();
CZeldaEditorDoc *ptrDoc=(CZeldaEditorDoc *)ptrFrame->GetActiveDocument();
This can be called from anywhere, even in setup. This is why the count is checked. The SetupProject() function in the main window calls this to add layers for the user. By default when the project starts, it has a move layer and one draw layer.
And the map manager add code:
LayerData *data=new LayerData;
//test.Format("Vector size: %d",LayerInfo.size());
Map create and clear code:
CMap *map=new CMap();
Sorry so long but this editor is really really big and a lot of the classes, windows, objects, and functionality of it is extremely reliant on other object, classes, windows, etc.
bool Create(DWORD dwWidth,DWORD dwHeight)
//return non-zero on failure
if (!m_pMap) return true;
void Clear(DWORD value=0)