From 997fe458b30adfad501f6f40ca6e6d3a691e44c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 5 Feb 2024 22:03:39 -0300 Subject: [PATCH] Fix indirect memory leak on VertexBufferVBO. Added a few icons. Tried to detect a bug on the terminal emulator. Fixed Git status when file has been renamed. --- projects/linux/ee.creator.user | 4 +-- src/eepp/graphics/vertexbuffervbo.cpp | 29 ++++++++++--------- src/examples/7guis/crud/crud.cpp | 25 ++++++---------- .../eterm/terminal/terminalemulator.hpp | 2 ++ .../src/eterm/terminal/terminaldisplay.cpp | 13 +++++++-- .../src/eterm/terminal/terminalemulator.cpp | 4 +++ src/tools/ecode/iconmanager.cpp | 5 +++- src/tools/ecode/plugins/git/git.cpp | 25 ++++++++++++---- 8 files changed, 68 insertions(+), 39 deletions(-) diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index c96f571b8..db9318406 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -116,7 +116,7 @@ {388e5431-b31b-42b3-b9ad-9002d279d75d} 10 0 - 25 + 19 ../../make/linux diff --git a/src/eepp/graphics/vertexbuffervbo.cpp b/src/eepp/graphics/vertexbuffervbo.cpp index 7c1b40c79..7954b0351 100644 --- a/src/eepp/graphics/vertexbuffervbo.cpp +++ b/src/eepp/graphics/vertexbuffervbo.cpp @@ -22,19 +22,7 @@ VertexBufferVBO::VertexBufferVBO( const Uint32& vertexFlags, PrimitiveType drawT } VertexBufferVBO::~VertexBufferVBO() { - for ( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) { - if ( VERTEX_FLAG_QUERY( mVertexFlags, i ) && mArrayHandle[i] ) { - glDeleteBuffersARB( 1, (unsigned int*)&mArrayHandle[i] ); - } - } - - if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) && mElementHandle ) { - glDeleteBuffersARB( 1, (unsigned int*)&mElementHandle ); - } - - if ( GLv_3CP == GLi->version() && mVAO ) { - GLi->deleteVertexArrays( 1, &mVAO ); - } + clear(); } void VertexBufferVBO::bind() { @@ -424,6 +412,21 @@ void VertexBufferVBO::unbind() { void VertexBufferVBO::clear() { mCompiled = false; mBuffersSet = false; + + for ( Int32 i = 0; i < VERTEX_FLAGS_COUNT; i++ ) { + if ( VERTEX_FLAG_QUERY( mVertexFlags, i ) && mArrayHandle[i] ) { + glDeleteBuffersARB( 1, (unsigned int*)&mArrayHandle[i] ); + } + } + + if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_USE_INDICES ) && mElementHandle ) { + glDeleteBuffersARB( 1, (unsigned int*)&mElementHandle ); + } + + if ( GLv_3CP == GLi->version() && mVAO ) { + GLi->deleteVertexArrays( 1, &mVAO ); + } + VertexBuffer::clear(); } diff --git a/src/examples/7guis/crud/crud.cpp b/src/examples/7guis/crud/crud.cpp index 975ffa7cc..949fb5e32 100644 --- a/src/examples/7guis/crud/crud.cpp +++ b/src/examples/7guis/crud/crud.cpp @@ -142,15 +142,15 @@ EE_MAIN_FUNC int main( int, char** ) { updateModel( true, false ); filterView->setText( "" ); } ); + const auto getSelectedPersonIt = [&]() -> std::vector::iterator { + auto p = static_cast( listView->getModel() ) + ->getPerson( listView->getSelection().first() ); + auto found = std::find_if( people.begin(), people.end(), + [&p]( const Person& person ) { return p.id == person.id; } ); + return found; + }; updateBut->onClick( [&]( auto ) { - auto selPerson = static_cast( listView->getModel() ) - ->getPerson( listView->getSelection().first() ); - - auto found = - std::find_if( people.begin(), people.end(), [&selPerson]( const Person& person ) { - return selPerson.id == person.id; - } ); - + auto found = getSelectedPersonIt(); if ( found != people.end() ) { found->name = nameView->getText().toUtf8(); found->surname = surnameView->getText().toUtf8(); @@ -163,14 +163,7 @@ EE_MAIN_FUNC int main( int, char** ) { UIMessageBox::New( UIMessageBox::OK, "Select a person from the list" )->showWhenReady(); return; } - auto selPerson = static_cast( listView->getModel() ) - ->getPerson( listView->getSelection().first() ); - - auto found = - std::find_if( people.begin(), people.end(), [&selPerson]( const Person& person ) { - return selPerson.id == person.id; - } ); - + auto found = getSelectedPersonIt(); if ( found != people.end() ) { people.erase( found ); clearInputs(); diff --git a/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp b/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp index 5a61f0dbf..b1f989c94 100644 --- a/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp +++ b/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp @@ -225,6 +225,8 @@ class TerminalEmulator final { void setAllowMemoryTrimnming( bool allowMemoryTrimnming ); + Vector2i getSize() const; + private: DpyPtr mDpy; PtyPtr mPty; diff --git a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp index f31865469..607b47b5e 100644 --- a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp @@ -1236,8 +1236,8 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) { if ( mVBForeground ) mVBForeground->setQuadColor( mCurGridPos, Color::Transparent ); } else { - auto* gd = mFont->getGlyphDrawable( glyph.u, mFontSize, glyph.mode & ATTR_BOLD, glyph.mode & ATTR_ITALIC, 0, - advanceX ); + auto* gd = mFont->getGlyphDrawable( glyph.u, mFontSize, glyph.mode & ATTR_BOLD, + glyph.mode & ATTR_ITALIC, 0, advanceX ); if ( ( glyph.mode & ATTR_EMOJI ) && FontManager::instance()->getColorEmojiFont() ) { gd->setColor( Color::White ); @@ -1435,6 +1435,15 @@ Vector2i TerminalDisplay::positionToGrid( const Vector2i& pos ) { mouseY = eeclamp( (int)std::floor( relPos.y / fontSize ), 0, clipRows - 1 ); } + // All these checks are because there's a very rare bug I cannot find how it happens + auto termSize = mTerminal->getSize(); + + eeASSERT( mouseX >= 0 && mouseX <= mTerminal->getSize().x ); + eeASSERT( mouseY >= 0 && mouseY <= mTerminal->getSize().y ); + + mouseX = eeclamp( mouseX, 0, termSize.x ); + mouseY = eeclamp( mouseY, 0, termSize.y ); + return { mouseX, mouseY }; } diff --git a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp index ed3a37061..f48eaabb4 100644 --- a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp @@ -734,6 +734,10 @@ void TerminalEmulator::setAllowMemoryTrimnming( bool allowMemoryTrimnming ) { mAllowMemoryTrimnming = allowMemoryTrimnming; } +Vector2i TerminalEmulator::getSize() const { + return { mTerm.col, mTerm.row }; +} + bool TerminalEmulator::isScrolling() const { return mTerm.scr != 0; } diff --git a/src/tools/ecode/iconmanager.cpp b/src/tools/ecode/iconmanager.cpp index ab328ea53..413147f92 100644 --- a/src/tools/ecode/iconmanager.cpp +++ b/src/tools/ecode/iconmanager.cpp @@ -117,6 +117,8 @@ void IconManager::init( UISceneNode* sceneNode, FontTrueType* iconFont, FontTrue { "filetype-rb", 61880 }, { "filetype-rs", 61881 }, { "filetype-ts", 61923 }, + { "filetype-jsx", 0xf1ab }, + { "filetype-tsx", 0xf1ab }, { "filetype-yaml", 61945 }, { "filetype-yml", 61945 }, { "filetype-jpg", 61801 }, @@ -139,9 +141,10 @@ void IconManager::init( UISceneNode* sceneNode, FontTrueType* iconFont, FontTrue { "filetype-nim", 61734 }, { "filetype-xml", 61769 }, { "filetype-dockerfile", 61758 }, - { "filetype-ruby", 61880 }, { "filetype-scala", 61882 }, + { "filetype-sc", 61882 }, { "filetype-perl", 61853 }, + { "filetype-vue", 0xf1f4 }, { "file", 61766 }, { "file-symlink", 61774 }, { "folder", 0xF23B }, diff --git a/src/tools/ecode/plugins/git/git.cpp b/src/tools/ecode/plugins/git/git.cpp index 82987ae20..9e7c96740 100644 --- a/src/tools/ecode/plugins/git/git.cpp +++ b/src/tools/ecode/plugins/git/git.cpp @@ -27,13 +27,14 @@ static size_t countLines( const std::string& text ) { } static void readAllLines( const std::string_view& buf, - std::function onLineRead ) { + std::function onLineRead, + char sep = '\n' ) { auto lastNL = 0; - auto nextNL = buf.find_first_of( '\n' ); + auto nextNL = buf.find_first_of( sep ); while ( nextNL != std::string_view::npos ) { onLineRead( buf.substr( lastNL, nextNL - lastNL ) ); lastNL = nextNL + 1; - nextNL = buf.find_first_of( '\n', nextNL + 1 ); + nextNL = buf.find_first_of( sep, nextNL + 1 ); } } @@ -596,7 +597,14 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir ) bool isStagedAndModified = status.type == GitStatusType::Staged && statusStr[1] != ' '; - auto filePath = subModulePath + file; + if ( status.symbol == GitStatusChar::Renamed ) { + LuaPattern rpattern( ".*%s%-%>%s(.*)" ); + LuaPattern::Range rranges[2]; + if ( rpattern.matches( file.data(), 0, rranges, file.size() ) ) + file = file.substr( rranges[1].start, rranges[1].end - rranges[1].start ); + } + + std::string filePath = subModulePath + file; auto repo = repoName( filePath, false, projectDir ); auto repoIt = s.files.find( repo ); bool found = false; @@ -644,11 +652,18 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir ) } else if ( pattern.matches( line.data(), 0, matches, line.size() ) ) { auto inserted = line.substr( matches[1].start, matches[1].end - matches[1].start ); auto deleted = line.substr( matches[2].start, matches[2].end - matches[2].start ); - auto file = line.substr( matches[3].start, matches[3].end - matches[3].start ); + std::string file = std::string{ + line.substr( matches[3].start, matches[3].end - matches[3].start ) }; int inserts; int deletes; if ( String::fromString( inserts, inserted ) && String::fromString( deletes, deleted ) && ( inserts || deletes ) ) { + LuaPattern pattern( "(.*)%{.*%s->%s(.*)%}" ); + if ( pattern.matches( file.data(), 0, matches, file.size() ) ) { + file = file.substr( matches[1].start, matches[1].end - matches[1].start ) + + file.substr( matches[2].start, matches[2].end - matches[2].start ); + } + auto filePath = subModulePath + file; auto repo = repoName( filePath, false, projectDir ); auto repoIt = s.files.find( repo );