SlideShare a Scribd company logo
inequation.org
inequation.org

Gamedev-grade debugging
Leszek Godlewski
Freelance Programmer
lg@inequation.org

SpreadIT 2013 · October 19th, 2013
SpreadIT 2013 · October 19th, 2013
Code snippets
Code snippets

All code used in the talk available online:
github.com/inequation/ggd

2
2

inequation.org
inequation.org
Agenda
Agenda

●

Who is this guy?

●

Why the talk?

●

A taste of gamedev debugging

●

Right tool for the job

●

Noise filtering

●

Memory corruption

●

Questions

3
3

inequation.org
inequation.org
Who is this guy?
Who is this guy?

Freelance Programmer
●
●

●

(Sep 2013 – onwards)
inequation.org
Painkiller Hell & Damnation
Linux port finalization (2013)
Unannounced project

Generalist Programmer,
The Farm 51
●
●

●

●

4
4

(Mar 2010 – Aug 2013)
thefarm51.com
Painkiller Hell & Damnation
(2012-2013; Win/Linux/X360/PS3)
Deadfall Adventures
(2011-2013; Win/X360)
A few unannounced projects
inequation.org
inequation.org
Agenda
Agenda

●

Who is this guy?

●

Why the talk?

●

A taste of gamedev debugging

●

Right tool for the job

●

Noise filtering

●

Memory corruption

●

Questions

5
5

inequation.org
inequation.org
Why the talk?
Why the talk?

Because THIS has happened to me:

http://imgur.com/yBa1OGm

6
6

inequation.org
inequation.org
Why the talk?
Why the talk?

Intern: I've read* at all the code and
still don't see the bug.
Me:

So just debug it!

*read, as in „stare without actually running it”

7
7

inequation.org
inequation.org
Why the talk?
Why the talk?

Intern:

© DreamWorks

8
8

http://imgur.com/yBa1OGm

inequation.org
inequation.org
Why the talk?
Why the talk?

The three uses of debugging
●

Bug hunting (doh)

●
●

9
9

inequation.org
inequation.org
Why the talk?
Why the talk?

The three uses of debugging
Bug hunting (doh)
● Reverse engineering
●

●

10
10

inequation.org
inequation.org
Why the talk?
Why the talk?

The three uses of debugging
Bug hunting (doh)
● Reverse engineering
● Testing a new feature
●

11
11

inequation.org
inequation.org
Agenda
Agenda

●

Who is this guy?

●

Why the talk?

●

A taste of gamedev debugging

●

Right tool for the job

●

Noise filtering

●

Memory corruption

●

Questions

12
12

inequation.org
inequation.org
A taste of gamedev debugging
A taste of gamedev debugging

Code: 01-taste

13
13

inequation.org
inequation.org
A taste of gamedev debugging
A taste of gamedev debugging

Can you spot the culprit?
// class declaration
class Crasher extends ActorComponent;
var int DummyArray[1024];
// in ammo consumption code
Crash = new class'Crasher';
Comp = new class'ActorComponent' (Crash);

14
14

inequation.org
inequation.org
Agenda
Agenda

●

Who is this guy?

●

Why the talk?

●

A taste of gamedev debugging

●

Right tool for the job

●

Noise filtering

●

Memory corruption

●

Questions

15
15

inequation.org
inequation.org
Right tool for the job
Right tool for the job

„Fix a bug for an intern, they will get stuck on
the next one.
Teach them debugging, they will fix most bugs
they encounter on their own.”

– Paulo Coelho

16
16

inequation.org
inequation.org
Right tool for the job
Right tool for the job

Debugging tools are essential to this
profession!
When joining a new team or starting development for a
new platform, demand debugging tools
● Ask senior teammates
● If they don't know, there must be documentation
● Be proactive!
● Don't give up until the debugger is fully working
● No tools? Roll your own!
● You are a coder after all, right?
●

17
17

inequation.org
inequation.org
Right tool for the job
Right tool for the job

Not all bugs are in the code
Animation graphs
● Flow graphs/visual scripts
● Post-process effects
●

Still need a way to debug them

18
18

inequation.org
inequation.org
Right tool for the job
Right tool for the job

Code: 02-tools

19
19

inequation.org
inequation.org
Agenda
Agenda

●

Who is this guy?

●

Why the talk?

●

A taste of gamedev debugging

●

Right tool for the job

●

Noise filtering

●

Memory corruption

●

Questions

20
20

inequation.org
inequation.org
Noise filtering
Noise filtering

There are parts of code executed thousands
of times each frame
Object transformation
● Collision detection
●

Also rarer, but still impractical to track
Setting materials on objects
● Attaching and detaching of components
●

21
21

inequation.org
inequation.org
Noise filtering
Noise filtering
Code: 03-material
04-ragdoll
05-assert

22
22

inequation.org
inequation.org
Agenda
Agenda

●

Who is this guy?

●

Why the talk?

●

A taste of gamedev debugging

●

Right tool for the job

●

Noise filtering

●

Memory corruption

●

Questions

23
23

inequation.org
inequation.org
Memory corruption
Memory corruption

Look closely:
// class declaration
class Crasher extends ActorComponent;
var int DummyArray[1024];
// in ammo consumption code
Crash = new class'Crasher';
Comp = new class'ActorComponent' (Crash);

24
24

inequation.org
inequation.org
Memory corruption
Memory corruption

Look closely:
// class declaration
class Crasher extends ActorComponent;
var int DummyArray[1024];
// in ammo consumption code
Crash = new class'Crasher';
Comp = new class'ActorComponent' (Crash);

25
25

inequation.org
inequation.org
Memory corruption
Memory corruption

●

UnrealScript object construction syntax
new <class> [(<template object>)];

●

But:
sizeof(Crasher) > sizeof(ActorComponent)

●

Verdict:

26
26

inequation.org
inequation.org
Memory corruption
Memory corruption

●

UnrealScript object construction syntax
new <class> [(<template object>)];

●

But:
sizeof(Crasher) > sizeof(ActorComponent)

●

Verdict:

27
27

BUFFER OVERFLOW!

inequation.org
inequation.org
Memory corruption
Memory corruption

But this can happen anywhere! How to find it?
Use a memory fence
● Many related techniques
● Allocate additional space in front and behind actual
allocations
● Then protect them from writing...
● Or write a byte pattern and periodically assert its
consistency
● Also it's useful to log stack traces
● Memory and CPU overhead!
● Use a debug memory allocator (dmalloc)
● Use a memory debugger (Valgrind)
● Use a memory analysis tool (HeapInspector)
●

28
28

inequation.org
inequation.org
Memory corruption
Memory corruption

Memory fences

malloc

Regular allocation

29
29

malloc

Fenced allocation

inequation.org
inequation.org
Takeaway
Takeaway

You can't be an effective programmer without
debugging tools
● If there are no tools, make some
● Noise filtering techniques save your time
● Time is not only money – nerves are just as important!
● Know your machine (physical or virtual) down to the
metal
● Instruction opcodes, registers etc. come in handy
● Tons of resources available
● Random crashes and/or content glitches may indicate
memory corruption
● Memory corruption can be defeated!
●

30
30

inequation.org
inequation.org
inequation.org
inequation.org

Questions?
lg@inequation.org

SpreadIT 2013 · October 19th, 2013
SpreadIT 2013 · October 19th, 2013
inequation.org
inequation.org

Thank you!
inequation.org
lg@inequation.org
@TheIneQuation

SpreadIT 2013 · October 19th, 2013
SpreadIT 2013 · October 19th, 2013

More Related Content

PDF
Groovy android
PDF
Spring-batch Groovy y Gradle
PDF
Jedi knight
PDF
Passing the Joel Test in the PHP World (phpbnl10)
PDF
Android Performance Tools
PDF
Golang from Scala developer’s perspective
PPTX
Geb+spock: let your functional tests live long and prosper
PDF
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
Groovy android
Spring-batch Groovy y Gradle
Jedi knight
Passing the Joel Test in the PHP World (phpbnl10)
Android Performance Tools
Golang from Scala developer’s perspective
Geb+spock: let your functional tests live long and prosper
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)

What's hot (8)

PDF
Why you should care about Go (Golang)
PDF
Idiomatic R for Rosetta Code (2013)
PPTX
Golang - Overview of Go (golang) Language
PDF
Test Driven Development with PHP
PDF
Angular Vienna - Use React tools for better Angular apps
PDF
Coding Dojo: Naming with Dices (2021)
PDF
MSL2008. Debugging
PPTX
Server side swift
Why you should care about Go (Golang)
Idiomatic R for Rosetta Code (2013)
Golang - Overview of Go (golang) Language
Test Driven Development with PHP
Angular Vienna - Use React tools for better Angular apps
Coding Dojo: Naming with Dices (2021)
MSL2008. Debugging
Server side swift
Ad

Viewers also liked (19)

PPT
El presidencialismo mexicano antes y después
PDF
Imágenes inmersivas
PDF
Suir img
PPTX
El barrroco
PPTX
Green Peace y WWF
PDF
Social Media For Busy Entrepreneurs and Small Businesses
PPTX
Crisis Subprime en España
PDF
One Year of Porting - Post-mortem of two Linux/SteamOS launches
PPSX
CriminalEFS-PowerPoint
PDF
Linux as a gaming platform - Errata
PPT
Ecosistemas
PDF
Linux as a gaming platform, ideology aside
PPTX
каталог керасис
PDF
Cross-platform game engine development with SDL 2.0
PDF
Хипстеры в энтерпрайзе
ODP
OpenGL (ES) debugging
ODP
Advanced Linux Game Programming
PDF
Docker In Bank Unrated
PDF
Service Discovery. Spring Cloud Internals
El presidencialismo mexicano antes y después
Imágenes inmersivas
Suir img
El barrroco
Green Peace y WWF
Social Media For Busy Entrepreneurs and Small Businesses
Crisis Subprime en España
One Year of Porting - Post-mortem of two Linux/SteamOS launches
CriminalEFS-PowerPoint
Linux as a gaming platform - Errata
Ecosistemas
Linux as a gaming platform, ideology aside
каталог керасис
Cross-platform game engine development with SDL 2.0
Хипстеры в энтерпрайзе
OpenGL (ES) debugging
Advanced Linux Game Programming
Docker In Bank Unrated
Service Discovery. Spring Cloud Internals
Ad

Similar to Gamedev-grade debugging (20)

PDF
Killer Bugs From Outer Space
PDF
Introduction of Tools for providing rich user experience in debugger
PDF
My talk on Piter Py 2016
PDF
IntoWebGL - Unite Melbourne 2015
PDF
PyConUK 2014 - PostMortem Debugging and Web Development Updated
PDF
Transitioning to Native
PDF
Y U NO CRAFTSMAN
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
ODP
Agileee 2012
PDF
Android Platform Debugging and Development
PDF
JSHint: Learning JavaScript the Hard Way
PPTX
Hacker vs company, Cloud Cyber Security Automated with Kubernetes - Demi Ben-...
PDF
Android Platform Debugging and Development
PDF
Headless Android
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
PDF
Working With Legacy Code
PPTX
Dear compiler please don't be my nanny v2
Killer Bugs From Outer Space
Introduction of Tools for providing rich user experience in debugger
My talk on Piter Py 2016
IntoWebGL - Unite Melbourne 2015
PyConUK 2014 - PostMortem Debugging and Web Development Updated
Transitioning to Native
Y U NO CRAFTSMAN
Android Platform Debugging and Development
Android Platform Debugging and Development
Agileee 2012
Android Platform Debugging and Development
JSHint: Learning JavaScript the Hard Way
Hacker vs company, Cloud Cyber Security Automated with Kubernetes - Demi Ben-...
Android Platform Debugging and Development
Headless Android
Android Platform Debugging and Development
Android Platform Debugging and Development
Android Platform Debugging and Development
Working With Legacy Code
Dear compiler please don't be my nanny v2

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx

Gamedev-grade debugging

  • 1. inequation.org inequation.org Gamedev-grade debugging Leszek Godlewski Freelance Programmer lg@inequation.org SpreadIT 2013 · October 19th, 2013 SpreadIT 2013 · October 19th, 2013
  • 2. Code snippets Code snippets All code used in the talk available online: github.com/inequation/ggd 2 2 inequation.org inequation.org
  • 3. Agenda Agenda ● Who is this guy? ● Why the talk? ● A taste of gamedev debugging ● Right tool for the job ● Noise filtering ● Memory corruption ● Questions 3 3 inequation.org inequation.org
  • 4. Who is this guy? Who is this guy? Freelance Programmer ● ● ● (Sep 2013 – onwards) inequation.org Painkiller Hell & Damnation Linux port finalization (2013) Unannounced project Generalist Programmer, The Farm 51 ● ● ● ● 4 4 (Mar 2010 – Aug 2013) thefarm51.com Painkiller Hell & Damnation (2012-2013; Win/Linux/X360/PS3) Deadfall Adventures (2011-2013; Win/X360) A few unannounced projects inequation.org inequation.org
  • 5. Agenda Agenda ● Who is this guy? ● Why the talk? ● A taste of gamedev debugging ● Right tool for the job ● Noise filtering ● Memory corruption ● Questions 5 5 inequation.org inequation.org
  • 6. Why the talk? Why the talk? Because THIS has happened to me: http://imgur.com/yBa1OGm 6 6 inequation.org inequation.org
  • 7. Why the talk? Why the talk? Intern: I've read* at all the code and still don't see the bug. Me: So just debug it! *read, as in „stare without actually running it” 7 7 inequation.org inequation.org
  • 8. Why the talk? Why the talk? Intern: © DreamWorks 8 8 http://imgur.com/yBa1OGm inequation.org inequation.org
  • 9. Why the talk? Why the talk? The three uses of debugging ● Bug hunting (doh) ● ● 9 9 inequation.org inequation.org
  • 10. Why the talk? Why the talk? The three uses of debugging Bug hunting (doh) ● Reverse engineering ● ● 10 10 inequation.org inequation.org
  • 11. Why the talk? Why the talk? The three uses of debugging Bug hunting (doh) ● Reverse engineering ● Testing a new feature ● 11 11 inequation.org inequation.org
  • 12. Agenda Agenda ● Who is this guy? ● Why the talk? ● A taste of gamedev debugging ● Right tool for the job ● Noise filtering ● Memory corruption ● Questions 12 12 inequation.org inequation.org
  • 13. A taste of gamedev debugging A taste of gamedev debugging Code: 01-taste 13 13 inequation.org inequation.org
  • 14. A taste of gamedev debugging A taste of gamedev debugging Can you spot the culprit? // class declaration class Crasher extends ActorComponent; var int DummyArray[1024]; // in ammo consumption code Crash = new class'Crasher'; Comp = new class'ActorComponent' (Crash); 14 14 inequation.org inequation.org
  • 15. Agenda Agenda ● Who is this guy? ● Why the talk? ● A taste of gamedev debugging ● Right tool for the job ● Noise filtering ● Memory corruption ● Questions 15 15 inequation.org inequation.org
  • 16. Right tool for the job Right tool for the job „Fix a bug for an intern, they will get stuck on the next one. Teach them debugging, they will fix most bugs they encounter on their own.” – Paulo Coelho 16 16 inequation.org inequation.org
  • 17. Right tool for the job Right tool for the job Debugging tools are essential to this profession! When joining a new team or starting development for a new platform, demand debugging tools ● Ask senior teammates ● If they don't know, there must be documentation ● Be proactive! ● Don't give up until the debugger is fully working ● No tools? Roll your own! ● You are a coder after all, right? ● 17 17 inequation.org inequation.org
  • 18. Right tool for the job Right tool for the job Not all bugs are in the code Animation graphs ● Flow graphs/visual scripts ● Post-process effects ● Still need a way to debug them 18 18 inequation.org inequation.org
  • 19. Right tool for the job Right tool for the job Code: 02-tools 19 19 inequation.org inequation.org
  • 20. Agenda Agenda ● Who is this guy? ● Why the talk? ● A taste of gamedev debugging ● Right tool for the job ● Noise filtering ● Memory corruption ● Questions 20 20 inequation.org inequation.org
  • 21. Noise filtering Noise filtering There are parts of code executed thousands of times each frame Object transformation ● Collision detection ● Also rarer, but still impractical to track Setting materials on objects ● Attaching and detaching of components ● 21 21 inequation.org inequation.org
  • 22. Noise filtering Noise filtering Code: 03-material 04-ragdoll 05-assert 22 22 inequation.org inequation.org
  • 23. Agenda Agenda ● Who is this guy? ● Why the talk? ● A taste of gamedev debugging ● Right tool for the job ● Noise filtering ● Memory corruption ● Questions 23 23 inequation.org inequation.org
  • 24. Memory corruption Memory corruption Look closely: // class declaration class Crasher extends ActorComponent; var int DummyArray[1024]; // in ammo consumption code Crash = new class'Crasher'; Comp = new class'ActorComponent' (Crash); 24 24 inequation.org inequation.org
  • 25. Memory corruption Memory corruption Look closely: // class declaration class Crasher extends ActorComponent; var int DummyArray[1024]; // in ammo consumption code Crash = new class'Crasher'; Comp = new class'ActorComponent' (Crash); 25 25 inequation.org inequation.org
  • 26. Memory corruption Memory corruption ● UnrealScript object construction syntax new <class> [(<template object>)]; ● But: sizeof(Crasher) > sizeof(ActorComponent) ● Verdict: 26 26 inequation.org inequation.org
  • 27. Memory corruption Memory corruption ● UnrealScript object construction syntax new <class> [(<template object>)]; ● But: sizeof(Crasher) > sizeof(ActorComponent) ● Verdict: 27 27 BUFFER OVERFLOW! inequation.org inequation.org
  • 28. Memory corruption Memory corruption But this can happen anywhere! How to find it? Use a memory fence ● Many related techniques ● Allocate additional space in front and behind actual allocations ● Then protect them from writing... ● Or write a byte pattern and periodically assert its consistency ● Also it's useful to log stack traces ● Memory and CPU overhead! ● Use a debug memory allocator (dmalloc) ● Use a memory debugger (Valgrind) ● Use a memory analysis tool (HeapInspector) ● 28 28 inequation.org inequation.org
  • 29. Memory corruption Memory corruption Memory fences malloc Regular allocation 29 29 malloc Fenced allocation inequation.org inequation.org
  • 30. Takeaway Takeaway You can't be an effective programmer without debugging tools ● If there are no tools, make some ● Noise filtering techniques save your time ● Time is not only money – nerves are just as important! ● Know your machine (physical or virtual) down to the metal ● Instruction opcodes, registers etc. come in handy ● Tons of resources available ● Random crashes and/or content glitches may indicate memory corruption ● Memory corruption can be defeated! ● 30 30 inequation.org inequation.org
  • 31. inequation.org inequation.org Questions? lg@inequation.org SpreadIT 2013 · October 19th, 2013 SpreadIT 2013 · October 19th, 2013