FIXED: Deleting the CViewText of CCtrlTextButton should no longer lead to crashes.

This commit is contained in:
dfighter1985 2013-03-10 00:56:27 +01:00
parent 31c6fc459f
commit 69954d6e8b
6 changed files with 73 additions and 37 deletions

View file

@ -125,6 +125,7 @@ namespace NLGUI
REFLECT_EXPORT_END REFLECT_EXPORT_END
void onRemoved(); void onRemoved();
void onWidgetDeleted( CInterfaceElement *e );
protected: protected:

View file

@ -503,6 +503,10 @@ namespace NLGUI
/// Unregisters a deletion watcher /// Unregisters a deletion watcher
static void unregisterDeletionWatcher( IDeletionWatcher *watcher ); static void unregisterDeletionWatcher( IDeletionWatcher *watcher );
/// Called when the widget is deleted,
/// so other widgets in the group can check if it belongs to them
virtual void onWidgetDeleted( CInterfaceElement *e ){}
protected: protected:
bool editorSelected; bool editorSelected;

View file

@ -322,6 +322,8 @@ namespace NLGUI
// Return the current Depth, with no ZBias applied. // Return the current Depth, with no ZBias applied.
float getDepthForZSort() const { return _DepthForZSort; } float getDepthForZSort() const { return _DepthForZSort; }
void onWidgetDeleted( CInterfaceElement *e );
protected: protected:
void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH); void makeNewClip (sint32 &oldClipX, sint32 &oldClipY, sint32 &oldClipW, sint32 &oldClipH);

View file

@ -65,10 +65,8 @@ namespace NLGUI
if( _ViewText != NULL ) if( _ViewText != NULL )
{ {
if( _Parent != NULL ) if( _Parent != NULL )
_Parent->delView( _ViewText ); _Parent->delView( _ViewText, true );
else
delete _ViewText; delete _ViewText;
_ViewText = NULL; _ViewText = NULL;
} }
} }
@ -124,7 +122,10 @@ namespace NLGUI
else else
if( name == "hardtext" ) if( name == "hardtext" )
{ {
if( _ViewText != NULL )
return _ViewText->getText().toString(); return _ViewText->getText().toString();
else
return std::string( "" );
} }
else else
if( name == "text_y" ) if( name == "text_y" )
@ -139,7 +140,10 @@ namespace NLGUI
else else
if( name == "text_underlined" ) if( name == "text_underlined" )
{ {
if( _ViewText != NULL )
return toString( _ViewText->getUnderlined() ); return toString( _ViewText->getUnderlined() );
else
return std::string( "" );
} }
else else
if( name == "text_posref" ) if( name == "text_posref" )
@ -280,6 +284,7 @@ namespace NLGUI
else else
if( name == "hardtext" ) if( name == "hardtext" )
{ {
if( _ViewText != NULL )
_ViewText->setText( value ); _ViewText->setText( value );
return; return;
} }
@ -303,8 +308,10 @@ namespace NLGUI
if( name == "text_underlined" ) if( name == "text_underlined" )
{ {
bool b; bool b;
if( _ViewText != NULL )
if( fromString( value, b ) ) if( fromString( value, b ) )
_ViewText->setUnderlined( b ); _ViewText->setUnderlined( b );
return; return;
} }
else else
@ -813,6 +820,8 @@ namespace NLGUI
} }
} }
// Setup ViewText color // Setup ViewText color
if( _ViewText != NULL )
{
if ( pTxId==_TextureIdNormal || editorMode ) if ( pTxId==_TextureIdNormal || editorMode )
{ {
if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A;
@ -840,6 +849,7 @@ namespace NLGUI
if(getFrozen() && getFrozenHalfTone()) if(getFrozen() && getFrozenHalfTone())
_ViewText->setAlpha(_ViewText->getAlpha()>>2); _ViewText->setAlpha(_ViewText->getAlpha()>>2);
} }
}
// *************************************************************************** // ***************************************************************************
@ -978,5 +988,11 @@ namespace NLGUI
_Parent->delView( _ViewText, true ); _Parent->delView( _ViewText, true );
} }
} }
void CCtrlTextButton::onWidgetDeleted( CInterfaceElement *e )
{
if( e == _ViewText )
_ViewText = NULL;
}
} }

View file

@ -47,7 +47,11 @@ namespace NLGUI
} }
if( editorMode ) if( editorMode )
{
notifyDeletionWatchers(); notifyDeletionWatchers();
if( _Parent != NULL )
_Parent->onWidgetDeleted( this );
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View file

@ -1088,7 +1088,6 @@ namespace NLGUI
_Views.erase(_Views.begin()+i); _Views.erase(_Views.begin()+i);
delEltOrder (child); delEltOrder (child);
child->onRemoved(); child->onRemoved();
child->setParent( NULL );
if (!dontDelete) delete v; if (!dontDelete) delete v;
return true; return true;
} }
@ -1107,7 +1106,6 @@ namespace NLGUI
_Controls.erase(_Controls.begin()+i); _Controls.erase(_Controls.begin()+i);
delEltOrder (child); delEltOrder (child);
child->onRemoved(); child->onRemoved();
child->setParent( NULL );
if (!dontDelete) delete c; if (!dontDelete) delete c;
return true; return true;
} }
@ -1126,7 +1124,6 @@ namespace NLGUI
_ChildrenGroups.erase(_ChildrenGroups.begin()+i); _ChildrenGroups.erase(_ChildrenGroups.begin()+i);
delEltOrder (child); delEltOrder (child);
child->onRemoved(); child->onRemoved();
child->setParent( NULL );
if (!dontDelete) delete g; if (!dontDelete) delete g;
return true; return true;
} }
@ -2477,4 +2474,16 @@ namespace NLGUI
return "IMPLEMENT ME!"; return "IMPLEMENT ME!";
} }
void CInterfaceGroup::onWidgetDeleted( CInterfaceElement *e )
{
for( std::vector< CViewBase* >::iterator itr = _Views.begin(); itr != _Views.end(); ++itr )
(*itr)->onWidgetDeleted( e );
for( std::vector< CCtrlBase* >::iterator itr = _Controls.begin(); itr != _Controls.end(); ++itr )
(*itr)->onWidgetDeleted( e );
for( std::vector< CInterfaceGroup* >::iterator itr = _ChildrenGroups.begin(); itr != _ChildrenGroups.end(); ++itr )
(*itr)->onWidgetDeleted( e );
} }
}