DEBUGGING CHAPTER 24 1. Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
BIM313 – Advanced Programming Techniques Debugging 1.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Finding and Debugging Errors
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.
How to Debug VB .NET Code.
Getting Started with Colleague Studio Debugger Presented by:Katie Morgan Pacific University August, 2014.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
JavaScript, Fourth Edition
HELLO WORLD: YOUR FIRST PROGRAM CHAPTER Topics  Hello World?  Creating a Unity Project –The Unity Project Folder  MonoDevelop: Unity's Code Editor.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
Enhancing User Interaction Through Programming
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş Please look at the last two slides.
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
Chapter 02 (Part III) Introduction to C++ Programming.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Object Oriented Software Development 8. Exceptions, testing and debugging.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Problem of the Day  Why are manhole covers round?
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Data Structures and Debugging Dr. Nancy Warter-Perez June 18, 2003.
CSE 232: C++ Programming in Visual Studio Graphical Development Environments for C++ Eclipse –Widely available open-source debugging environment Available.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Error Handling Tonga Institute of Higher Education.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Debug in Visual Studio Windows Development Fundamentals LESSON 2.5A.
CHAPTER 10 ERROR HANDLING & DEBUGGING JavaScript can be hard to learn. Everyone makes mistakes when writing it.
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Digital Game Design ACST 3710 Your First Unity Program 1.
Mobile Device Development
Development Environment
A variable is a name for a value stored in memory.
Programming in visual basic .net Visual Basic Building Blocks
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Testing and Debugging.
Computer Programming I
Debugging CMSC 202.
Important terms Black-box testing White-box testing Regression testing
5.01 Understand Different Types of Programming Errors
Common C Programming Errors, GDB Debugging
Tonga Institute of Higher Education
Debugging Taken from notes by Dr. Neil Moore
Chapter 15 Debugging.
Testing, debugging, and using support libraries
Error Analysis Runtime Errors.
Our Environment We will exercise on Microsoft Visual C++ v.6
Debugging Taken from notes by Dr. Neil Moore
ICT Gaming Lesson 2.
Chapter 15 Debugging.
Chapter 15 Debugging.
Presentation transcript:

DEBUGGING CHAPTER 24 1

Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping Through Code with the Debugger –Attaching the Debugger to Unity  Watching Variables in the Debugger 2

Getting Started with Debugging  Debugging is a way to step through and watch your code as it is running  This can help you –Better understand code –Find errors and bugs –Track down inefficiencies  Debugging is built in to Unity via MonoDevelop –The MonoDevelop debugger can attach to the Unity process to debug your code –And, the MonoDevelop debugger can connect to an iOS or Android device and debug code running on the device!!! This is very helpful for finding issues with touch interfaces Can be done over either a cable or WiFi! –The book has detailed instructions for using the debugger 3

Types of Bugs  Compile-Time Bugs –A bug found in the syntax of your code –Compile-time bugs prevent your code from compiling Makes it unusable in Unity until the bug is resolved –Compile-time bugs usually cause very specific errors The error below is on line 4, character 14 of CubeSpawner1.cs 4

Anatomy of a Compile-Time Bug  Click the error message to get more information 5

Anatomy of a Compile-Time Bug  Click the error message to get more information  The full error text can usually tell you what's wrong 6

Anatomy of a Compile-Time Bug  Click the error message to get more information  The full error text can usually tell you what's wrong –If not, search the Internet for the error number –Example: "Unity error CS0101" Unity forums and StackOverflow.com have some of the best answers 7

Common Compile-Time Errors to Know  error CS0101: The namespace 'global::' already contains a definition for '______' –Two scripts are trying to define the same class Change the name of the class in one of the scripts  error CS1525: Unexpected symbol '}' –Many "Unexpected symbol" errors are caused by a semicolon missing on a previous line or a misplaced brace Check line endings for semicolons ; Check to make sure all braces have a mate { } 8

Bugs Attaching Scripts to GameObjects  Error occurs when attempting to attach a script to a GameObject –Caused by the name of the script not matching the name of the defined class  Example –Script filename: CubeSpawner1 (or CubeSpawner1.cs) –Class name : public class CubeSpawner : MonoBehaviour { … }  To Fix: Match the names to each other 9

Types of Bugs  Runtime Errors –A bug that occurs when your code is running –Unity has no way of predicting these  Most common types of Runtime Errors –UnassignedReferenceException –NullReferenceException 10

Common Runtime Errors  UnassignedReferenceException –A variable in the Inspector has not been set Most commonly GameObject prefabs for Instantiate() calls –To Fix: Assign the variable in the Inspector 11

Common Runtime Errors  Null Reference Exception –Unity has been asked to access something that doesn't exist –Example: 7void Start () { 8GameObject[] goArray = new GameObject[10]; 9print (goArray[5].transform.position); 10} // on line 9, goArray[5] is null, so it has no transform 12 –Error can only tell you the line number –These are difficult to debug!

Stepping Through Code with the Debugger  Step 1: Set a Breakpoint in your code 13

Stepping Through Code with the Debugger  Step 2: Attach the Debugger to the Unity process –Much more detail in the book (about a potential bug) –Click the Attach to Process button in MonoDevelop 14 –Choose Unity Editor (Unity) from the process list & click Attach

Stepping Through Code with the Debugger  Step 3: Click Play in Unity –The Debugger will halt code execution at the Breakpoint 15

Stepping Through Code with the Debugger  Step 3: Click Play in Unity –The Debugger will halt code execution at the Breakpoint –Unity will be completely frozen while the Debugger is halted This means you cannot switch back to the Unity process –Important buttons at the top of the Debugger window 16 –Each controls the Debugger's execution Run – Continues playing the project until another breakpoint is hit If Run doesn't advance to the next frame, switch back to Unity Step Over – Continues to the next line, stepping over function calls Step In – Continues to the next line, stepping into function calls Step Out – Exits the current function but continues debugging Detach Process – Stops debugging altogether

Watching Variables in the Debugger  Panes at the bottom of MonoDevelop have more info –Locals - Allows you to see all local variables this is a reference to the current class instance –Watch - Allows you to enter specific variables to watch –Call Stack - Shows you which functions have been called to get to this point in the code Click a function to jump to it's local scope 17

Chapter 24 – Summary 18  Debugging is one of the most important processes in coding –The MonoDevelop Debugger is one of the most powerful tools for you to learn –It's also surprisingly easy to learn to use –The Debugger can also help you understand complex code Use it on the code from the book if you're ever confused  You can also code for Unity using Microsoft Visual Studio, which has its own debugger –Lots of information online about how to set this up  Next Chapter: Classes –Learn about how classes combine data and functionality –All the code you write in Unity C# will be in classes –Classes are also the key to Object-Oriented Programming