No active widget = bad pointer

Jekteir

25-03-2008 04:03:23

Hi, my code injects a mouse movement, and when this code runs from GUIManager::injectMouseMove():

if( (mActiveWidget->getGrabbed()) && (mActiveWidget->draggingEnabled()) )

it calls line 709 of QuickGUIWidget.cpp for

bool Widget::getGrabbed() const
{
return mGrabbed;
}


but the widget pointer isn't valid, presumably because mActiveWidget has not been set by QuickGUI. Exception!

Jek

kungfoomasta

25-03-2008 04:47:14

Are you absolutely sure its a bad pointer? The GUIManager sets the pointer in its constructor:

mActiveWidget = mWidgetContainingMouse = mActiveSheet = mDefaultSheet;

It also sets it in GUIManager::setActiveSheet:

// Update the active widget
mActiveWidget = mActiveSheet;


The active widget should never be NULL, even with a blank screen it would be the sheet. Maybe you are deleting something that was the active widget? Although I cover this case also. You'd have to give more information on how you ran into this problem, the active widget should never be an invalid pointer.

Jekteir

25-03-2008 17:32:04

You're right, the widget pointer was valid and set before the widget was deleted. Roughly, my code does this with widgets:

QuickGUI::Window *inputWdw = guiSheet->createWindow();
inputWdw->hideCloseButton();
inputWdw->getTitleBar()->setText(caption);
inputWdw->allowResizing(false);
inputWdw->setUseBorders(false);

...
QuickGUI::Widget *currentWidget = inputWdw->createTextBox(wgtName);
currentWidget->setUseBorders(false);
dynamic_cast<QuickGUI::TextBox*>(currentWidget)->setText(wgtData);
dynamic_cast<QuickGUI::TextBox*>(currentWidget)->focus();

...
currentWidget->setPosition(currentLineWidth + 10,totalHeight);
currentWidget->setWidth(wgtWidth);
currentWidget->setHeight(wgtHeight);

...
inputWdw->removeAndDestroyAllChildWidgets();
...
guiMgr->injectMouseMove(int(newXRel),int(newYRel));

So I assume the problem is that you're deleting the child widgets in removeAndDestroyAllChildWidgets() without checking whether each widget is the active widget for the GUI manager and resetting that pointer if it is? You know, it might be safer to call/create a function for deleting a widget which all widget deletions in QuickGUI have to use -- one which does the event-firing you do in removeAndDestroyAllChildWidgets(), but also runs checks like whether it's the active widget/widget with focus, whether it's referred/pointer to in any other places... delete *widget just seems too blunt :)

Jek

kungfoomasta

25-03-2008 18:47:03

I'm not sure if removeAndDestroyAllChildWidgets does any checking if the active widget is going to be deleted, I will have to check it out. You're right there should be one function to handle it all, so there is less to maintain.