The title is somewhat simplified, the problem somewhat strange. Here's how it goes:
I wrote an autosave function for IMS that would save the state before module integration. When I start building a new vessel, the first time I integrate a module it executes flawlessly. The second time it executes it causes an access violation in some unrelated code a bit later on. The function seems to execute without trouble otherwise. If I reload the scenario that has been saved by it, and integrate, I get the violation immediately, not only after the second time.
First I thought I'm writing out of bounds in my chararrays, but that's not the case. If I comment out oapiWriteScenario and still execute all the rest in the function, there is no problem.
The next thought was that the violation might be caused somewhere in the save state of my vessel, but that's also a negative. If I save the state just before using the scenario editor, I don't get an access violation. If I execute my autosave function after that, here it is.
I have no idea what exactly the problem could be here. It must have something to do with what I do in the function, but commenting out the oapiSaveScenario call makes the problem go away.
However, commenting out all the rest and passing a fixed filename to oapiWriteScenario also makes the problem go away, so it seems the two of us are working hand in hand on this little crash...
Here's the function:
Note: finalise is always false at the moment.
I wrote an autosave function for IMS that would save the state before module integration. When I start building a new vessel, the first time I integrate a module it executes flawlessly. The second time it executes it causes an access violation in some unrelated code a bit later on. The function seems to execute without trouble otherwise. If I reload the scenario that has been saved by it, and integrate, I get the violation immediately, not only after the second time.
First I thought I'm writing out of bounds in my chararrays, but that's not the case. If I comment out oapiWriteScenario and still execute all the rest in the function, there is no problem.
The next thought was that the violation might be caused somewhere in the save state of my vessel, but that's also a negative. If I save the state just before using the scenario editor, I don't get an access violation. If I execute my autosave function after that, here it is.
I have no idea what exactly the problem could be here. It must have something to do with what I do in the function, but commenting out the oapiSaveScenario call makes the problem go away.
However, commenting out all the rest and passing a fixed filename to oapiWriteScenario also makes the problem go away, so it seems the two of us are working hand in hand on this little crash...
Here's the function:
Code:
void IMS::AutoSave(bool finalise)
//makes an autosave of the scenario in an appropriate subfolder. Saves go from 1 through 9,
//then start overwriting themselves. Every 10. save is permanent.
{
char flname[200];
char desc[200];
string createPath = "Scenarios/IMS/";
char VesName[50];
sprintf(VesName, GetName());
createPath += VesName;
CreateDirectory(createPath.data(), NULL);
int TotModNum = modules.size() + 1; //because CM isn't included in modules
if (finalise)
{
sprintf(flname, "IMS/%s/%s_before_finalisation", VesName, VesName); //last save before finalisation gets own filename
}
else
{
int saveIndex = TotModNum % 10; //autosaves will be incremental from 1 to 9. Every tenth autosave will not get overwritten, while the increments in between will be
if (saveIndex == 0)
{
saveIndex = TotModNum /10;
}
sprintf(flname, "IMS/%s/%s_%d", VesName, VesName, saveIndex);
}
sprintf(desc, "MJD %lf, %d modules installed", (float)(oapiGetSimMJD()), TotModNum);
oapiSaveScenario(flname, desc);
}
Note: finalise is always false at the moment.
Last edited: