SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)
Peter Kofler
 

La actualidad más candente (8)

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

Destacado

El presidencialismo mexicano antes y después
El presidencialismo mexicano antes y después El presidencialismo mexicano antes y después
El presidencialismo mexicano antes y después
espejodeoesed
 
CriminalEFS-PowerPoint
CriminalEFS-PowerPointCriminalEFS-PowerPoint
CriminalEFS-PowerPoint
Jenn Amabile
 
каталог керасис
каталог керасискаталог керасис
каталог керасис
Nastasik
 

Destacado (19)

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

Similar a Gamedev-grade debugging

Similar a Gamedev-grade debugging (20)

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

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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