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:
void Win32InputManager::_parseConfigSettings( ParamList ¶mList )
{
//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:
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?