Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Joysticks work under Linux but not under windows  (Read 1111 times)

simulacrum111

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 10
    • View Profile
Joysticks work under Linux but not under windows
« on: September 15, 2009, 02:26:36 PM »

Hello again,

I have intergrated OIS into my application for joystick support.  Under linux everything is copacetic.

Windows is another story...

If I run the OISConsole demo that comes with the OIS source my joysticks are not recognized, but the demo application does not suffer any runtime errors.  Let me clarify, OIS detects my joysticks but I don't get any inputs from them in buffered or unbuffered mode.

In my own code I cannot get OIS to initialize.  The code fails in the following OIS function found in Win32InputManager.cpp:

Code: [Select]
void Win32InputManager::_parseConfigSettings( ParamList &paramList )
{
//Here we pick up settings such as a device's cooperation mode
std::map<std::string, DWORD> temp;
temp["DISCL_BACKGROUND"] = DISCL_BACKGROUND;
temp["DISCL_EXCLUSIVE"] = DISCL_EXCLUSIVE;
temp["DISCL_FOREGROUND"] = DISCL_FOREGROUND;
temp["DISCL_NONEXCLUSIVE"] = DISCL_NONEXCLUSIVE;
temp["DISCL_NOWINKEY"] = DISCL_NOWINKEY;

//Check for pairs: ie. ("w32_keyboard","DISCL_NOWINKEY")("w32_keyboard","DISCL_FOREGROUND")
ParamList::iterator i = paramList.begin(), e = paramList.end();
for( ; i != e; ++i )
{
if( i->first == "w32_keyboard" )
kbSettings |= temp[i->second];
else if( i->first == "w32_mouse" )
mouseSettings |= temp[i->second];
else if( i->first == "w32_joystick" )
joySettings |= temp[i->second];
}
if( kbSettings == 0 ) kbSettings = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE | DISCL_NOWINKEY;
if( mouseSettings == 0 ) mouseSettings = DISCL_FOREGROUND | DISCL_EXCLUSIVE;
if( joySettings == 0 ) joySettings = DISCL_FOREGROUND | DISCL_EXCLUSIVE;
}

The first "if statement" in the for loop generates an exception "Expression: map/set iterator not dereferencable" in msvc 9.  The map is not empty and the code is not trying to de-reference the "end" iterator...I'm baffled completely as to what else could cause this.

My OIS initialization code is virtually identical to that in the OIS console demo (again no runtime errors from the demo, but joysticks don't work.).

Here is my init code if it helps to see it:

Code: [Select]
                        OIS::ParamList pl;

#if defined OIS_WIN32_PLATFORM
                        if (!fltk::xid(disp_win))
                        {
                                Terminate("\nInputPoller::StartJoystickPolling - FLTK did provide a valid window handle - ensure "show" is called on the window before calling this function.");
                        }//end if

                        std::ostringstream converter;
                        converter<<(size_t)fltk::xid(disp_win);

                        pl.insert(std::make_pair(std::string("WINDOW"),converter.str()));

                        //Default mode is foreground exclusive..but, we want to show mouse - so nonexclusive
                        //pl.insert(std::make_pair(std::string("w32_mouse"),std::string("DISCL_FOREGROUND")));
                        //pl.insert(std::make_pair(std::string("w32_mouse"),std::string("DISCL_NONEXCLUSIVE")));
#elif defined OIS_LINUX_PLATFORM
                        std::ostringstream converter;
                        converter<<fltk::xid(disp_win);

                        pl.insert(std::make_pair(std::string("WINDOW"),converter.str()));

                        //For this demo, show mouse and do not grab (confine to window)
                        // pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false")));
                        // pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false")));
#endif
                        //This never returns null.. it will raise an exception on errors
                        this->_inputManager = OIS::InputManager::createInputSystem(pl);

                        //Lets enable all addons that were compiled in:
                        this->_inputManager->enableAddOnFactory(OIS::InputManager::AddOn_All);

#ifndef NDEBUG
                        //Print debugging information
                        unsigned int v = this->_inputManager->getVersionNumber();
                        std::cout << "OIS Version: " << (v >> 16) << "." << ((v >> 8) & 0x000000FF) << "." << (v & 0x000000FF)
                                << "\nRelease Name: " << this->_inputManager->getVersionName()
                                << "\nManager: " << this->_inputManager->inputSystemName()
                                << "\nTotal Keyboards: " << this->_inputManager->getNumberOfDevices(OIS::OISKeyboard)
                                << "\nTotal Mice: " << this->_inputManager->getNumberOfDevices(OIS::OISMouse)
                                << "\nTotal JoySticks: " << this->_inputManager->getNumberOfDevices(OIS::OISJoyStick);

                        //List all devices
                        const char *g_DeviceType[6] = {
                                "OISUnknown",
                                "OISKeyboard",
                                "OISMouse",
                                "OISJoyStick",
                                "OISTablet",
                                "OISOther"};
                        OIS::DeviceList list = this->_inputManager->listFreeDevices();
                        for (OIS::DeviceList::iterator i = list.begin(); i != list.end(); ++i)
                        {
                                std::cout<<"\n\tDevice: "<<g_DeviceType[i->first]<<" Vendor: "<<i->second;
                        }//end for
#endif

                        try
                        {
                                this->_joysticks.reserve(
                                        this->_inputManager->getNumberOfDevices(
                                                OIS::OISJoyStick));
                                for (unsigned int i = 0; i < this->_joysticks.capacity(); ++i)
                                {
                                        this->_joysticks.push_back(
                                                static_cast<OIS::JoyStick*>(
                                                        this->_inputManager->createInputObject(
                                                                OIS::OISJoyStick,false)));
#ifndef NDEBUG
                                        std::cout<<"\n\nCreated Joystick "<<(i + 1)
                                               <<"\n\tAxes: "<<this->_joysticks.back()->getNumberOfComponents(OIS::OIS_Axis)
                                               <<"\n\tSliders: "<<this->_joysticks.back()->getNumberOfComponents(OIS::OIS_Slider)
                                               <<"\n\tPOV/HATs: "<<this->_joysticks.back()->getNumberOfComponents(OIS::OIS_POV)
                                               <<"\n\tButtons: "<<this->_joysticks.back()->getNumberOfComponents(OIS::OIS_Button)
                                               <<"\n\tVector3: "<<this->_joysticks.back()->getNumberOfComponents(OIS::OIS_Vector3);
                                }//end for

                                std::cout<<std::endl;
#else
                                }//end for
#endif
                        }
                        catch (OIS::Exception &ex)
                        {
                                Terminate(sestring("\nInputPoller::StartJoystickPolling - Joystick creation failed:  ").append(ex.eText));
                        }//end try


Has this problem ever surfaced before?  Any Ideas?

Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Joysticks work under Linux but not under windows
« Reply #1 on: September 15, 2009, 05:53:32 PM »

For the map iteration issue, I can only assume some kind of:
1) Build mismatch (debug vs release, SP1 vs non-SP1, vc7 vs vc9, etc). Make sure you clean everything of OIS, and re-build all with your current IDE
2) A buffer / memory issue within your code that happens to be breaked on in OIS code.

For the joystick issue, I'm not sure why the OIS Console demo would not pick up any input from the joysticks.. are you positive? If I recall, they simply don't dump to joystick events to standard output - or didn't before. If you add some cout's there, it should show some kind of actions.
Logged

simulacrum111

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 10
    • View Profile
Re: Joysticks work under Linux but not under windows
« Reply #2 on: September 15, 2009, 07:12:20 PM »

I recompiled OIS and the console demo from scratch using visual studio.  I can't use MinGW or Cygwin because people with throw fits...and visual studio isn't bad.

I didn't get any different results.

It will take all night but I will recompile the entire project tonight and see if something has slipped through the cracks.  My hope is that someone borked something during a build somewhere and the iterator problem isn't any more subtle than that.

---------------------------------------

As for not getting any input on standard out with the Console demo -

- When input is buffered and output should be handled by the "handler" class and I get nothing.  The handler is full of print statements so since I see nothing in standard output I'm assuming I'm not getting any events.

- When input is NOT buffered I get the axis state of the joystick BUT that state is never updated i.e. axis 0 thru N just sit on the init value of 0 no matter what I do with the joystick.  This output is continuous whether I am doing anything or not with the sticks.  I don't know how to interpret what is happening in this case.

Getting/not getting events could be a symptom of the "iterator" problem so maybe if I fix that then this problem will fix itself.  Something strange is that the same joystick is reported as having different numbers of axis under windows and linux.

I don't mean to be a bother.  I'm just looking for insight.
« Last Edit: September 16, 2009, 05:47:16 AM by simulacrum111 »
Logged

simulacrum111

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 10
    • View Profile
Re: Joysticks work under Linux but not under windows
« Reply #3 on: September 16, 2009, 10:24:22 AM »

I have rebuilt my entire project twice now to no effect.

The map only exists as long as it takes to initialize OIS.  I add the window to the parameter list and pass it to OIS.  That's it.

From the code I'm using and in OIS the iterator should be valid when OIS needs it.

Perhaps this is a compiler problem.  Are there any complier options I should avoid?  I disabled secure stl and the min, max from the windows api.  That's about it.

Nothing makes sense here.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Joysticks work under Linux but not under windows
« Reply #4 on: September 16, 2009, 06:01:25 PM »

Are you using the v1_2 branch of OIS? if not, grab that from CVS. Also, try using the other input method that takes an int directly for the window handle and see if that works for you. Then, it constructs the param list inside OIS code... The error definitely sounds like an STL mismatch between OIS build and your app.. perhaps because of what you said about disabling secure stl.. what do you mean by that?
Logged

simulacrum111

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 10
    • View Profile
Re: Joysticks work under Linux but not under windows
« Reply #5 on: September 16, 2009, 11:00:16 PM »

It seems our guesses were right.

There is an STL incompatiblity due to compiler options.  I disable visual studio's secure STL features because of the performance hit they can impose.  I did not set the proper compiler options to do the same for OIS since OIS uses the STL.  This made my build of OIS binary incompatible with my project.

The iterator problem is passed for now by enabling secure STL.

I still can't get a dump of the joystick state, but I am encouraged that one problem is out of the way.
Logged

simulacrum111

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 10
    • View Profile
Re: Joysticks work under Linux but not under windows
« Reply #6 on: September 17, 2009, 09:52:57 AM »

I think I've gotten all the issues ironed out.

Thanks for the responses.  Cheers.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: Joysticks work under Linux but not under windows
« Reply #7 on: September 17, 2009, 06:42:57 PM »

Cool. So you got your joystick working too? What was the issue if you don't mind me asking.
Logged