Skip to main content
GameDev.net gamedev.net
🔒 Locked

Runtime error - please help

Started by Rodin Dec 12, 2007 at 9:19 PM 1 replies 1k views
Original Post
Rodin
Rodin
Hi, I've been coding my first SDL game - a pong clone creatively named 'Pong' - and it's been going well for a while, but then I started getting a runtime error:
Segmentation fault (core dumped)
I screwed around with the code for a while, rewriting bits of it slightly to see if it would make a difference, and lo and behold it worked again. However, it has been throwing the same error now, and I'm not sure why. When it gives me the error, it does not run ANY of the code. I'm am building it using Code::Blocks and running it through command line on Ubuntu 7.10.
firstelder_d
firstelder_d
A Segmentation fault is a vague error, it basically means you tried to do something you shouldn't have so the os killed your program. You probably tried to access a NULL pointer, or access an array element outside its boundaries

int array[10];array[10] = 5; //seq fault, index is from 0-9


I'm not familiar with Code::Blocks so I don't know what debug tools you have. The brute force way of finding the problem is to start commenting code out until it works and using print statements.
Crypter
Crypter
A segmentation fault is not that vague of an error (Not as much as a GPF can be, anyways.) It simply means you are attempting to read or write to memory you do not have access to.

firstelder_d has posted one common example that can cause a seg fault (The out of bounds array, Although under certain conditions, it may not. It depends on several factors)

Accessing through a null pointer, or an uninitialized garbage pointer will cause problems like this (Including the common 0xc0000005 access violation). Make sure all of your pointers are initialized as soon as you declare them to NULL. Also, insure all pointers are valid by checking against this NULL value before even attempting to use the pointer.

Are you dynamically allocating memory on the heap? Ensure you do not go beyond the allocated memory block. This is similar to the out of bounds array.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.