Message 1 of 4
More Loading Woes - Saving/Loading a complex class

Not applicable
05-29-2008
10:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm at my wit's end. I've got a HelperObj that keeps a pointer to an instance of a class I've defined that contains a variety of information I use for export later on. I need to save/load the data from this instance along with the HelperObj.
Here's the kicker - if I make a scene with this sort of data then save it, reset, and load (without closing Max) - it works. Like a charm. BUT. If I save the scene then close Max, when I open Max and try to load the scene later it doesn't work. It loads something into the buffer, but when I cast it it's got bogus data (I think). If I try to call methods on the object after loading , I get memory access errors.
I experimented with trying to save it via AddAppDataChunk but had zero luck.
Here's a stripped down version of how I'm trying to accomplish this. "trigger" is the object I'm trying to save. It extends IRefTargMonitor.
IOResult CPhysicsEvent::Save(ISave *isave)
{
ULONG nb;
void *trigBuf = MAX_malloc(sizeof(trigger));
memcpy(trigBuf, trigger, sizeof(trigger));
isave->BeginChunk(TRIGGER_MAIN);
isave->BeginChunk(TRIGGER_CHUNK);
isave->Write(trigBuf,sizeof(trigger), &nb);
isave->EndChunk();
isave->EndChunk();
return IO_OK;
}
IOResult CPhysicsEvent::Load(ILoad *iload)
{
IOResult res = IO_OK;
ULONG nb;
void *trigBuf;
while (IO_OK==(res=iload->OpenChunk()))
{
switch(iload->CurChunkID())
{
case TRIGGER_MAIN:
while (IO_OK==(res=iload->OpenChunk()))
{
switch(iload->CurChunkID())
{
case TRIGGER_CHUNK:
trigBuf = malloc(iload->CurChunkLength());
res=iload->Read(trigBuf, iload->CurChunkLength(), &nb);
trigger = (CPhysicsTrigger*)trigBuf;
break;
}
iload->CloseChunk();
}
break;
}
iload->CloseChunk();
}
return IO_OK;
}
Anybody? Bueller? Bueller?
Here's the kicker - if I make a scene with this sort of data then save it, reset, and load (without closing Max) - it works. Like a charm. BUT. If I save the scene then close Max, when I open Max and try to load the scene later it doesn't work. It loads something into the buffer, but when I cast it it's got bogus data (I think). If I try to call methods on the object after loading , I get memory access errors.
I experimented with trying to save it via AddAppDataChunk but had zero luck.
Here's a stripped down version of how I'm trying to accomplish this. "trigger" is the object I'm trying to save. It extends IRefTargMonitor.
IOResult CPhysicsEvent::Save(ISave *isave)
{
ULONG nb;
void *trigBuf = MAX_malloc(sizeof(trigger));
memcpy(trigBuf, trigger, sizeof(trigger));
isave->BeginChunk(TRIGGER_MAIN);
isave->BeginChunk(TRIGGER_CHUNK);
isave->Write(trigBuf,sizeof(trigger), &nb);
isave->EndChunk();
isave->EndChunk();
return IO_OK;
}
IOResult CPhysicsEvent::Load(ILoad *iload)
{
IOResult res = IO_OK;
ULONG nb;
void *trigBuf;
while (IO_OK==(res=iload->OpenChunk()))
{
switch(iload->CurChunkID())
{
case TRIGGER_MAIN:
while (IO_OK==(res=iload->OpenChunk()))
{
switch(iload->CurChunkID())
{
case TRIGGER_CHUNK:
trigBuf = malloc(iload->CurChunkLength());
res=iload->Read(trigBuf, iload->CurChunkLength(), &nb);
trigger = (CPhysicsTrigger*)trigBuf;
break;
}
iload->CloseChunk();
}
break;
}
iload->CloseChunk();
}
return IO_OK;
}
Anybody? Bueller? Bueller?