Pyrdacor / Ambermoon

Resources for the incredible Amiga game Ambermoon
90 stars 8 forks source link

Investigating memory corruption at Illien #66

Open Hexaae opened 2 years ago

Hexaae commented 2 years ago

Exiting and entering Pelanis palace a couple of times after I fly with Giant Eagle to Illien can randomly cause strange gfx corruption like this: WinUAE Screenshot 2022 08 17 - 18 36 26 53 Sometimes the walls have the wrong tile with windows or plaques at every wall tile (???).

Still investigating a reproducible pattern...

Hexaae commented 2 years ago

EDIT: it seems the bug is reproducible entering/exiting Pelanis Palace/Illien multiple times, but only when using the WHDLoad slave 2.1

Pyrdacor commented 2 years ago

Then you might tell Wepl about it.

Hexaae commented 2 years ago

Reported in your WHD thread about Ambermoon 1.16 release...

Hexaae commented 2 years ago

Oh no, I had a strange issue also running 1.16 from WB: when sleeping I got msgs truncated like "Luca0150" instead of usual "Luca regained 150 magic points...", it could still be something in 1.1.6, after using Crystal Ball and recharging it with a spell to recharge items, and after a flight with the Eagle... can't find a simple pattern.... or maybe are just randomic issues due to the strange memory allocations by this game 😰

Pyrdacor commented 2 years ago

Can you please open a new issue for the text stuff?

Hexaae commented 2 years ago

Can you please open a new issue for the text stuff?

Let me investigate if I can reproduce it first, I'll also degrade emu speed etc.

Hexaae commented 2 years ago

ATM all I can say is that it's reproducible even with the original game 1.08 @Pyrdacor Please, can you test my savegame right outside of Illien? https://1drv.ms/u/s!ApMUGr0cuN39gpk9ECH-X5XOpUzZ-Q?e=zdO3dW Enter Illien (376,277) and look at the walls, enter/exit Pelanis Palce and/or exit/re-enter Illien from main gate multiple times, fly with Eagle to Godsbane (406,77), open the map when inside, exit and fly again to Illien and repeat... There's some sort of memory corruptions doing these actions, showing up as gfx glitches in Illien...

EDIT: it could be a problem introduced with unified exe (saved in my savegame probably). With 1.08 up to your 1.13 I can reproduce it only once ( = when entering first time in Illien). If I enter and exit Illien, from now on I can't reproduce it anymore with pre 1.14 versions from my checks... Using 1.16 I can reproduce it easily and often just entering Illien. Quite tricky to reproduce...

a1exh commented 2 years ago

V1.07 and below were the originals

Hexaae commented 2 years ago

Ok. Tested up to 1.13: my savegame above entering Illien twice solves the problem (sort of fixes by itself). With 1.14+ I can reproduce it every time.

Hexaae commented 2 years ago

Testing like crazy with all versions of the game, including 1.07... To me it seems an original game issue when entering Illien (376,277) after a trip with the Eagle to/from Castle Godsbane... Can you please try to reproduce the strange textures corruptions in Illien? It could be a (corrupt) savegame issue, but it sounds more like an original game bug at this point...

Repro steps:

Hexaae commented 2 years ago

Started a new game with 1.16 in the meanwhile and, using cheat with Netsrak's Staff, I got the flute to call the Giant Eagle to fly to the nearest town: I found NewLake and I noticed the same issue with (wrong) wall textures the first time I entered the gate! It seems a generic issue with 3D view in towns (not Spannenberg)... at least after a trip from another location.

Hexaae commented 1 year ago

Not a WHDLoad + 060 bug. It is an original game bug anyway, reproducible not only in Illien but also in other towns: after a long trip with the giant eagle it often occurs that the 3D city textures are incorrect. Not an 060 bug only: on WinUAE it happens also with 030 or 040 emu and also with the original game 1.07 or 1.08 launched from WB.

a1exh commented 1 year ago

Not that it matters but the last "original games" were 1.05 (DE) and 1.07 (Eng).

Bugs like this have been reported in the past but no-one ever posted real technical information that could be debugged.

e.g. Someone called st-th (who is now unreachable) posted some tiny tiny fractions of details.

http://eab.abime.net/showpost.php?p=531661&postcount=174

Hexaae commented 1 year ago

Ouch! So there are a lot of code bugs indeed... I love this game 😫

a1exh commented 1 year ago

Maybe. He never published his work. But some of his posts were extremely technical and led to bug fixes. Such as the herbs that never worked

http://eab.abime.net/showpost.php?p=891734&postcount=516

Pyrdacor commented 1 year ago

Maybe. He never published his work. But some of his posts were extremely technical and led to bug fixes. Such as the herbs that never worked

http://eab.abime.net/showpost.php?p=891734&postcount=516

I wish I had that information back then. I had to find those two bugs on my own. His item slot format description is not 100% correct but it's amazing to see how much knowledge about the game formats he had back then. It's a shame he never published it.

Today I guess I am aware of most bugs outside of the executables and know all the file formats in detail.

While I develop AA, I also found some more bugs in code and also decoded more bits and bytes of the file formats. But most of the bugs are minor or only lead to problems with additional content.

Just recently I found one. There is the spell Blink which is the only spell in the game which targets a free battle field. All other spells target monsters, players, items or nothing at all.

Such spells as Blink are stored in a list of pointers with some additional data. Something like "FieldTargetedSpells". Each entry starts with a long, where the first word is the spell school and the second word is the spell index. Then follows a pointer to the function which does the target selection routine. Then some code loops over the list and checks for a spell match. There is an end marker of 0xffff in the spell list. However the code which loops checks for 0xffffffff. So in case it couldn't find the spell for some reason, it would interpret the word 0xffff as the spell school and the next word (following data) as the spell index. This won't match either so it keeps going until it finds a 0xffffffff by luck. This shouldn't hurt, but still is a bug. The code is only used for the spells with that target type so only for Blink. And of course it will match instantly. If someone sets the target type of a spell to "field" and don't add the table entries correctly, the code may search through the whole memory in worst case and eventually even crash when reaching the memory boundary etc.

a1exh commented 1 year ago

I wish I had that information back then. I had to find those two bugs on my own.

Perhaps you discovered it before we started working together. This bug was in my spreadsheet in full detail including a link to that page . You even cross reference my spreadsheet entry (Unfixed 46) when you committed the change.

https://github.com/Pyrdacor/Ambermoon/commit/16f305b82f567df5b117d2c2aa123d4430ed41e8#diff-970d9d07a7064d52efff7f30b4c4f0bfdd786a721e4c1a1d7e83fa97e12805af

Pyrdacor commented 1 year ago

Yeah I knew the bug from your spreadsheet of course but most likely overlooked the link. ;)

Most of the times, the link only contained the description of the bug. I had no clue that someone really posted some details about the actual fix or even description of code errors. So maybe I just skipped that link which turned out to be a mistake now.

Hexaae commented 1 year ago

Just as a reminder and backlink to keep track of these threads: http://mantis.whdload.de/view.php?id=5716 https://imgsli.com/MTIxMzcy example of random corrupt textures when exiting outdoor...

Pyrdacor commented 1 year ago

Is the texture issue temporary? How long does it occur?

Hexaae commented 1 year ago

The pattern to reproduce ithis issue is:

Pyrdacor commented 1 year ago

I mean: is the texture changing while you move on the map or is it constant as long as you be on the same map?

Hexaae commented 1 year ago

Won't change till I re-enter/exit a door in the city. So it seems a problem in the texture loading when switching 2D->3D.

Pyrdacor commented 1 year ago

It looks more like some tiles have the wrong texture index so the map data is somewhat broken.

Hexaae commented 1 year ago

It happens randomly anyway and only following the instruction. If I enter/exit Illien city 10 times in a row it won't happen. If I move to another town flying there with the eagle, and then go back to Illien there is a higher chance to see the bug...

Pyrdacor commented 1 year ago

I hope my memory doesn't fool me here but in Ambermoon Advanced I think there were some issues as well. Also when changing some maps a few times. It was also a 3D map and you enter it from a "world map". You also enter Illien from the world map so this might be related.

World maps have a special flag bit set. I think the one flag is important, which controls how the 2D player is drawn. This changes a lot of stuff in the original code so there might be a specific bug when you move from a "world map" to a 3D map.

In the original code there is a "map type" variable. While the data only specifies 2D and 3D as a type, the game differentiates 4 types:

The main reason for splitting them is drawing I guess but also some changes in logic.

In our cases a change from the first one to the third one happens. And I think exactly that transition might have a flaw. But it will be hard to find it.

Pyrdacor commented 1 year ago

It would be interesting if the bug is persistent when it once happens. If it occurs, can you try to revert or change it by moving again to another town and back?

Moreover does it affect the whole town of Illien or only some parts?

From the screenshots it is in the lower part of the map. Would be interesting if it also happens in the top part as well.

Hexaae commented 1 year ago

It's random (but only after some patterns described above, or at least that is the easy way...) and not persistent: just entering shops/houses in the town and exiting multiple times usually fixes it... Whole town uses the same few textures so yes, when it happens is extended to the whole town...

Will check for the N vs S map towns but I don't think will change.,,

Pyrdacor commented 1 year ago

This sounds like wrong branching or memory access during map load then. As only some tiles are affected, I think it can't be no major memory error but is most likely a slightly incorrect index calculation.

Would be interesting to have a 1:1 comparison of changed tiles. For example: is very wall of type X after the bug of type Y? Or is it totally random? This would provide some clues in which data loading the error happens.

The data is 2 part. The lab data which stored the textures for walls and objects (and other stuff) and the map itself which references those walls and objects via index.

So either the index on the map is wrong or the texture index in the lab data (or just the wrong gfx is loaded into memory for that index).

Hexaae commented 1 year ago

It's always the same corrupt appearance for all instances (X -> Y), and identical everywhere is used. It usually happens for the walls. Rarely it happens for the floor as in the first screenshot, and usually it doesn't look "corrupt fastmem loaded into chip"-like but just a replacement with the wrong one (which looks "good", no corruption except you notice is not the correct texture...).

Following my repro-steps above, with my savegame everyone should be able to reproduce it.

Pyrdacor commented 1 year ago

I will have a closer look at it soon. Thanks for investigating.

Hexaae commented 1 year ago

News?

Hexaae commented 1 year ago

This should be easy to reproduce: enter Illien, and take notice of walls/columns. Now enter Pelanis Palace and exit. Look at how columns change to a different texture:

Illien-bug