Jump to content
  • Advertisement
Sign in to follow this  
Hypherion

Problem with SDL input

This topic is 4504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

first of all this is the actual code
if (SDL_PollEvent(&m_event))
			{
				if (m_event.type == SDL_QUIT)
					{
						m_windowClosed=true;
					}
				if (m_event.type=SDL_KEYDOWN)
				{
					keys[m_event.key.keysym.sym]=true;
					
				}
				if (m_event.type=SDL_KEYUP)
				{
					keys[m_event.key.keysym.sym]=false;
				}
			}


(keys is a one dimensional array which will say what keys are pressed and which aren't) the problem is that after i run the aplication and i move the mouse cursor in the application window, it crashes with a "Fatal signal: Segmentation Fault (SDL Parachute Deployed)" if i take out the last 2 "if" 's it works fine does anyone have an idea about this "problem"?

Share this post


Link to post
Share on other sites
Advertisement
This sort of thing happens when you use array indices which are out of range. Perhaps the keys array is too small.
However, you can use SDL_GetKeyState instead of managing a custom keys array.

Share this post


Link to post
Share on other sites
SDL has a function that returns an array of the keyboard state, so you don't need to deal with keeping track of which keys are pressed or not, which is what's causing the error

try this:

Uint8 *keys = SDL_GetKeyState( NULL );

then, to see if a specific key is pressed:

if( keys[SDLK_SPACE] )
{
std::cout << "hello, world";
}

Much cleaner and easier to manage than what you're currently doing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!