I’ve put traces in lots of places involving DirectSail and repairing the sails... none of them are being called.
On the other hand, this here...
itemsbox.c
Code:
if (!bFromCharacterScreen) { // KK
locCameraSleep(true);
SetTimeScale(0);
Log_SetActiveAction("Nothing");
BLIVisible(false);
SendMessage(&IActions,"ll",LI_SET_VISIBLE,false);
LayerFreeze("realize",bSeaActive && !ownDeckStarted() && !LAi_IsBoardingProcess());
LayerFreeze("execute",true);
bool bShow = ownDeckStarted();
if(!bShow) bShow = LAi_IsBoardingProcess();
LayerFreeze("sea_realize",!bSeaActive && bShow);
LayerFreeze("sea_execute",true);
}
Is
definitely a big part of the problem (the layer freezes, I think... look at the boarding clause and read on). Also this...
LogInterface.c
Code:
void BI_GetMsgIconRoot()
{
aref arTmp;
aref pARef[4];
int i,idx,cn;
ref mchr = GetMainCharacter();
idx = 0;
if(bSeaActive && !bAbordageStarted) // <----- [ This is being triggered during boarding! ]
{
for (i = 0; i < COMPANION_MAX; i++)
{
cn = GetCompanionIndex(mchr, i);
if(cn<0) {continue;}
Characters[cn].MessageIcons = true;
makearef(arTmp,Characters[cn].MessageIcons);
pARef[idx] = arTmp;
idx++;
}
SendMessage(&BattleInterface,"le", BI_MSG_SET_MSG_ICONS, &pARef);
}
else // <----- [ Therefore, this clause fails to execute if the above passes, and BOOM! ]
{
for (i = 0; i < OFFICER_MAX; i++)
{
cn = GetOfficersIndex(mchr, i);
if(cn<0) {continue;}
Characters[cn].MessageIcons = true;
makearef(arTmp,Characters[cn].MessageIcons);
pARef[idx] = arTmp;
idx++;
}
SendMessage(&objLandInterface,"le", MSG_BATTLE_LAND_SET_MSGICONS, &pARef);
}
}
I removed the first piece of code and I have had no crashes whatsoever since. The items box screen is also much more stable. I then removed the second piece of code whilst keeping the first commented and the same crash happened as I looted the next body (this was during the same boarding process and without reloading, I was fine looting everything until that point), but again none since putting it back so it is surely related.
Seemingly the second piece is
required for some reason, if it fails to execute then the crash happens. This is actually most likely what is happening because the first
if statement has a clause for boarding, but it still executes and I imagine this is because boarding is technically not active while the items box is open, so there is a good chance that the first clause will run (thus the
else statement obviously won’t).
If there isn’t much going on in the background then there may be a good chance that by the time the code comes to be executed the items box has properly closed and the check passes successfully because boarding is active again. If, however, there is a lot going on, particularly if there is a large sea battle taking place, the code will execute more slowly and at the time the above function is executed boarding is not active because the items box is still running - so it crashes. I have noticed that the crash occurs much more frequently during the larger battles; at first I thought it might be more to do with larger ships, but I now think it’s about processing speed.
It is also worth noting that after removing the first piece of code,
no sails appear in the backdrop after looting.
[example of this]
In conclusion, I believe that removing the first piece of code entirely, or possibly just the freeze entries, will fix the problem.
Actually, I have a serious problem now with my save game. I
think I have saved some of the changes I made during debugging, I really cannot see how removing code from the items box interface will cause a buffer overflow when docking into a port, but that’s what is happening now.
I reckon that is because I removed the code from loginterface.c and saved my game with those changes in place, so now it’s buggered. Nope, removing the freeze entries results in a bugger overflaw when docking to land, which is probably because icon statuses are not being reset properly.
User Rised Exception
C:\PROJECTS\DRIVE_V2\ENGINE\SOURCES\s_stack.cpp line 47
stack overflaw
When it crashes as I go to port, this is what I see at the very end of
compile.log from a trace...
Loot Crash Check: LogInterface.c - BI_GetMsgIconRoot()
Error.log is pretty much constantly throwing this up...
RUNTIME ERROR - file: battle_interface\loginterface.c; line: 533
invalid index 4 [size:4]
RUNTIME ERROR - file: battle_interface\loginterface.c; line: 533
process event stack error
This one, too...
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 5490
invalid index -1 [size:1000]
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 5490
invalid array index
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 5490
function 'SwapCabinChests' stack error
So I heartily recommend not messing about with the
BI_GetMsgIconRoot() function unless you
really know what you’re doing.
I guess that bit of code, and therefore the entire problem, has something to do with the ship and officer icons, whichever are to be shown at the given time. Obviously we don’t want the icons for companions showing during boarding, but maybe that’s actually what it’s trying to do?