[solved]SDL input error

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

[solved]SDL input error

Post by pythip »

I am doing lazy foos tutorial, I did a number of them, and then started over and am doing them again but inside classes this time, all went well the first time I did them.
so my problem is this I compile my program, run it, alls fine, but when I quit I get a whole bunch of errors in my console. below is some of the code of my program, I will post a portion the error message it is quite lengthy, any help would be great

from input.cpp

Code: Select all

int input::get_input()
{		
	key = SDL_GetKeyState (NULL);

	if (key[SDLK_UP])
	{
	x = 1;
	}
	if (key[SDLK_DOWN])
	{
	x = 2;
	}
	if (key[SDLK_LEFT])
	{
	x = 3;
	}
	if (key[SDLK_RIGHT])
	{
	x = 4;
	}
	if (key[SDLK_r])
	{
	inputgraphics.load_graphics();
	}
	return x;
}
from main.cpp

Code: Select all

while( quit == false )
	{
		quit =input.check_quit(quit);
		graphics.x = input.get_input();
		graphics.getInput();
		graphics.update();
	}
	graphics.quit();
	engine.quit();
	return 0;
from graphics.cpp

Code: Select all

void graphics::getInput()
{
	if (x == 1)
	{
	message = upMessage;
	}
	if (x == 2)
	{
	message = downMessage;
	}
	if (x == 3)
	{
	message = leftMessage;
	}
	if (x == 4)
	{
	message = rightMessage;
	}
}
bool graphics::update()
{
apply_surface( 0, 0, background, buffer,NULL);
apply_surface(500, 0, message, buffer);
apply_surface(0, 0, player, buffer, &clip[0]);
apply_surface( 0, 40, player, buffer, &clip[1]);
apply_surface( 0, 80, player, buffer, &clip[2]);
apply_surface( 0, 120, player, buffer, &clip[3]);
    if( SDL_Flip( buffer ) == -1 )

    {
	printf("graphics.cpp buffer = -1: %s\n", SDL_GetError());

        return 1;

    }
}
error message

Code: Select all

*** glibc detected *** ./test: double free or corruption (!prev): 0x08530ab0 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0x19dff1]
/lib/tls/i686/cmov/libc.so.6[0x19f6f2]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x1a27cd]
/usr/lib/libSDL-1.2.so.0(SDL_FreeSurface+0xe8)[0xdf1a68]
./test[0x8049397]
./test[0x8049581]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x149b56]
./test[0x8048c41]
======= Memory map: ========
00110000-00126000 r-xp 00000000 08:07 7120       /usr/lib/libdirect-1.2.so.0.7.0
00126000-00127000 r--p 00015000 08:07 7120       /usr/lib/libdirect-1.2.so.0.7.0
00127000-00128000 rw-p 00016000 08:07 7120       /usr/lib/libdirect-1.2.so.0.7.0
00128000-0012a000 r-xp 00000000 08:07 6897       /usr/lib/libXau.so.6.0.0
0012a000-0012b000 r--p 00001000 08:07 6897       /usr/lib/libXau.so.6.0.0
0012b000-0012c000 rw-p 00002000 08:07 6897       /usr/lib/libXau.so.6.0.0
0012c000-00130000 r-xp 00000000 08:07 6908       /usr/lib/libXdmcp.so.6.0.0
00130000-00131000 rw-p 00003000 08:07 6908       /usr/lib/libXdmcp.so.6.0.0
00133000-00271000 r-xp 00000000 08:07 1377       /lib/tls/i686/cmov/libc-2.10.1.so
00271000-00272000 ---p 0013e000 08:07 1377       /lib/tls/i686/cmov/libc-2.10.1.so
00272000-00274000 r--p 0013e000 08:07 1377       /lib/tls/i686/cmov/libc-2.10.1.so
00274000-00275000 rw-p 00140000 08:07 1377       /lib/tls/i686/cmov/libc-2.10.1.so
00275000-00278000 rw-p 00000000 00:00 0 
00278000-0033a000 r-xp 00000000 08:07 22518      /usr/lib/libasound.so.2.0.0
0033a000-0033e000 r--p 000c1000 08:07 22518      /usr/lib/libasound.so.2.0.0
0033e000-0033f000 rw-p 000c5000 08:07 22518      /usr/lib/libasound.so.2.0.0
0033f000-00361000 r-xp 00000000 08:07 7528       /usr/lib/libjpeg.so.62.0.0
00361000-00362000 r--p 00021000 08:07 7528       /usr/lib/libjpeg.so.62.0.0
00362000-00363000 rw-p 00022000 08:07 7528       /usr/lib/libjpeg.so.62.0.0
00363000-00377000 r-xp 00000000 08:07 1440       /lib/libz.so.1.2.3.3
00377000-00378000 r--p 00013000 08:07 1440       /lib/libz.so.1.2.3.3
00378000-00379000 rw-p 00014000 08:07 1440       /lib/libz.so.1.2.3.3
00379000-00387000 r-xp 00000000 08:07 6910       /usr/lib/libXext.so.6.4.0
00387000-00388000 r--p 0000d000 08:07 6910       /usr/lib/libXext.so.6.4.0
00388000-00389000 rw-p 0000e000 08:07 6910       /usr/lib/libXext.so.6.4.0
00389000-00391000 r-xp 00000000 08:07 6932       /usr/lib/libXrender.so.1.3.0
00391000-00392000 r--p 00007000 08:07 6932       /usr/lib/libXrender.so.1.3.0
00392000-00393000 rw-p 00008000 08:07 6932       /usr/lib/libXrender.so.1.3.0
00396000-003ad000 r-xp 00000000 08:07 6860       /usr/lib/libICE.so.6.3.0
003ad000-003ae000 r--p 00016000 08:07 6860       /usr/lib/libICE.so.6.3.0
003ae000-003af000 rw-p 00017000 08:07 6860       /usr/lib/libICE.so.6.3.0
003af000-003b1000 rw-p 00000000 00:00 0 
003b3000-003c8000 r-xp 00000000 08:07 4699       /lib/tls/i686/cmov/libpthread-2.10.1.so
003c8000-003c9000 r--p 00014000 08:07 4699       /lib/tls/i686/cmov/libpthread-2.10.1.so
003c9000-003ca000 rw-p 00015000 08:07 4699       /lib/tls/i686/cmov/libpthread-2.10.1.so
003ca000-003cc000 rw-p 00000000 00:00 0 
003cc000-00442000 r-xp 00000000 08:07 7122       /usr/lib/libdirectfb-1.2.so.0.7.0
00442000-00443000 ---p 00076000 08:07 7122       /usr/lib/libdirectfb-1.2.so.0.7.0
00443000-00444000 r--p 00076000 08:07 7122       /usr/lib/libdirectfb-1.2.so.0.7.0
00444000-00445000 rw-p 00077000 08:07 7122       /usr/lib/libdirectfb-1.2.so.0.7.0
00445000-00446000 rw-p 00000000 00:00 0 
00446000-00484000 r-xp 00000000 08:07 17070      /usr/lib/libpulse.so.0.12.0
00484000-00485000 r--p 0003d000 08:07 17070      /usr/lib/libpulse.so.0.12.0
00485000-00486000 rw-p 0003e000 08:07 17070      /usr/lib/libpulse.so.0.12.0
00486000-0048a000 r-xp 00000000 08:07 6938       /usr/lib/libXtst.so.6.1.0
0048a000-0048b000 r--p 00004000 08:07 6938       /usr/lib/libXtst.so.6.1.0
0048b000-0048c000 rw-p 00005000 08:07 6938       /usr/lib/libXtst.so.6.1.0
0048c000-00493000 r-xp 00000000 08:07 1435       /lib/libwrap.so.0.7.6
00493000-00494000 r--p 00006000 08:07 1435       /lib/libwrap.so.0.7.6
00494000-00495000 rw-p 00007000 08:07 1435       /lib/libwrap.so.0.7.6
00498000-004ee000 r-xp 00000000 08:07 7857       /usr/lib/libtiff.so.4.2.1
004ee000-004f0000 r--p 00055000 08:07 7857       /usr/lib/libtiff.so.4.2.1
004f0000-004f1000 rw-p 00057000 08:07 7857       /usr/lib/libtiff.so.4.2.1
004f1000-00504000 r-xp 00000000 08:07 1430       /lib/tls/i686/cmov/libnsl-2.10.1.so
00504000-00505000 r--p 00012000 08:07 1430       /lib/tls/i686/cmov/libnsl-2.10.1.so
00505000-00506000 rw-p 00013000 08:07 1430       /lib/tls/i686/cmov/libnsl-2.10.1.so
00506000-00508000 rw-p 00000000 00:00 0 
00508000-0050d000 r-xp 00000000 08:07 7647       /usr/lib/libogg.so.0.6.0
0050d000-0050e000 r--p 00004000 08:07 7647       /usr/lib/libogg.so.0.6.0
0050e000-0050f000 rw-p 00005000 08:07 7647       /usr/lib/libogg.so.0.6.0
00518000-00592000 r-xp 00000000 08:07 7203       /usr/lib/libfreetype.so.6.3.20
00592000-00596000 r--p 00079000 08:07 7203       /usr/lib/libfreetype.so.6.3.20
00596000-00597000 rw-p 0007d000 08:07 7203       /usr/lib/libfreetype.so.6.3.20
00597000-006c1000 r-xp 00000000 08:07 6891       /usr/lib/libX11.so.6.2.0
006c1000-006c2000 ---p 0012a000 08:07 6891       /usr/lib/libX11.so.6.2.0
006c2000-006c3000 r--p 0012a000 08:07 6891       /usr/lib/libX11.so.6.2.0
006c3000-006c5000 rw-p 0012b000 08:07 6891       /usr/lib/libX11.so.6.2.0
006c5000-006c6000 rw-p 00000000 00:00 0 
006c6000-0072c000 r-xp 00000000 08:07 7805       /usr/lib/libsndfile.so.1.0.20
0072c000-0072d000 r--p 00065000 08:07 7805       /usr/lib/libsndfile.so.1.0.20
0072d000-0072e000 rw-p 00066000 08:07 7805       /usr/lib/libsndfile.so.1.0.20
0072e000-00732000 rw-p 00000000 00:00 0 
0073a000-0075d000 r-xp 00000000 08:07 32303      /usr/lib/libpng12.so.0.37.0
0075d000-0075e000 r--p 00022000 08:07 32303      /usr/lib/libpng12.so.0.37.0
0075e000-0075f000 rw-p 00023000 08:07 32303      /usr/lib/libpng12.so.0.37.0
0075f000-00796000 r-xp 00000000 08:07 1324       /lib/libdbus-1.so.3.4.0
00796000-00797000 r--p 00036000 08:07 1324       /lib/libdbus-1.so.3.4.0
00797000-00798000 rw-p 00037000 08:07 1324       /lib/libdbus-1.so.3.4.0
007a0000-007a7000 r-xp 00000000 08:07 6889       /usr/lib/libSM.so.6.0.0
007a7000-007a8000 r--p 00006000 08:07 6889       /usr/lib/libSM.so.6.0.0
007a8000-007a9000 rw-p 00007000 08:07 6889       /usr/lib/libSM.so.6.0.0
007a9000-007f7000 r-xp 00000000 08:07 6843       /usr/lib/libFLAC.so.8.2.0
007f7000-007f8000 r--p 0004d000 08:07 6843       /usr/lib/libFLAC.so.8.2.0
007f8000-007f9000 rw-p 0004e000 08:07 6843       /usr/lib/libFLAC.so.8.2.0
007f9000-00813000 r-xp 00000000 08:07 8502       /usr/lib/libvorbis.so.0.4.0
00813000-00814000 r--p 00019000 08:07 8502       /usr/lib/libvorbis.so.0.4.0Aborted
Last edited by pythip on Mon Apr 26, 2010 7:47 am, edited 1 time in total.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: SDL input error

Post by short »

Code: Select all

graphics.quit();
   engine.quit();
   return 0;
put a breakpoint at the line graphics.quit(); and step through your code with your debugger. That is where I would start. When you do something to exit the program (press the X in the upper right hand corner?) your debugger should pop up and you should be able to step through your code and figure out where the program is exiting, and thus find the error.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: SDL input error

Post by pythip »

I'm using g++ which doesn't have a debugger, I tried putting my code into codeblocks, which I don't have any experience using, and compiled my main.cpp and it ran, then I realised that the breaks that I set didn't stop the program, so I made a project, and when I went to build the project I got errors, I included the same linkers as I would in g++, anyone know how to fix this? I should probably note that the error messages only appear when I press the arrow keys.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: SDL input error

Post by short »

pythip wrote:I'm using g++ which doesn't have a debugger, I tried putting my code into codeblocks, which I don't have any experience using, and compiled my main.cpp and it ran, then I realised that the breaks that I set didn't stop the program, so I made a project, and when I went to build the project I got errors, I included the same linkers as I would in g++, anyone know how to fix this? I should probably note that the error messages only appear when I press the arrow keys.
I'm just going to be blunt. Get a debugger. The fact that it only happens when you press an arrow key is a BIG hint. I would probably have to see your entire program to tell you exactly, because your code looks fine (what I can see of it). So, please do yourself a favor, get and learn (and love?) a debugger. It's like the yang to your ying. Or whatever.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
pythip
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 33
Joined: Sat Apr 24, 2010 11:25 pm

Re: SDL input error

Post by pythip »

so the problem was I telling the program that if RIGHT was pressed, then it would change the text on the screen to "going right", the next time it went through the loop, I would press a different button, assigning multiple variables to the same surface, so I solved it by setting the surface to NULL after I put it on the screen, thanks for the help, had a tough time with the debuggers though (codeblocks/ anjunta /eclipse). So I just printf("exit graphics"), and went from there.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [solved]SDL input error

Post by eatcomics »

That's not gonna be enough... Seriously he is right, get a debugger, if you were having a hard time with them, its because you were doing something wrong. If you get a debugger you will save yourself soooooo much trouble in the future, its not really a suggestion, you will need a debugger
Image
Post Reply