wgois / OIS

Official OIS repository. Object oriented Input System
https://wgois.github.io/OIS/
zlib License
257 stars 86 forks source link

InputManager::createInputObject(OIS::Mouse, false) crashes when mouse is not plugged in. #60

Open HeeMyung opened 4 years ago

HeeMyung commented 4 years ago

Describe the bug When an application is launched without a valid 'MOUSE' device. the program crashes when calling InputManager::createInputObject(OIS::Mouse, false) (raising an exception)

To Reproduce Just run an application without proper 'MOUSE' device.

Expected behavior Do not crash.

Platform (please complete the following information):

Additional context You could think silly about launching without any valid mouse, but some people using my apps only with a trackball device, not with a mouse. Funny thing is that if I run the program with plugged in a mouse and unplugging out after initialize, the program runs well and actually can control the mouse cursor with trackball device!

Ybalrid commented 4 years ago

Interesting... I need to try to repro that. @HeeMyung sorry for the delay, you have some code to share or a project to repro that in?

HeeMyung commented 4 years ago

There are some systems that have a device that could actually generate mouse events (like surface pro) that can't pass up the initialization process. I can't reproduce the problem cause I was just received some crash dumps over the user report and googling the situation. The only thing I can reproduce was that the program raise an exception when I don't have any mouse device which is normal I think. A funny thing here is that I have a 'used' mouse device that is not plugged in (was the mouse I used before). And if I don't stop using that device, I don't have any problem with initializing the program even though I actually pull off all of my real mouse devices. And I can continue without any problem after plugging in a mouse after initialization. So my guess is that the creation of a mouse object on OIS does not need the actual mouse device but just something I don't know.

Here's the code fragment which the exception raised. The program crashes on the last line because my program is not handling the exception.

sorry for poor English

OIS::ParamList pl;
std::ostringstream wHndStr;
wHndStr << m_windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), wHndStr.str()));

// OIS - Mouse Cursor
if (m_isNonExclusiveMouseInput)
{
    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")));
}

pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));

m_inputManager = OIS::InputManager::createInputSystem(pl);

m_keyboard = static_cast<OIS::Keyboard*>(m_inputManager->createInputObject(OIS::OISKeyboard, true));
m_mouse = static_cast<OIS::Mouse*>(m_inputManager->createInputObject(OIS::OISMouse, true));