Just before the release of the “Amnesia: Rebirth” game, the vendor “Fractional Games” opened the source code of the legendary “Amnesia: The Dark Descent” and its sequel “Amnesia: A Machine For Pigs”. Why not use the static analysis tool to see what dreadful mistakes are hidden in the inside of these cult horror games?

After seeing the news on Reddit that the source code of the games “Amnesia: The Dark Descent” and “Amnesia: A Machine for Pigs” was released, I couldn’t pass by and not check this code using PVS-Studio, and at the same time write an article about it. Especially since the new part of this game-series - “Amnesia: Rebirth” is released on the 20th of October (and at the moment of posting this article the game is already released).

“Amnesia: The Dark Descent” was released in 2010 and became a cult game in the survival horror genre. Frankly speaking, I have never been able to play through it, even a bit. The reason is that in horror games I play by one algorithm: install, run for five minutes, exit by “alt+f4” at the first creepy moment and delete the game. But I liked watching this game run through videos on YouTube.

1

In case someone is not familiar with PVS-Studio yet, this is a static analyzer that looks for errors and suspicious places in source code of programs.

I especially like delving into source code of games. So, if you are interested in what errors are made in games, you can read my previous articles.

After checking, it turned out that a large amount of code overlaps between “The Dark Descent” and “A Machine For Pigs”, and the reports for these two projects were very similar. So almost all the errors that I will cite further take place in both projects.

The better half of errors found by the analyzer in these projects was copy-paste errors. This explains the title of the article. The main reason for these errors is the “last line effect”.

Let’s get right to it.

_Code in this article may not be displayed correctly. Please, visit the original article - _https://viva64.com/en/b/0769/

Copy-paste errors

There were a lot of suspicious places that looked like inattentive copying. Some cases may be due to the internal logic of the game itself. Once they confused both the analyzer and me, at least a comment could be of use. After all, other developers may be as clueless as I am.

Fragment 1.

Let’s start with an example where the entire function consists of comparing method results and fields values of two objects aObjectDataA and aObjectDataB. I will cite the entire function for clarity. Try to see for yourself where the error was made in the function:

#game-development #c++ #cpp #cpp-vulnerabilities #bugs #amnesia #gaming-industry #gaming

Fixing Code Errors in Amnesia: The Dark Descent
1.15 GEEK