Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigating memory corruption at Illien #66

Open
Hexaae opened this issue Aug 17, 2022 · 34 comments
Open

Investigating memory corruption at Illien #66

Hexaae opened this issue Aug 17, 2022 · 34 comments
Assignees
Labels
bug Something isn't working game Issues related to the Amiga game

Comments

@Hexaae
Copy link

Hexaae commented Aug 17, 2022

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
Copy link
Author

Hexaae commented Aug 17, 2022

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

@Pyrdacor
Copy link
Owner

Then you might tell Wepl about it.

@Hexaae
Copy link
Author

Hexaae commented Aug 17, 2022

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

@Hexaae
Copy link
Author

Hexaae commented Aug 17, 2022

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
Copy link
Owner

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

@Hexaae
Copy link
Author

Hexaae commented Aug 18, 2022

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
Copy link
Author

Hexaae commented Aug 21, 2022

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
Copy link

a1exh commented Aug 21, 2022

V1.07 and below were the originals

@Hexaae
Copy link
Author

Hexaae commented Aug 21, 2022

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
Copy link
Author

Hexaae commented Aug 24, 2022

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:

  • fly using giant Eagle from Illien (376,277) <--> Castle Godsbane (406,77) multiple times
  • while doing so, every time you go to Godsbane enter Castle Godsbane and open the map then exit and call the Eagle...
  • when you fly to Illien enter the gate and go stright to the Pelanis Palace then exit the palace, always looking at the walls textures... You can also try to enter/exit Pelanis Palace multiple times...
  • repeat until you notice something strange (usually a trip from Castle Godsbane to Illien should be enough to notice strange walls textures when you re-enter Illien's gate).

@Hexaae
Copy link
Author

Hexaae commented Aug 24, 2022

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
Copy link
Author

Hexaae commented Sep 16, 2022

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
Copy link

a1exh commented Sep 16, 2022

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
Copy link
Author

Hexaae commented Sep 16, 2022

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

@a1exh
Copy link

a1exh commented Sep 17, 2022

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
Copy link
Owner

Pyrdacor commented Sep 17, 2022

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
Copy link

a1exh commented Sep 18, 2022

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.

16f305b#diff-970d9d07a7064d52efff7f30b4c4f0bfdd786a721e4c1a1d7e83fa97e12805af

@Pyrdacor
Copy link
Owner

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
Copy link
Author

Hexaae commented Oct 30, 2022

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
Copy link
Owner

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

@Hexaae
Copy link
Author

Hexaae commented Oct 31, 2022

The pattern to reproduce ithis issue is:

  • call the eagle and fly to castle Godsbane. Enter the castle and open the map.
  • exit the castle and fly to Illien or another big city. Enter the city and enter f.e. Pelanis palace. Then exit the palace.
    At this point you can usually notice strange texture corruption in the city outdoor...

@Pyrdacor
Copy link
Owner

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
Copy link
Author

Hexaae commented Oct 31, 2022

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
Copy link
Owner

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

@Hexaae
Copy link
Author

Hexaae commented Oct 31, 2022

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
Copy link
Owner

Pyrdacor commented Nov 1, 2022

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:

  • World map (2D)
  • Other 2D map
  • City (3D with sky)
  • 3D dungeon

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
Copy link
Owner

Pyrdacor commented Nov 1, 2022

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
Copy link
Author

Hexaae commented Nov 1, 2022

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
Copy link
Owner

Pyrdacor commented Nov 1, 2022

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
Copy link
Author

Hexaae commented Nov 1, 2022

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
Copy link
Owner

Pyrdacor commented Nov 2, 2022

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

@Pyrdacor Pyrdacor self-assigned this Nov 2, 2022
@Pyrdacor Pyrdacor added bug Something isn't working game Issues related to the Amiga game labels Nov 2, 2022
@Hexaae
Copy link
Author

Hexaae commented Dec 11, 2022

News?

@Hexaae
Copy link
Author

Hexaae commented Jun 5, 2023

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

@Hexaae
Copy link
Author

Hexaae commented Mar 3, 2025

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

News about this old bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working game Issues related to the Amiga game
Projects
None yet
Development

No branches or pull requests

3 participants