mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-29 17:46:29 +03:00
Fix rare crash when invalidating widgets.
This commit is contained in:
@@ -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 ) {}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -33,9 +33,8 @@ class ClockImpl {
|
||||
LARGE_INTEGER mStartTime;
|
||||
LARGE_INTEGER mFrequency;
|
||||
unsigned long mTimerMask;
|
||||
|
||||
bool isPO2( Uint32 n );
|
||||
};
|
||||
|
||||
}}} // namespace EE::System::Platform
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
@@ -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 ) )
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user