Unit not at its plot

Leoreth

Blue Period
Moderator
Joined
Aug 23, 2009
Messages
37,059
Location
東京藝術大学
I have recently encountered a strange issue that is hard to reproduce, and I have no idea what could have caused it in the first place. Sometimes I will find units whose positional coordinates are not actually at the plot that contains them. It looks like this in the game:

Spoiler :
Civ4ScreenShot0402.JPG

As you can see, the unit standard is at the tile but the unit art is not displayed.

When I end turn, it triggers the following assertion:
Spoiler :
Debug1.png
Debug2.png



When I continue from this breaking point, the game crashes when it encounters a null pointer:
Spoiler :
Debug3.png

The game also crashes when trying to delete the unit in world builder. I can clean the null entry from the plot unit queue (I have done so before) but that doesn't answer the question of how this weird state even comes about. A cursory glance at the code suggests that methods usually make sure to keep units and plots in sync. I'm kind of at a loss about both why a unit's plot would not match its coordinates and why it would become null shortly after that.

Any ideas?
 
This is indeed weird. CvPlot has a list of units on the plot (for performance and network sync reasons). Each unit stores x,y for where it is located. In your case a plot believes to contain a unit where the unit believes it is elsewhere.

The question is how did this happen. If a unit is moved with CvUnit::setXY() (which includes functions calling it like CvUnit::move()), then this shouldn't happen. Somehow a unit changed x,y values without using setXY(). I have no good idea to why this could happen.

Look around in the unit data. Is there something odd like is it a dying unit or anything else, which might stand out? Also do you have a modded feature to teleport units?

What happens if you change the x,y of the unit to match the plot?
 
I have been thinking if I have modded in new functions that might move units, but the most I am doing as far as I can remember is moving units around using setXY().

I'll take another look into the unit data and see what happens when I set the unit to match its plot. I guess additional debug statements that validate that unit coordinates and plots match every time one of these is modified could also help catch this.
 
Top Bottom