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
void onRemoved();
void onWidgetDeleted( CInterfaceElement *e );
protected:

View file

@ -503,6 +503,10 @@ namespace NLGUI
/// Unregisters a deletion 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:
bool editorSelected;

View file

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

View file

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

View file

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

View file

@ -1088,7 +1088,6 @@ namespace NLGUI
_Views.erase(_Views.begin()+i);
delEltOrder (child);
child->onRemoved();
child->setParent( NULL );
if (!dontDelete) delete v;
return true;
}
@ -1107,7 +1106,6 @@ namespace NLGUI
_Controls.erase(_Controls.begin()+i);
delEltOrder (child);
child->onRemoved();
child->setParent( NULL );
if (!dontDelete) delete c;
return true;
}
@ -1126,7 +1124,6 @@ namespace NLGUI
_ChildrenGroups.erase(_ChildrenGroups.begin()+i);
delEltOrder (child);
child->onRemoved();
child->setParent( NULL );
if (!dontDelete) delete g;
return true;
}
@ -2477,4 +2474,16 @@ namespace NLGUI
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 );
}
}