Skip to content

Commit

Permalink
MainWindow: fixed some bugs related to handling of null transport in …
Browse files Browse the repository at this point in the history
…in add-instrument menu. Fixes #777.
  • Loading branch information
azonenberg committed Oct 10, 2024
1 parent 9923605 commit 5711d44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,9 @@ void MainWindow::AddToRecentInstrumentList(shared_ptr<SCPIInstrument> inst)
if(inst == nullptr)
return;

LogTrace("Adding instrument \"%s\" to recent instrument list\n", inst->m_nickname.c_str());
LogTrace("Adding instrument \"%s\" to recent instrument list (had %zu)\n",
inst->m_nickname.c_str(), m_recentInstruments.size());
LogIndenter li;

auto now = time(NULL);

Expand All @@ -1499,6 +1501,7 @@ void MainWindow::AddToRecentInstrumentList(shared_ptr<SCPIInstrument> inst)
inst->GetDriverName() + ":" +
inst->GetTransportName() + ":" +
inst->GetTransportConnectionString();
LogTrace("Connection string: %s\n", connectionString.c_str());
m_recentInstruments[connectionString] = now;

//Delete anything old
Expand All @@ -1517,8 +1520,12 @@ void MainWindow::AddToRecentInstrumentList(shared_ptr<SCPIInstrument> inst)
}
}

LogTrace("Removing oldest instrument (%s) to make room\n", oldestPath.c_str());
m_recentInstruments.erase(oldestPath);
}

LogTrace("Added (now have %zu total recent instruments)\n", m_recentInstruments.size());
SaveRecentInstrumentList();
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/ngscopeclient/MainWindow_Menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,17 @@ void MainWindow::DoAddSubMenu(
for(auto cstring : cstrings)
{
auto fields = explode(cstring, ':');

//make sure it's well formed
if(fields.size() < 4)
continue;
{
//Special case: null transport allows 3 fields
if( (fields.size() == 3) && (fields[2] == "null") )
{}

else
continue;
}

auto nick = fields[0];
auto drivername = fields[1];
Expand All @@ -333,9 +342,13 @@ void MainWindow::DoAddSubMenu(
{
if(ImGui::MenuItem(nick.c_str()))
{
auto path = fields[3];
for(size_t j=4; j<fields.size(); j++)
path = path + ":" + fields[j];
string path;
if(fields.size() >= 4)
{
path = fields[3];
for(size_t j=4; j<fields.size(); j++)
path = path + ":" + fields[j];
}

auto transport = MakeTransport(transname, path);
if(transport != nullptr)
Expand Down

0 comments on commit 5711d44

Please sign in to comment.