From 1ac37e14686c095e49ea3837c09853d17cdc9bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 21 Nov 2021 14:49:50 -0300 Subject: [PATCH] ecode: Fixed some crashes. Changed default python linter. --- bin/assets/linters/linters.json | 5 ++-- include/eepp/ui/abstract/uiabstractview.hpp | 2 ++ include/eepp/window/engine.hpp | 3 +++ src/eepp/graphics/texture.cpp | 28 ++++++++++---------- src/eepp/graphics/textureloader.cpp | 3 +-- src/eepp/ui/abstract/uiabstracttableview.cpp | 13 +++++++-- src/eepp/ui/abstract/uiabstractview.cpp | 12 ++++++++- src/eepp/ui/models/filesystemmodel.cpp | 5 ++-- src/eepp/window/engine.cpp | 4 +++ src/tools/codeeditor/filesystemlistener.cpp | 7 +++-- 10 files changed, 56 insertions(+), 26 deletions(-) diff --git a/bin/assets/linters/linters.json b/bin/assets/linters/linters.json index 04519a51a..69e0267a2 100644 --- a/bin/assets/linters/linters.json +++ b/bin/assets/linters/linters.json @@ -18,9 +18,8 @@ }, { "file_patterns": ["%.py$"], - "warning_pattern": "[^:]:(%d+):(%d+):%s([%w]+:%s[^\n]*)", - "column_starts_at_zero": true, - "command": "pylint --disable=C0114,C0115,C0116,C0103 --score=n $FILENAME" + "warning_pattern": "[^:]:(%d+):(%d+):%s([^\n]+)", + "command": "pycodestyle --ignore=E402 $FILENAME" }, { "file_patterns": ["%.sh$"], diff --git a/include/eepp/ui/abstract/uiabstractview.hpp b/include/eepp/ui/abstract/uiabstractview.hpp index a144f1cef..c9cb12753 100644 --- a/include/eepp/ui/abstract/uiabstractview.hpp +++ b/include/eepp/ui/abstract/uiabstractview.hpp @@ -79,6 +79,8 @@ class EE_API UIAbstractView : public UIScrollableWidget { virtual void onModelSelectionChange(); + void modelUpdate( unsigned flags ); + UIAbstractView( const std::string& tag ); virtual ~UIAbstractView(); diff --git a/include/eepp/window/engine.hpp b/include/eepp/window/engine.hpp index 97eea6f05..382bc96a6 100644 --- a/include/eepp/window/engine.hpp +++ b/include/eepp/window/engine.hpp @@ -125,6 +125,9 @@ class EE_API Engine { /** @return The id of the thread that was used to initialize the OpenGL Context. */ Uint32 getMainThreadId(); + /** @returns True if the current thread is the main thread. */ + bool isMainThread() const; + /** @return The instance of platform class that provides some helpers for some platforms */ PlatformHelper* getPlatformHelper(); diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index a2cba6091..aa3b4abb6 100644 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -84,8 +84,8 @@ Texture::~Texture() { void Texture::deleteTexture() { if ( mTexture ) { unsigned int Texture = static_cast( mTexture ); - bool threaded = Engine::instance()->isSharedGLContextEnabled() && - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threaded = + Engine::instance()->isSharedGLContextEnabled() && !Engine::instance()->isMainThread(); if ( threaded ) Engine::instance()->getCurrentWindow()->setGLContextThread(); @@ -139,8 +139,8 @@ void Texture::setCoordinateType( const CoordinateType& coordinateType ) { } Uint8* Texture::iLock( const bool& ForceRGBA, const bool& KeepFormat ) { - bool threaded = Engine::instance()->isSharedGLContextEnabled() && - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threaded = + Engine::instance()->isSharedGLContextEnabled() && !Engine::instance()->isMainThread(); #ifndef EE_GLES if ( !( mFlags & TEX_FLAG_LOCKED ) ) { @@ -323,8 +323,8 @@ void Texture::iTextureFilter( const Filter& filter ) { if ( mTexture ) { mFilter = filter; - bool threaded = Engine::instance()->isSharedGLContextEnabled() && - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threaded = + Engine::instance()->isSharedGLContextEnabled() && !Engine::instance()->isMainThread(); if ( threaded ) Engine::instance()->getCurrentWindow()->setGLContextThread(); @@ -460,8 +460,8 @@ void Texture::reload() { Int32 width = (Int32)mWidth; Int32 height = (Int32)mHeight; - bool threaded = Engine::instance()->isSharedGLContextEnabled() && - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threaded = + Engine::instance()->isSharedGLContextEnabled() && !Engine::instance()->isMainThread(); if ( threaded ) Engine::instance()->getCurrentWindow()->setGLContextThread(); @@ -539,8 +539,8 @@ static unsigned int convertPixelFormatToGLFormat( Image::PixelFormat pf ) { void Texture::update( const Uint8* pixels, Uint32 width, Uint32 height, Uint32 x, Uint32 y, PixelFormat pf ) { if ( NULL != pixels && mTexture && x + width <= mWidth && y + height <= mHeight ) { - bool threaded = Engine::instance()->isSharedGLContextEnabled() && - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threaded = + Engine::instance()->isSharedGLContextEnabled() && !Engine::instance()->isMainThread(); if ( threaded ) Engine::instance()->getCurrentWindow()->setGLContextThread(); @@ -576,8 +576,8 @@ void Texture::update( Image* image, Uint32 x, Uint32 y ) { } void Texture::replace( Image* image ) { - bool threaded = Engine::instance()->isSharedGLContextEnabled() && - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threaded = + Engine::instance()->isSharedGLContextEnabled() && !Engine::instance()->isMainThread(); if ( threaded ) Engine::instance()->getCurrentWindow()->setGLContextThread(); @@ -718,8 +718,8 @@ void Texture::drawEx( Float x, Float y, Float width, Float height, const Float& Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h ); - Float sw = ( Float )( Sector.Right - Sector.Left ); - Float sh = ( Float )( Sector.Bottom - Sector.Top ); + Float sw = (Float)( Sector.Right - Sector.Left ); + Float sh = (Float)( Sector.Bottom - Sector.Top ); Float tx = width / sw; Float ty = height / sh; Int32 ttx = (Int32)tx; diff --git a/src/eepp/graphics/textureloader.cpp b/src/eepp/graphics/textureloader.cpp index 715c21028..e4c845de7 100644 --- a/src/eepp/graphics/textureloader.cpp +++ b/src/eepp/graphics/textureloader.cpp @@ -355,8 +355,7 @@ void TextureLoader::loadFromPixels() { : flags; flags = ( mCompressTexture ) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags; - bool threadedLoad = - Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); + bool threadedLoad = !Engine::instance()->isMainThread(); if ( threadedLoad && Engine::instance()->isSharedGLContextEnabled() ) { Engine::instance()->getCurrentWindow()->setGLContextThread(); diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index a6931ff75..6fc8bb5be 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,6 +6,7 @@ #include #include #include +#include namespace EE { namespace UI { namespace Abstract { @@ -72,8 +74,15 @@ size_t UIAbstractTableView::getItemCount() const { } void UIAbstractTableView::onModelUpdate( unsigned flags ) { - UIAbstractView::onModelUpdate( flags ); - createOrUpdateColumns(); + if ( !Engine::instance()->isMainThread() ) { + runOnMainThread( [&] { + modelUpdate( flags ); + createOrUpdateColumns(); + } ); + } else { + UIAbstractView::onModelUpdate( flags ); + createOrUpdateColumns(); + } } void UIAbstractTableView::createOrUpdateColumns() { diff --git a/src/eepp/ui/abstract/uiabstractview.cpp b/src/eepp/ui/abstract/uiabstractview.cpp index d2419fde6..da6d38532 100644 --- a/src/eepp/ui/abstract/uiabstractview.cpp +++ b/src/eepp/ui/abstract/uiabstractview.cpp @@ -1,4 +1,6 @@ +#include #include +#include namespace EE { namespace UI { namespace Abstract { @@ -42,7 +44,7 @@ void UIAbstractView::setModel( std::shared_ptr model ) { onModelUpdate( Model::InvalidateAllIndexes ); } -void UIAbstractView::onModelUpdate( unsigned flags ) { +void UIAbstractView::modelUpdate( unsigned flags ) { if ( !getModel() || ( flags & Model::InvalidateAllIndexes ) ) { getSelection().clear(); } else { @@ -51,6 +53,14 @@ void UIAbstractView::onModelUpdate( unsigned flags ) { } } +void UIAbstractView::onModelUpdate( unsigned flags ) { + if ( !Engine::instance()->isMainThread() ) { + runOnMainThread( [&] { modelUpdate( flags ); } ); + } else { + modelUpdate( flags ); + } +} + void UIAbstractView::onModelSelectionChange() { if ( getModel() && mOnSelection && getSelection().first().isValid() ) mOnSelection( getSelection().first() ); diff --git a/src/eepp/ui/models/filesystemmodel.cpp b/src/eepp/ui/models/filesystemmodel.cpp index 42a08786c..1419740f8 100644 --- a/src/eepp/ui/models/filesystemmodel.cpp +++ b/src/eepp/ui/models/filesystemmodel.cpp @@ -42,7 +42,6 @@ const FileSystemModel::Node& FileSystemModel::Node::getChild( const size_t& inde void FileSystemModel::Node::invalidate() { mHasTraversed = false; mInfoDirty = true; - mChildren.clear(); } FileSystemModel::Node* FileSystemModel::Node::findChildName( const std::string& name, @@ -72,6 +71,7 @@ void FileSystemModel::Node::traverseIfNeeded( const FileSystemModel& model ) { if ( !mInfo.isDirectory() || mHasTraversed ) return; mHasTraversed = true; + mChildren.clear(); auto files = FileSystem::filesInfoGetInPath( mInfo.getFilepath(), true, model.getDisplayConfig().sortByName, @@ -130,7 +130,8 @@ FileSystemModel::FileSystemModel( const std::string& rootPath, const FileSystemM mRealRootPath( FileSystem::getRealPath( rootPath ) ), mMode( mode ), mDisplayConfig( displayConfig ) { - update(); + mRoot = std::make_unique( mRootPath, *this ); + onModelUpdate(); } const std::string& FileSystemModel::getRootPath() const { diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index 08bcbd39c..f01e83bfe 100644 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -369,6 +369,10 @@ Uint32 Engine::getMainThreadId() { return mMainThreadId; } +bool Engine::isMainThread() const { + return Thread::getCurrentThreadId() == Engine::instance()->getMainThreadId(); +} + PlatformHelper* Engine::getPlatformHelper() { if ( NULL == mPlatformHelper ) { #if DEFAULT_BACKEND == BACKEND_SDL2 diff --git a/src/tools/codeeditor/filesystemlistener.cpp b/src/tools/codeeditor/filesystemlistener.cpp index 367d8a228..b22150fa5 100644 --- a/src/tools/codeeditor/filesystemlistener.cpp +++ b/src/tools/codeeditor/filesystemlistener.cpp @@ -15,8 +15,11 @@ void FileSystemListener::handleFileAction( efsw::WatchID, const std::string& dir case efsw::Actions::Moved: { auto* node = mFileSystemModel.get()->getNodeFromPath( file.getFilepath(), true, false ); if ( node ) { - node->invalidate(); - mFileSystemModel.get()->invalidate(); + if ( !mFileSystemModel.get()->getDisplayConfig().ignoreHidden || + !file.isHidden() ) { + node->invalidate(); + mFileSystemModel.get()->invalidate(); + } } if ( mDirTree )