Skip to content

Commit

Permalink
Merge pull request #505 from drowe67/tmiw-reporter-crash
Browse files Browse the repository at this point in the history
Don't delete from allReporterList unless disconnected.
  • Loading branch information
tmiw authored Aug 17, 2023
2 parents 44bac0f + 2442ca0 commit b310e43
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 60 deletions.
2 changes: 2 additions & 0 deletions USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes

1. Bugfixes:
* Revert BETA back to prior 1.9.0 value for waterfall. (PR #503)
* Optimize FreeDV Reporter window logic to reduce likelihood of waterfall stuttering. (PR #505)
* Fix intermittent crash during FreeDV Reporter updates. (PR #505)

## V1.9.0 August 2023

Expand Down
99 changes: 41 additions & 58 deletions src/freedv_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,48 +558,6 @@ wxString FreeDVReporterDialog::makeValidTime_(std::string timeStr)
}
}

void FreeDVReporterDialog::checkColumnsAndResize_()
{
std::map<int, bool> shouldResize;

// Process all data in table and determine which columns now have longer text
// (and thus should be auto-resized).
for (int index = 0; index < m_listSpots->GetItemCount(); index++)
{
for (int col = 0; col < NUM_COLS; col++)
{
auto str = m_listSpots->GetItemText(index, col);
auto itemFont = m_listSpots->GetItemFont(index);
int textWidth = 0;
int textHeight = 0; // Note: unused

// Note: if the font is invalid we should just use the default.
if (itemFont.IsOk())
{
GetTextExtent(str, &textWidth, &textHeight, nullptr, nullptr, &itemFont);
}
else
{
GetTextExtent(str, &textWidth, &textHeight);
}

if (textWidth > columnLengths_[col])
{
shouldResize[col] = true;
columnLengths_[col] = textWidth;
}
}
}

// Trigger auto-resize for columns as needed
for (auto& kvp : shouldResize)
{
// Note: we don't add anything to shouldResize that is false, so
// no need to check for shouldResize == true here.
m_listSpots->SetColumnWidth(kvp.first, wxLIST_AUTOSIZE_USEHEADER);
}
}

void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data)
{
bool filtered = isFiltered_(data->frequency);
Expand All @@ -617,10 +575,7 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data)

if (itemIndex >= 0 && filtered)
{
// Remove as it has been filtered out.
delete allReporterData_[data->sid];
allReporterData_.erase(data->sid);

// Remove as it has been filtered out.
delete (std::string*)m_listSpots->GetItemData(itemIndex);
m_listSpots->DeleteItem(itemIndex);

Expand All @@ -637,16 +592,16 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data)
return;
}

m_listSpots->SetItem(itemIndex, 1, data->gridSquare);
m_listSpots->SetItem(itemIndex, 2, data->version);
m_listSpots->SetItem(itemIndex, 3, data->freqString);
m_listSpots->SetItem(itemIndex, 4, data->status);
m_listSpots->SetItem(itemIndex, 5, data->txMode);
m_listSpots->SetItem(itemIndex, 6, data->lastTx);
m_listSpots->SetItem(itemIndex, 7, data->lastRxCallsign);
m_listSpots->SetItem(itemIndex, 8, data->lastRxMode);
m_listSpots->SetItem(itemIndex, 9, data->snr);
m_listSpots->SetItem(itemIndex, 10, data->lastUpdate);
setColumnForRow_(itemIndex, 1, data->gridSquare);
setColumnForRow_(itemIndex, 2, data->version);
setColumnForRow_(itemIndex, 3, data->freqString);
setColumnForRow_(itemIndex, 4, data->status);
setColumnForRow_(itemIndex, 5, data->txMode);
setColumnForRow_(itemIndex, 6, data->lastTx);
setColumnForRow_(itemIndex, 7, data->lastRxCallsign);
setColumnForRow_(itemIndex, 8, data->lastRxMode);
setColumnForRow_(itemIndex, 9, data->snr);
setColumnForRow_(itemIndex, 10, data->lastUpdate);

if (data->transmitting)
{
Expand All @@ -659,8 +614,36 @@ void FreeDVReporterDialog::addOrUpdateListIfNotFiltered_(ReporterData* data)
m_listSpots->SetItemBackgroundColour(itemIndex, wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
m_listSpots->SetItemTextColour(itemIndex, wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT));
}
}

void FreeDVReporterDialog::setColumnForRow_(int row, int col, wxString val)
{
auto oldText = m_listSpots->GetItemText(row, col);

if (oldText != val)
{
m_listSpots->SetItem(row, col, val);

auto itemFont = m_listSpots->GetItemFont(row);
int textWidth = 0;
int textHeight = 0; // Note: unused

// Note: if the font is invalid we should just use the default.
if (itemFont.IsOk())
{
GetTextExtent(val, &textWidth, &textHeight, nullptr, nullptr, &itemFont);
}
else
{
GetTextExtent(val, &textWidth, &textHeight);
}

checkColumnsAndResize_();
if (textWidth > columnLengths_[col])
{
columnLengths_[col] = textWidth;
m_listSpots->SetColumnWidth(col, wxLIST_AUTOSIZE_USEHEADER);
}
}
}

bool FreeDVReporterDialog::isFiltered_(uint64_t freq)
Expand Down Expand Up @@ -720,4 +703,4 @@ bool FreeDVReporterDialog::isFiltered_(uint64_t freq)
{
return bandForFreq != currentBandFilter_;
}
}
}
4 changes: 2 additions & 2 deletions src/freedv_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ class FreeDVReporterDialog : public wxDialog

wxString makeValidTime_(std::string timeStr);

void checkColumnsAndResize_();

void addOrUpdateListIfNotFiltered_(ReporterData* data);
bool isFiltered_(uint64_t freq);

void setColumnForRow_(int row, int col, wxString val);
};

#endif // __FREEDV_REPORTER_DIALOG__

0 comments on commit b310e43

Please sign in to comment.