Skip to content

Commit

Permalink
Fix crash when re-running build while currently running a target bina…
Browse files Browse the repository at this point in the history
…ry. Separate processes from build and run.
  • Loading branch information
SpartanJ committed Nov 25, 2024
1 parent 5bf9b89 commit 9f18c81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/tools/ecode/projectbuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ void ProjectBuildManager::cancelBuild() {

void ProjectBuildManager::cancelRun() {
mCancelRun = true;
if ( mProcess ) {
mProcess->destroy();
mProcess->kill();
if ( mProcessRun ) {
mProcessRun->destroy();
mProcessRun->kill();
}
}

Expand Down Expand Up @@ -891,6 +891,8 @@ void ProjectBuildManager::runBuild( const std::string& buildName, const std::str

for ( const auto& cmd : res.cmds ) {
int progress = c > 0 ? c / (Float)totSteps : 0;
if ( mProcess )
mProcess->kill();
mProcess = std::make_unique<Process>();
auto options = Process::SearchUserPath | Process::NoWindow | Process::CombinedStdoutStderr;
if ( !cmd.config.clearSysEnv )
Expand Down Expand Up @@ -1001,7 +1003,9 @@ void ProjectBuildManager::runApp( const ProjectBuildCommand& cmd, const ProjectB
}
};

mProcess = std::make_unique<Process>();
if ( mProcessRun )
mProcessRun->kill();
mProcessRun = std::make_unique<Process>();

auto options = Process::SearchUserPath | Process::CombinedStdoutStderr | Process::NoWindow;
if ( !cmd.config.clearSysEnv )
Expand All @@ -1023,31 +1027,31 @@ void ProjectBuildManager::runApp( const ProjectBuildCommand& cmd, const ProjectB
nullptr );
}

if ( mProcess->create( cmd.cmd, cmd.args, options, toUnorderedMap( res.envs ),
cmd.workingDir ) ) {
if ( mProcessRun->create( cmd.cmd, cmd.args, options, toUnorderedMap( res.envs ),
cmd.workingDir ) ) {
std::string buffer( 4096, '\0' );
unsigned bytesRead = 0;
int returnCode = 0;
do {
bytesRead = mProcess->readStdOut( buffer );
bytesRead = mProcessRun->readStdOut( buffer );
std::string data( buffer.substr( 0, bytesRead ) );
if ( progressFn )
progressFn( 0, std::move( data ), &cmd );
} while ( bytesRead != 0 && mProcess->isAlive() && !mShuttingDown && !mCancelRun );
} while ( bytesRead != 0 && mProcessRun->isAlive() && !mShuttingDown && !mCancelRun );

if ( mShuttingDown || mCancelRun ) {
if ( mProcess )
mProcess->kill();
if ( mProcessRun )
mProcessRun->kill();
mCancelRun = false;
printElapsed();
if ( doneFn )
doneFn( EXIT_FAILURE, &cmd );
return;
}

if ( mProcess ) {
mProcess->join( &returnCode );
mProcess->destroy();
if ( mProcessRun ) {
mProcessRun->join( &returnCode );
mProcessRun->destroy();
}

if ( returnCode != EXIT_SUCCESS ) {
Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/projectbuild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class ProjectBuildManager {
UITab* mTab{ nullptr };
App* mApp{ nullptr };
std::unique_ptr<Process> mProcess;
std::unique_ptr<Process> mProcessRun;
ProjectBuild mNewBuild;
bool mLoadedWithBuilds{ false };
bool mLoading{ false };
Expand Down

0 comments on commit 9f18c81

Please sign in to comment.