Segfault in my game

Segfault in my game

Postby Pix3l » 20 Dec 2011, 22:46

Hello guys, I just released my last game, a simple Space Invaders clone written in C and SDL, but i noticed a segmentation fault error and I can't understand what it cause it.

I run gdb with the game and it dump this:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7cf4b30 (LWP 4992)]
0x0804adf9 in moveInvaders () at retroinvaders.c:1061
1061 if(rectCollision(Enemy[i].x, Enemy[i].y, Enemy[i].width, STD_H,

I can't understand why it creates this error...

You can found the complete source here http://code.google.com/p/pix3lworkshop/ ... ers.tar.gz
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

Re: Segfault in my game

Postby qubodup » 21 Dec 2011, 19:34

Can't reproduce on 32bit arch linux.
User avatar
qubodup
Global Moderator
 
Posts: 1671
Joined: 08 Nov 2009, 22:52
Location: Berlin, Germany

Re: Segfault in my game

Postby Pix3l » 21 Dec 2011, 22:03

qubodup {l Wrote}:Can't reproduce on 32bit arch linux.


It's not frequently, it crash at random time at the very beginning, after you press 1 for play.
I noticed it on a 32bit Debian.
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

Re: Segfault in my game

Postby qubodup » 22 Dec 2011, 02:40

can't reproduce on 64bit arch either.

if it appears randomly, perhaps it has to do with an event that happens randomly? perhaps the appearance of the UFO at the top?
User avatar
qubodup
Global Moderator
 
Posts: 1671
Joined: 08 Nov 2009, 22:52
Location: Berlin, Germany

Re: Segfault in my game

Postby Pix3l » 22 Dec 2011, 12:03

It appears at every invaders step, on checking their new position if collide with a piece of bottom bunkers.

I noticed that this bug afflict also win32 systems, the problem is somewhere in moveinvaders function i think...
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

Re: Segfault in my game

Postby andrewj » 22 Dec 2011, 13:27

Line 143 says this:

{l Code}: {l Select All Code}
} Bunker[80];


The 80 should be replaced with MAX_BUNKERS.
Same for Bullets[2], should be Bullets[MAX_BULLETS].

Perhaps you made MAX_BUNKERS higher but forgot to change the other one? Otherwise I cannot see any obvious mistake to make the program crash on that line.
User avatar
andrewj
 
Posts: 194
Joined: 15 Dec 2009, 16:32
Location: Tasmania

Re: Segfault in my game

Postby Pix3l » 22 Dec 2011, 15:33

Very strange...
Tested it again by using the macro in the structs definitions, i have already a segfault

Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb7bebb30 (LWP 3070)]
rectCollision (x1=151566241, y1=176, w1=16, h1=16, x2=64, y2=368, w2=10, h2=8)
at retroinvaders.c:177
177 {

The problem seems to be the call to rectCollision in checking of bunker pieces, that pass an incorrect x1 to the function...

I put some debugging line in the code and the result was this

[Thread debugging using libthread_db enabled]
[New Thread 0xb7dbbb30 (LWP 3424)]
[New Thread 0xb783bb90 (LWP 3425)]
[New Thread 0xb701ab90 (LWP 3426)]
[New Thread 0xb6819b90 (LWP 3427)]
[Thread 0xb783bb90 (LWP 3425) exited]
[Thread 0xb6819b90 (LWP 3427) exited]
[Thread 0xb701ab90 (LWP 3426) exited]
[New Thread 0xb701ab90 (LWP 3428)]
x1 49 y1 144 w1 16 h116
x2 64 y2 368 w2 10 h28
x1 49 y1 144 w1 16 h116
x2 64 y2 368 w2 10 h28

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7dbbb30 (LWP 3424)]
0x0804ae1f in moveInvaders () at retroinvaders.c:1065
1065 printf("x1 %d y1 %d w1 %d h1%d\nx2 %d y2 %d w2 %d h2%d\n", Enemy[i].x, Enemy[i].y, Enemy[i].width, STD_H, Bunker[k].x, Bunker[k].y, BUNKER_TILE_W, BUNKER_TILE_H);
(gdb)

Is it right that the thread 0xb7dbbb30 (LWP 3424)] points to another memory address like this? 0x0804ae1f in moveInvaders () at retroinvaders.c:1065
I have really no idea about... :(
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

Re: Segfault in my game

Postby Pix3l » 23 Dec 2011, 12:20

I found the problem (i hope), thanks to a friend, it was the lenght of the string filename in sounds handling, too short for the path provided.
Now the problem, seems to be vanished, thanks to all for your interest and happy xmas :]

Checks the code repository for the patched version and a modular one. :]
http://www.pix3lworkshop.altervista.org/ - Your 8bit choice since 2006!
User avatar
Pix3l
 
Posts: 55
Joined: 10 Sep 2010, 21:00
Location: Italy

Who is online

Users browsing this forum: No registered users and 1 guest