Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Game engine code quality - is everything really...

Game engine code quality - is everything really that bad

The PVS-Studio team examines typical mistakes that can be encountered in the source code of game engines. The team offers ways to fix the mistakes so that they don't lead to errors (that are sometimes pretty funny) in the gameplay.
The presentation discusses how one can use static analysis to write higher quality code for computer games.
Want more on how a static analyzer can help in game development? Check out our related articles: https://pvs-studio.com/en/blog/posts/?tag=GameDev

PVS-Studio

July 06, 2023
Tweet

More Decks by PVS-Studio

Other Decks in Programming

Transcript

  1. ▪ Educate developers about common bugs ▪ Use tools to

    look for bugs automatically How to Avoid Bugs? 8
  2. ▪ Show typical error patterns ▪ Show how to use

    static code analysis correctly This Talk Aims To: 9
  3. PVS-Studio warns: V501 There are identical sub-expressions 'Position.Y >= Control.Center.Y

    — BoxSize.Y * 0.5f' to the left and to the right of the '&&' operator. Unreal Engine 4 (C++) 13
  4. PVS-Studio warns: V557 CWE-119 Array overrun is possible. The 'id'

    index is pointing beyond array bound. Amazon Lumberyard (C++) 16
  5. Unreal Engine 4 18 PVS-Studio warns: V522 Dereferencing of the

    null pointer 'LevelStreamingObject' might take place.
  6. PVS-Studio warns: V3063 A part of conditional expression is always

    true if it is evaluated: pageSize <= 1000. Unity (C#) 21
  7. PVS-Studio warns: V709 Suspicious comparison found: 'f0 == f1 ==

    m_fractureBodies.size()’. Remember that 'a == b == c’ is not equal to 'a == b && b == c'. Bullet –Red Dead Redemption’s Engine (C++) 23
  8. PVS-Studio warns: V502 Perhaps the '?:' operator works in a

    different way than it was expected. The '?:' operator has a lower priority than the '+' operator. CryEngine (C++) 26
  9. PVS-Studio warns: V502 Perhaps the '?:' operator works in a

    different way than it was expected. The '?:' operator has a lower priority than the '-' operator. Amazon Lumberyard (C++) 28
  10. PVS-Studio warns: V549 CWE-688 The first argument of 'memcmp' function

    is equal to the second argument. Amazon Lumberyard 33
  11. 35

  12. Do Trust the Engines 37 ▪ All these errors are

    already fixed ▪ Developers actively work on preventing new ones
  13. ▪ Unit tests ▪ Code review ▪ Functional, regression testing

    ▪ Dynamic analysis ▪ Static analysis Fight Bugs 38
  14. ▪id Software ▪Wargaming ▪Epic Games ▪Playrix ▪Warner Brothers Who Uses

    Static Analysis… 42 ▪Oculus ▪Codemasters ▪Rocksteady ▪ZeniMax Media ▪And others…
  15. Modern Static Analyzers 43 • PVS-Studio • ReSharper • Coverity

    • SonarQube • Klocwork • Clang Static Analyzer • IntelliJ IDEA • ... • A details list of static analyzers:
  16. ▪ In continuous integration systems (command-line tools, plugins for CI

    systems, monitoring systems) Analysis: How and Where 46
  17. ▪ Errors are fixed the moment they appear ▪ Many

    errors are fixed before testing and do not get to that stage ▪ Those that made it are detected at night ▪ The cost to fix bugs is almost zero Recap 48
  18. ▪ Of course! Static analysis does not find all bugs

    ▪ Static analysis – is an answer to the "how else can I improve code quality?" question ▪ An example of a great combination: static + dynamic analysis Should You Use Other Approaches? 50
  19. ▪ Everyone makes mistakes. Even experts. ▪ This is normal,

    you can use special tools to fix them. Conclusion 52
  20. Typical error patterns: ▪ Copy-pasting and the last line effect

    ▪ Using an incorrect address ▪ Errors in conditional operators ▪ Operation precedence issues ▪ Elusive typos Conclusion 53
  21. ▪ You can save a lot of resources, if you

    set up continuous static analysis Conclusion 54