Nick
2006.08.09, 01:51 PM
I'm trying to work on a simple Cocoa app that makes use of SDL's input handling for a joystick. After getting my NIB all set up along with my controller class, I add the SDL framework and make sure that SDL is set to using a NIB. Now when I launch my app, it launches and looks fine, but Command-Q no longer works and when I go to initialize everything (it's a custom menu option), it crashes. I do have a PS2 pad hooked up using a PS2/USB converter which should work just fine (it does in my Windows apps). Here's my main() and the initialize function:
int main( int argc, char *argv[] )
{
SDL_Init( SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE );
SDL_JoystickEventState( 1 );
int value = NSApplicationMain( argc, ( const char ** ) argv );
SDL_Quit();
return value;
}
- (IBAction)initialize:(id)sender
{
numberOfPads = SDL_NumJoysticks();
/*
this is the initialize function for the two pads
- (void)initialize:(int)joystickID
{
joystick = SDL_JoystickOpen( joystickID );
name = [ NSString stringWithCString:SDL_JoystickName( joystickID ) ];
NSLog( name );
}
*/
[ padOne initialize:0 ];
[ padTwo initialize:1 ];
//lDown is simply an NSButton in the NIB
[ lDown setTitle: [ padOne name ] ];
if ( [ padOne joystick ] == nil && [ padTwo joystick ] == nil )
numberOfPads = 0;
else if ( [ padOne joystick ] == nil && [ padTwo joystick ] != nil )
numberOfPads = 3; //cheap way we can tell that there is a second pad
else if ( [ padOne joystick ] != nil && [ padTwo joystick ] == nil )
numberOfPads = 1;
else if ( [ padOne joystick ] != nil && [ padTwo joystick ] != nil )
numberOfPads = 2;
}
int main( int argc, char *argv[] )
{
SDL_Init( SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE );
SDL_JoystickEventState( 1 );
int value = NSApplicationMain( argc, ( const char ** ) argv );
SDL_Quit();
return value;
}
- (IBAction)initialize:(id)sender
{
numberOfPads = SDL_NumJoysticks();
/*
this is the initialize function for the two pads
- (void)initialize:(int)joystickID
{
joystick = SDL_JoystickOpen( joystickID );
name = [ NSString stringWithCString:SDL_JoystickName( joystickID ) ];
NSLog( name );
}
*/
[ padOne initialize:0 ];
[ padTwo initialize:1 ];
//lDown is simply an NSButton in the NIB
[ lDown setTitle: [ padOne name ] ];
if ( [ padOne joystick ] == nil && [ padTwo joystick ] == nil )
numberOfPads = 0;
else if ( [ padOne joystick ] == nil && [ padTwo joystick ] != nil )
numberOfPads = 3; //cheap way we can tell that there is a second pad
else if ( [ padOne joystick ] != nil && [ padTwo joystick ] == nil )
numberOfPads = 1;
else if ( [ padOne joystick ] != nil && [ padTwo joystick ] != nil )
numberOfPads = 2;
}