Arctic Anomaly

Toupie

Chieftain
Joined
Sep 10, 2013
Messages
29
This is when you get this kind of stuff:
Spoiler :


EDIT:
This is how the anomaly appears on the "see again your game" screen
Spoiler :

(I customized the civs colors) :)


Already partly discussed here, its origin seems quite mysterious, although it may be elucidated now.

For a while I thought it was when an unit would mess with the date changing line by standing there for too long. You then got a scrambled screen.

As discovered by Dark Panda, this actually linked to the score screen. Specifically, I've come to the conclusion it is directly linked to the number of Wonders which appear in the score screen. If the Wonders icons need to be cropped to be displayed, your MAP file is pretty screwed.

So I played a game using a minima the score screen but there's one problem: when you win by Space Colonization, the score screen is automatically displayed, screwing the MAP file. Which makes continuing the game much less fun. Plus this glitch limit your score, as you theorically cannot get all the Wonders without screwing your MAP file.

So here are my questions:

1) Is there any mean to prevent the automatic displaying of the score screen ?
2) How many Wonders can one build without this glitch appearing ?
3) Does a simple patch for this bug exist ?
4) By the way, i'd like some precisions about the Date change line. Where is it exactly located ? Is it solely a 1-tile wide vertical line ?

I'm using the French version of 474.05
 
Question, is it possible (and/or easy) to not have the pictures for the wonders appear in the score screen? If so, would this solve the arctic issue?
 
1) Is there any mean to prevent the automatic displaying of the score screen ?
2) How many Wonders can one build without this glitch appearing ?
3) Does a simple patch for this bug exist ?
4) By the way, i'd like some precisions about the Date change line. Where is it exactly located ? Is it solely a 1-tile wide vertical line ?

Question, is it possible (and/or easy) to not have the pictures for the wonders appear in the score screen? If so, would this solve the arctic issue?

Many questions from both of you!
While something can most certainly be done to fix this issue, the hard part is to actually identify the exact issue, e.g. find a clear situation that triggers this bug, and provide the corresponding savegame.

If anyone has this in their archives, I'd be very interested :)
 
and provide the corresponding savegame.

If anyone has this in their archives, I'd be very interested :)
Okay, so here are two savegames from the same game.
First is just before buying the last Russian city. The second one is after spaceship victory (I decided to not buy the last city). The MAP file got corrupted after the final score screen was displayed.
 

Attachments

  • CIVIL1.SVE
    37 KB · Views: 75
  • CIVIL1.MAP
    14.8 KB · Views: 67
  • CIVIL3.SVE
    37 KB · Views: 80
  • CIVIL3.MAP
    15 KB · Views: 57
Okay, so here are two savegames from the same game.
First is just before buying the last Russian city. The second one is after spaceship victory (I decided to not buy the last city). The MAP file got corrupted after the final score screen was displayed.

Your first gamesave is the ideal test case to trigger the issue:
  • At first the map is fine:
  • Then we show the score by pressing F9:
  • Then the map is screwed:

I'll roll my sleeves up and try to get to the bottom of it... Merci! :)
 

Attachments

  • civ_867.png
    civ_867.png
    5.7 KB · Views: 768
  • civ_866.png
    civ_866.png
    7.3 KB · Views: 764
  • civ_865.png
    civ_865.png
    5 KB · Views: 771
Finally I started to investigate this issue in details.

As discovered before, the problem appears when CIV renders Wonders icons to the Score screen.

The root bug is that CIV does not verify the vertical position (Y coordinate) before writing the sprite to the screen.

In memory, the MAP image (that contains MAP data), as well as cached icons for buildings and wonders) and the SCREEN image (where the Score graphics are being rendered when pressing F9) are placed next to each other. More precisely, the SCREEN image starts at 0x424F0, while the MAP image starts at 0x51F00.

Since 1 image is 320x200, using 1 byte per pixel, the total size of 1 image is 64000 bytes, or 0xFA00.
We can see that the MAP image is almost right after the SCREEN image because 0x424F0 + 0xFA00 = 0x51EF0, which is 10 bytes away from the MAP image.

So what happens is that CIV is writing the Wonder icon sprite to the SCREEN image too low, and continues to write pixels even though they are outside the SCREEN image... Those pixels are then written to the MAP image, which gets screwed as expected.

This also explains why this bug happens when a combination of very large population + many wonders occurs: too may things to display on the Score screen.

Now for the fix: definitely not straightforward, unless completely deactivating the rendering of Wonder icons in Score screen...

TO BE CONTINUED...
 
Found it. Now, are the icons supposed to appear when you go to the score screen? They still are in my version...
 
Hmm, maybe it's a conflict with one of the other patches then. I started a new game and it doesn't work on mine. I have attached a print screen for you.
 

Attachments

  • wonder.png
    wonder.png
    286.6 KB · Views: 107
Double-check that you modified the sequence which is at offset 0x4718C, because there are multiple occurences of this sequence in the code...

Actually, this sequence codes for:
Code:
call gfx_copyScreenArea [I][COLOR="DimGray"]; function to copy part of an image to another image[/COLOR][/I]
add sp, 6

Obviously, this call occurs many times in the code, because there are many places where CIV wants to copy part of an image to another image - basically all sprite rendering calls this function...

But you only want to modify the call that is done within the SCORE screen subroutine, for displaying Wonder icons...
For better matching look for the longer sequence: 9A 41 70 91 0C 83 C4 06 B8 0B 00. There should be only one.
 
I must have done the wrong one then.... at least I have multiple backups to go back to. I will double check....
 
Good to go, would you mind putting the longer sequence in your previous post? That way no one else will make the same mistake.... :D
 
The root cause for this issues is actually in the graphics code, inside MGRAPHIC.EXE.

Long story short, the problem occurs in the graphics function "CopyImageArea" (my name), which copies a rectangle area (src_x_left, src_y_top, width, height) from an image (SRCIMG) to a specific location (dest_x_left, dest_y_top) in another image (DESTIMG).

Basically, images are stored as linear byte arrays, 1 byte per pixel, row after row.

So copying part of an image into another image is just a matter of making N (=height) copies of M (=width) consecutive bytes (row pixels) from one place (the source image) to another place (the target image).

The problem is illustrated in the MGRAPHIC.EXE disassembly screenshot hereunder: this function applies the logic above almost blindly, and does not perform any boundary check on the destination where data is written. Thus, if the target area is partly off-screen, the routine gladly overwrites bytes located right after the destination image data range.

As discussed before, the CIV memory is laid out as [SCREEN IMAGE DATA]-[MAP IMAGE DATA], so when writing the Wonder icons to the SCREEN IMAGE DATA, the sprites crosses the bottom image boundary and gets written at the top of the [MAP IMAGE DATA], where the Geography is stored.

Hence the arctic anomaly.

Bugfix anyone?

 

Attachments

  • arctic_anomaly_mgraphic_disasm.png
    arctic_anomaly_mgraphic_disasm.png
    75.1 KB · Views: 671
Top Bottom