This one's really starting to get to me, since I can *not* find out what's causing it. I know the exact line it crashes and everything, but I don't know why. Basically it's for my OpenGL based GUI and has to do with input handling. Whenever I press an alphabetical key the program basically crashes. But what I don't get is why it's screwing up the getWindow function, which returns a pointer to a window class. Well... this is the getWindow function:
RUIwindow* RUI::getWindow( int id )
{
for( vWit = vWindow.begin(); vWit!=vWindow.end(); vWit++ )
{
if( (*vWit)->ID == id )
{
return (*vWit);
}
}
return NULL;
}
I'm assuming something is wrong with the vector since the program still crashes even when there are no windows (which means it shouldn't loop at all, and according to some printf tests, it doesn't). This function is called a couple times during each render. It works fine, no matter how many windows are up... that is until I press a key. I'm using GLFW here, so whenever a key is pressed this is what happens:
void keyboardNormal( int key, int action )
{
gui->handleInput( RUI_INPUT_KB_CHAR, key, action );
}
void RUI::handleInput( int INPUT_TYPE, int a, int b )
{
switch( INPUT_TYPE )
{
case RUI_INPUT_KB_CHAR:
addLetter( a, b ); //This is the one getting called
break;
case RUI_INPUT_KB_SPECIAL:
addSpecial( a, b );
break;
case RUI_INPUT_MOUSE_PRESS:
onMousePress( a, b );
break;
case RUI_INPUT_MOUSE_MOVE:
onMouseMove( a, b );
break;
}
return;
}
void RUI::addLetter( unsigned char letter, unsigned char state )
{
if( hwndFocus != 255 && editFocus != 255 )
{
if( letter == RUI_KEY_BACKSPACE && getWindow( hwndFocus )->vEditBox[editFocus]->data.length() > 0 )
{
if( getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos > 0 )
{
getWindow( hwndFocus )->vEditBox[editFocus]->data.erase( getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos-1, 1 );
getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos--;
}
}
if( letter == RUI_KEY_DELETE && getWindow( hwndFocus )->vEditBox[editFocus]->data.length() > 0 )
{
if( getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos < getWindow( hwndFocus )->vEditBox[editFocus]->data.length() )
{
getWindow( hwndFocus )->vEditBox[editFocus]->data.erase( getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos, 1 );
}
}
else if( ( letter != RUI_KEY_BACKSPACE && letter != RUI_KEY_DELETE ) && getWindow( hwndFocus )->vEditBox[editFocus]->data.length() < getWindow( hwndFocus )->vEditBox[editFocus]->size )
{
std::string ltr = ""; ltr += letter;
getWindow( hwndFocus )->vEditBox[editFocus]->data.insert( getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos, ltr.c_str() );
getWindow( hwndFocus )->vEditBox[editFocus]->cursorPos++;
}
}
printf("TEST"); //This manages to get printed, so I know it's not in the function
return;
}
And after that everything returns... I assume it's not handleInput since everything works fine when mouse movement, special keys, and mouse button input is handled.
Sorry to have to come to the forums with such a question that I should be able to fix myself, but I really can't. I've been stumped on this for almost 3 days now with absolutely no progress. It's times like this I wish I had a working debugger. In fact, I spent a good few hours yesterday trying to get GDB working in Code::Blocks for me to no avail. Seems PSAPI.dll is missing an export to the NtAllocateMemory function in NT.DLL... I assume this has to do with me running with Windows 98 since past NT.DLL errors seem to have been platform specific. So that's driving me nuts, too... but I guess it's an unrelated matter. Anyways, thanks to any and all who attempt to help me out here! >_O