RESOLVED:segfault error; help please?
Posted: Sun Jan 11, 2009 5:54 am
Maybe it's because I've been devving all night, but this is beyond me... Whenever I run my project, it gets to the constructor and calls updateStates(). It segfaults when trying to access the controller, whether it comes to the hat, axes, or buttons first.
typedef'd struct called myController...
class header called inputClass
source code
typedef'd struct called myController...
Code: Select all
typedef struct
{
Sint16 axis[4];
bool button[12];
Uint8 hat;
} myController;
Code: Select all
class inputClass
{
private:
SDL_Joystick* joystick;
myController* controller;
public:
inputClass();
~inputClass();
void updateStates();
myController* getStates();
};
Code: Select all
inputClass::inputClass()
{
SDL_Init(SDL_INIT_JOYSTICK);
joystick = SDL_JoystickOpen(0);
//std::cout << "joystick open" << std::endl;
updateStates();
}
void inputClass::updateStates()
{
for(int i = 0; i < 4; i++)
{
controller->axis[i] = SDL_JoystickGetAxis(joystick, i);
}
for (int i = 0; i < 12; i++)
{
controller->button[i] = SDL_JoystickGetButton(joystick, i);
}
controller->hat = SDL_JoystickGetHat(joystick, 0);
}