[SDL] Need help tracking down a SegFault

Erik esigra at gmail.com
Sun Feb 24 10:56:17 PST 2008


Michael Sullivan skrev:
> On Sun, 2008-02-24 at 19:20 +0100, Erik wrote:
>   
>> Michael Sullivan skrev:
>>     
>>> michael at camille ourrpg $ make && ./main
>>> g++ -W -Wall `sdl-config --cflags`  -c battle.cpp
>>> battle.cpp: In member function 'bool Battle::initialize()':
>>> battle.cpp:85: warning: name lookup of 'i' changed
>>> battle.cpp:11: warning:   matches this 'i' under ISO standard rules
>>> battle.cpp:58: warning:   matches this 'i' under old rules
>>>       
>> Fix those warnings first and see if it helps.
>> _______________________________________________
>>     
>
> michael at camille ourrpg $ make
> g++ -O1 -g -ggdb -W -Wall `sdl-config --cflags`  -c battle.cpp
> battle.cpp: In member function 'SDL_Surface* Battle::drawString(int,
> int, std::string)':
> battle.cpp:108: warning: missing initializer for member
> 'SDL_Color::unused'
> g++ -O1 -g -ggdb -W -Wall `sdl-config --cflags`  -c character.cpp
> g++ -O1 -g -ggdb -W -Wall `sdl-config --cflags`  -c ally.cpp
> g++ -O1 -g -ggdb -W -Wall `sdl-config --cflags`  -c main.cpp
> g++ -o main battle.o character.o ally.o main.o `sdl-config --libs`
> -lSDL_image -lSDL_gfx -lSDL_ttf -lz 
> michael at camille ourrpg $ gdb main
> GNU gdb 6.7.1
> Copyright (C) 2007 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show
> copying"
> and "show warranty" for details.
> This GDB was configured as "i686-pc-linux-gnu"...
> Using host libthread_db library "/lib/libthread_db.so.1".
> (gdb) r
> Starting program: /home/michael/ourrpg/main 
> [Thread debugging using libthread_db enabled]
> [New Thread 0x4000 (LWP 14641)]
> Line is 65; i = 0
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x4000 (LWP 14641)]
> 0xb7f1a752 in SDL_MapRGB () from /usr/lib/libSDL-1.2.so.0
> (gdb) backtrace
> #0  0xb7f1a752 in SDL_MapRGB () from /usr/lib/libSDL-1.2.so.0
> #1  0x080496d6 in Battle::initialize (this=0xbfca96d4) at battle.cpp:66
> #2  0x0804b087 in main () at main.cpp:7
> (gdb) quit
> The program is running.  Exit anyway? (y or n) y
> michael at camille ourrpg $ valgrind ./main
> ==14644== Memcheck, a memory error detector.
> ==14644== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et
> al.
> ==14644== Using LibVEX rev 1732, a library for dynamic binary
> translation.
> ==14644== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
> ==14644== Using valgrind-3.2.3, a dynamic binary instrumentation
> framework.
> ==14644== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et
> al.
> ==14644== For more details, rerun with: -v
> ==14644== 
> ==14644== Syscall param write(buf) points to uninitialised byte(s)
> ==14644==    at 0x40DD69E: write (in /lib/libpthread-0.10.so)
> ==14644==    by 0x458DE7D: (within /usr/lib/libX11.so.6.2.0)
> ==14644==  Address 0x465897B is 19 bytes inside a block of size 16,384
> alloc'd
> ==14644==    at 0x4021ABE: calloc
> (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
> ==14644==    by 0x45731B3: XOpenDisplay (in /usr/lib/libX11.so.6.2.0)
> ==14644== 
> ==14644== Conditional jump or move depends on uninitialised value(s)
> ==14644==    at 0x8049683: Battle::initialize() (battle.cpp:64)
> ==14644==    by 0x804B086: main (main.cpp:7)
>   
This is the first error that Valgrind finds in your code, so that is 
where you should start fixing. (Ignore anything that comes after that.) 
I do not know if -O1 is good to use when debugging, -O0 may be safer, so 
it does not show the wrong line numbers somewhere.



More information about the SDL mailing list