• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fixed Boarding: Inconsistent Crashes Related to Looting

That includes the unmodded Beta 4 version of KB_routines.c again. o_O

I think I need your itemsbox.c file.

Do you know what this code does?
Code:
void BI_GetMsgIconRoot()
{
   aref arTmp;
   aref pARef[4];
   int i,idx,cn;
   ref mchr = GetMainCharacter();

   idx = 0;
    // This was being triggered during boarding, clause added to fix it...
   if(bSeaActive && !bAbordageStarted && !LAi_IsBoardingProcess())
   {
     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
   {
     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 wonder why the following variables and functions ALL exist:
LAi_boarding_process
bool LAi_IsBoardingProcess()
bAbordageStarted


Would it not be enough to have ONE of those??? :shock
 
And what do these lines do?
Code:
     LayerFreeze("realize",true);
     LayerFreeze("sea_realize",true);
     LayerFreeze("execute",true);
     LayerFreeze("sea_execute",true);
There used to be a fair bit of code in place to make that "false" depending on being at sea/in boarding.
I assume there must have been a reason for that. But I have no clue what all that is meant for. o_O
 
That includes the unmodded Beta 4 version of KB_routines.c again. o_O

I think I need your itemsbox.c file.
Do you have this now?

Do you know what this code does?
Code:
void BI_GetMsgIconRoot()
{
   aref arTmp;
   aref pARef[4];
   int i,idx,cn;
   ref mchr = GetMainCharacter();

   idx = 0;
    // This was being triggered during boarding, clause added to fix it...
   if(bSeaActive && !bAbordageStarted && !LAi_IsBoardingProcess())
   {
     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
   {
     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 think it is something to do with changing the officer and ship icons depending on which should be shown. I guess the problem with boarding is that technically the player is at sea, but is also using the land interface.

And what do these lines do?
Code:
     LayerFreeze("realize",true);
     LayerFreeze("sea_realize",true);
     LayerFreeze("execute",true);
     LayerFreeze("sea_execute",true);
There used to be a fair bit of code in place to make that "false" depending on being at sea/in boarding.
I assume there must have been a reason for that. But I have no clue what all that is meant for. o_O
So for whatever reason, when a box is opened it might be switching between the interfaces and getting confused as to which icons to show, and because it probably tries to display the ship icons (or simply cannot load the officers) then it goes wrong. One thing I did notice when messing with it was at one point the AI would stand on the spot, not moving around or attacking somebody right next to them but quite happily swinging their sword around as if to be idle. So I guess it just freezes the animations and also does something with showing the screen as well. I’m not explaining it well because I don’t really understand it, I just know that making those changes turns the background texture black in the items box and nothing appears in the backdrop of the sea afterwards. Most importantly, I have never had a crash during boarding after doing this.

I wonder why the following variables and functions ALL exist:
LAi_boarding_process
bool LAi_IsBoardingProcess()
bAbordageStarted


Would it not be enough to have ONE of those??? :shock
Well, for starters I am guessing there are two types of abordage: one is when the player is just moping around their own ship and the other is the actual boarding process. bAbordageStarted seems to be triggered just by going to deck, so it doesn’t explicitly confirm that we are boarding. As for the other two, they do look as if they mean and do the same thing.
 
Do you have this now?
I do. :yes

I just know that making those changes turns the background texture black in the items box and nothing appears in the backdrop of the sea afterwards. Most importantly, I have never had a crash during boarding after doing this.
Ah, it turns the background BLACK! So those changes do break the "transparent background" then.
That is rather unfortunate. Does it not look very ugly now then?

Well, for starters I am guessing there are two types of abordage: one is when the player is just moping around their own ship and the other is the actual boarding process. bAbordageStarted seems to be triggered just by going to deck, so it doesn’t explicitly confirm that we are boarding.
I think you're probably right there.

As for the other two, they do look as if they mean and do the same thing.
Definitely true.
 
I just know that making those changes turns the background texture black in the items box and nothing appears in the backdrop of the sea afterwards.
I've done some very quick tests and got to this:
Code:
  if (!bFromCharacterScreen) { // KK
     locCameraSleep(true);
     SetTimeScale(0.0);

     Log_SetActiveAction("Nothing");
     BLIVisible(false);
     SendMessage(&IActions,"ll",LI_SET_VISIBLE,false);
     
     LayerFreeze("realize",false); // PB: Try this even simpler
   }
With only that line, the transparent background does work. The other lines can seemingly be left out.
But I have no clue if this is too simple and might cause problems elsewhere.

Executing these three while at sea is FUN:
Code:
     LayerFreeze("sea_realize",false);
     LayerFreeze("execute",false);
     LayerFreeze("sea_execute",false);
Look what happened when I opened the itemsbox in my cabin:
upload_2016-5-15_20-52-27.png

Note that I have NO SHIP HULL! :rofl
 
Ah, it turns the background BLACK! So those changes do break the "transparent background" then.
That is rather unfortunate. Does it not look very ugly now then?
I prefer it, but that’s just my preference. Either way, if it fixes the bug then I don’t care.

I am so going to have to mess about with that some more! :woot
 
Executing these three while at sea is FUN:
Code:
     LayerFreeze("sea_realize",false);
     LayerFreeze("execute",false);
     LayerFreeze("sea_execute",false);
Fun it may be, but I just remembered that removing those lines entirely might be what caused the crashes when docking to port. Why that happens I don’t know, presumably there’s a problem resetting stuff... but either way something like that was preventing me from mooring.

Also, in the image are those ropes or wire-frame? o_O
 
I've done some very quick tests and got to this:
Code:
  if (!bFromCharacterScreen) { // KK
     locCameraSleep(true);
     SetTimeScale(0.0);

     Log_SetActiveAction("Nothing");
     BLIVisible(false);
     SendMessage(&IActions,"ll",LI_SET_VISIBLE,false);
    
     LayerFreeze("realize",false); // PB: Try this even simpler
   }
Is this what you’ve applied? I can’t open any corpses or boxes at all with this. :unsure
 
It worked in my game last time I checked.
Please try the EXE I posted today.
 
I’d be really grateful if people could make note of something for me...

Does the crash ever occur if the number of companions equals the number of officers (or there are none of either)?

I ask this because I have a feeling that this here in LogInterface.c is causing problems...
Code:
void BI_GetMsgIconRoot()
{
   aref arTmp;
   aref pARef[4]; // <---- this
   ...
Maybe not that bit in particular, but either way I believe the code is getting confused as to how many icons should be shown.

What I’m thinking is that when the interface switches between land and sea, and I guess that’s what happens while looting during boarding, then this code switches the icons (not that we see the ship icons in this case, but maybe they are technically looked at). I’m confident that there is a conflict here, and now I am assuming that it is to do with the number of icons - if they differ then it can go very wrong.

That is why I need to know if this crash ever happens if the number of companions and officers are equal.
 
Last edited:
For me, the crash happens after I've boarded, cleared at least one deck, then looted corpses/chests or exchanged equipment with an officer. Sometimes while walking around the deck the game then crashes, or if I make it to the next deck then there are random sails or ropes visible and the game may crash soon after. It certainly doesn't happen when the interface changes from sea to land - by the time the crash happens, the interface has already switched successfully.

The crash is not consistent in that usually I can board an enemy ship, loot everything in sight, and not have a crash, which is why I never have to buy medical supplies - they're the single most common thing to find in ships' chests. It is consistent in that I usually save game just before starting a battle, and if the game crashes and I reload the save game then it will probably crash again even though the enemy force is different (I tend to move around on world map, save game just before switching to sailing mode for a battle, then reload if the battle ended badly). After a few such attempts I re-run the battle without looting anything and it does not crash. Basically, if it's going to crash then it's always going to crash, but most times it does not crash.
 
For me, the crash happens after I've boarded, cleared at least one deck, then looted corpses/chests or exchanged equipment with an officer. Sometimes while walking around the deck the game then crashes, or if I make it to the next deck then there are random sails or ropes visible and the game may crash soon after.
That does fit with @Mere_Mortal's observations and fixes as well.

My preferred fix is the one quoted in post #114.
That is also the one included in here: Mod Release - Build 14 Beta 4.1 WIP | PiratesAhoy!

However, it is very important that this is tested to check if my simplified version indeed works.
So if you could implement that in your own game, I'd much appreciate it. :doff
 
I don’t particularly understand what is happening when an items box is active, but my feeling is that there is a crucial difference between the interface states. Having said that, and I’ve pointed out that there might be confusion as to whether the land or sea interface should be used, I’m not so sure that’s actually the case - I assume the land interface is always being used regardless. I mean, in the case of boarding I guess it’s a bit like being at the port - the sea is active, and so is the land interface.

I think it’s more about boarding not being active at all while looting, so when it comes to refreshing the icons there may be an attempt to load the companion icons, which fails and thus causes a crash (or it does kinda load them and that messes things up).

I am fairly confident that half of the problem is related to the speed at which the code is being executed. This crash would hardly happen (in fact, it never happens now so I’ve almost forgotten how it goes) if there were just a few ships in the area - but it would pretty much be inevitable in the case of a large battle. When an items box is closed the officer icons have to be refreshed, and that’s where the BI_GetMsgIconRoot() function comes in - the first check tests whether or not boarding is active, and if the game is processing too slowly then maybe this check is executed before the items box interface has properly closed and therefore boarding is not active - so the first check passes and the second one never gets looked at. I know for certain that the first check does run during boarding because I’ve traced it, and this should not be happening.

Now when it comes to the layer freeze changes I made, I guess one of two things is happening there. Either the boarding state is being maintained or because there is less going on while the items box is open, since there is neither a background on the items screen and nor funky ship sails in the backdrop, then the code might be executing more efficiently and thus by the time the check is done boarding is active again (so the crash could still happen, but it is much less likely).
 
Last edited:
Back
Top