Fix rare crash when invalidating widgets.

This commit is contained in:
Martín Lucas Golini
2024-02-11 23:41:38 -03:00
parent eccf1f1cba
commit 7cf8aef499
8 changed files with 46 additions and 16 deletions

View File

@@ -23,6 +23,25 @@ class ScopedOp {
std::function<void()> mEndOp;
};
class ScopedOpOptional {
public:
explicit ScopedOpOptional( bool cond, std::function<void()> startOp,
std::function<void()> endOp = nullptr ) :
cond( cond ), mEndOp( endOp ) {
if ( cond && startOp )
startOp();
}
~ScopedOpOptional() {
if ( cond && mEndOp )
mEndOp();
}
private:
bool cond;
std::function<void()> mEndOp;
};
class BoolScopedOp {
public:
explicit BoolScopedOp( bool& boolRef ) : boolRef( boolRef ) {}

View File

@@ -49,6 +49,8 @@ class EE_API ModelIndex {
ModelIndex siblingAtColumn( int column ) const;
std::string toString() const;
protected:
friend class Model;
const Model* mModel{ nullptr };

View File

@@ -99,9 +99,9 @@ class EE_API UISceneNode : public SceneNode {
UIWidget* getRoot() const;
void invalidateStyle( UIWidget* widget );
void invalidateStyle( UIWidget* widget, bool tryReinsert = false );
void invalidateStyleState( UIWidget* widget, bool disableCSSAnimations = false );
void invalidateStyleState( UIWidget* widget, bool disableCSSAnimations = false, bool tryReinsert = false );
void invalidateLayout( UILayout* widget );

View File

@@ -81,10 +81,6 @@ unsigned long ClockImpl::getElapsedTime() {
return newMicro;
}
bool ClockImpl::isPO2( Uint32 n ) {
return ( n & ( n - 1 ) ) == 0;
}
}}} // namespace EE::System::Platform
#endif

View File

@@ -33,9 +33,8 @@ class ClockImpl {
LARGE_INTEGER mStartTime;
LARGE_INTEGER mFrequency;
unsigned long mTimerMask;
bool isPO2( Uint32 n );
};
}}} // namespace EE::System::Platform
#endif

View File

@@ -16,6 +16,11 @@ ModelIndex ModelIndex::siblingAtColumn( int column ) const {
return sibling( row(), column );
}
std::string ModelIndex::toString() const {
return String::format( "ModelIndex{col: %ld - row: %ld, internalId: %ld}", mColumn, mRow,
mInternalId );
}
Variant ModelIndex::data( ModelRole role ) const {
if ( !isValid() )
return {};

View File

@@ -664,14 +664,18 @@ UIWidget* UISceneNode::getRoot() const {
return mRoot;
}
void UISceneNode::invalidateStyle( UIWidget* node ) {
void UISceneNode::invalidateStyle( UIWidget* node, bool tryReinsert ) {
eeASSERT( NULL != node );
if ( node->isClosing() )
return;
if ( mDirtyStyle.count( node ) > 0 )
return;
if ( mDirtyStyle.count( node ) > 0 ) {
if ( !tryReinsert )
return;
else
mDirtyStyle.erase( node );
}
for ( auto& dirtyNode : mDirtyStyle )
if ( NULL != dirtyNode && dirtyNode->isParentOf( node ) )
@@ -689,14 +693,19 @@ void UISceneNode::invalidateStyle( UIWidget* node ) {
mDirtyStyle.insert( node );
}
void UISceneNode::invalidateStyleState( UIWidget* node, bool disableCSSAnimations ) {
void UISceneNode::invalidateStyleState( UIWidget* node, bool disableCSSAnimations,
bool tryReinsert ) {
eeASSERT( NULL != node );
if ( node->isClosing() )
return;
if ( mDirtyStyleState.count( node ) > 0 )
return;
if ( mDirtyStyleState.count( node ) > 0 ) {
if ( !tryReinsert )
return;
else
mDirtyStyleState.erase( node );
}
for ( auto& dirtyNode : mDirtyStyleState )
if ( NULL != dirtyNode && dirtyNode->isParentOf( node ) )

View File

@@ -994,8 +994,8 @@ void UIWidget::onThemeLoaded() {}
void UIWidget::onParentChange() {
if ( !isSceneNodeLoading() && !isLoadingState() ) {
getUISceneNode()->invalidateStyle( this );
getUISceneNode()->invalidateStyleState( this, true );
getUISceneNode()->invalidateStyle( this, true );
getUISceneNode()->invalidateStyleState( this, true, true );
}
}