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" )
{ {
return _ViewText->getText().toString(); if( _ViewText != NULL )
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" )
{ {
return toString( _ViewText->getUnderlined() ); if( _ViewText != NULL )
return toString( _ViewText->getUnderlined() );
else
return std::string( "" );
} }
else else
if( name == "text_posref" ) if( name == "text_posref" )
@ -280,7 +284,8 @@ namespace NLGUI
else else
if( name == "hardtext" ) if( name == "hardtext" )
{ {
_ViewText->setText( value ); if( _ViewText != NULL )
_ViewText->setText( value );
return; return;
} }
else else
@ -303,8 +308,10 @@ namespace NLGUI
if( name == "text_underlined" ) if( name == "text_underlined" )
{ {
bool b; bool b;
if( fromString( value, b ) ) if( _ViewText != NULL )
_ViewText->setUnderlined( b ); if( fromString( value, b ) )
_ViewText->setUnderlined( b );
return; return;
} }
else else
@ -813,32 +820,35 @@ namespace NLGUI
} }
} }
// Setup ViewText color // Setup ViewText color
if ( pTxId==_TextureIdNormal || editorMode ) if( _ViewText != NULL )
{ {
if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A; if ( pTxId==_TextureIdNormal || editorMode )
else viewTextColor= _TextColorNormal; {
_ViewText->setColor(viewTextColor); if(_TextHeaderColor) viewTextColor.A= _TextColorNormal.A;
_ViewText->setShadowColor(_TextShadowColorNormal); else viewTextColor= _TextColorNormal;
_ViewText->setModulateGlobalColor(_TextModulateGlobalColorNormal); _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 ); _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 );
}
}