Freqman memory fix (#1177)

* Cleanings and setting the limit to a working for all apps one
* fixing a guru memory errors, renaming a leftover variable
* removed unneeded set_dirty
This commit is contained in:
gullradriel
2023-06-22 17:34:20 +02:00
committed by GitHub
parent f22808f8ca
commit 7331979107
6 changed files with 75 additions and 89 deletions

View File

@@ -81,14 +81,11 @@ void FreqManBaseView::change_category(int32_t category_id) {
if (file_list.empty()) return;
std::vector<freqman_entry>().swap(database);
if (!load_freqman_file(file_list[categories[category_id].second], database)) {
error_ = ERROR_ACCESS;
}
menu_view.set_db(database);
freqlist_view.set_db(database);
text_empty.hidden(!database.empty());
menu_view.set_dirty();
set_dirty();
}
@@ -162,10 +159,14 @@ FrequencySaveView::FrequencySaveView(
};
}
FrequencyLoadView::~FrequencyLoadView() {
std::vector<freqman_entry>().swap(database);
}
void FrequencyLoadView::refresh_widgets(const bool v) {
menu_view.hidden(v);
freqlist_view.hidden(v);
text_empty.hidden(!v);
// display.fill_rectangle(menu_view.screen_rect(), Color::black());
// display.fill_rectangle(freqlist_view.screen_rect(), Color::black());
set_dirty();
}
@@ -176,17 +177,14 @@ FrequencyLoadView::FrequencyLoadView(
refresh_widgets(v);
};
add_children({&menu_view,
add_children({&freqlist_view,
&text_empty});
// Resize menu view to fill screen
menu_view.set_parent_rect({0, 3 * 8, 240, 30 * 8});
menu_view.on_select = [&nav, this](FreqManUIList&) {
nav_.pop();
auto& entry = database[menu_view.get_index()];
freqlist_view.set_parent_rect({0, 3 * 8, 240, 30 * 8});
freqlist_view.on_select = [&nav, this](FreqManUIList&) {
auto& entry = database[freqlist_view.get_index()];
if (entry.type == RANGE) {
// User chose a frequency range entry
if (on_range_loaded)
@@ -199,18 +197,21 @@ FrequencyLoadView::FrequencyLoadView(
if (on_frequency_loaded)
on_frequency_loaded(entry.frequency_a);
}
// swap with empty vector to ensure memory is immediately released
std::vector<freqman_entry>().swap(database);
nav_.pop();
};
}
void FrequencyManagerView::on_edit_freq(rf::Frequency f) {
database[menu_view.get_index()].frequency_a = f;
database[freqlist_view.get_index()].frequency_a = f;
save_freqman_file(file_list[categories[current_category_id].second], database);
change_category(current_category_id);
}
void FrequencyManagerView::on_edit_desc(NavigationView& nav) {
text_prompt(nav, desc_buffer, 28, [this](std::string& buffer) {
database[menu_view.get_index()].description = buffer;
database[freqlist_view.get_index()].description = buffer;
save_freqman_file(file_list[categories[current_category_id].second], database);
change_category(current_category_id);
});
@@ -230,7 +231,7 @@ void FrequencyManagerView::on_delete() {
delete_freqman_file(file_list[categories[current_category_id].second]);
refresh_list();
} else {
database.erase(database.begin() + menu_view.get_index());
database.erase(database.begin() + freqlist_view.get_index());
save_freqman_file(file_list[categories[current_category_id].second], database);
}
change_category(current_category_id);
@@ -241,10 +242,9 @@ void FrequencyManagerView::refresh_widgets(const bool v) {
button_edit_desc.hidden(v);
button_delete.hidden(v);
text_empty.hidden(!v);
menu_view.hidden(v);
menu_view.set_dirty();
freqlist_view.hidden(v);
labels.hidden(v);
// display.fill_rectangle(menu_view.screen_rect(), Color::black());
// display.fill_rectangle(freqlist_view.screen_rect(), Color::black());
set_dirty();
}
@@ -261,13 +261,13 @@ FrequencyManagerView::FrequencyManagerView(
add_children({&labels,
&button_new_category,
&menu_view,
&freqlist_view,
&text_empty,
&button_edit_freq,
&button_edit_desc,
&button_delete});
menu_view.on_select = [this](FreqManUIList&) {
freqlist_view.on_select = [this](FreqManUIList&) {
button_edit_freq.focus();
};
@@ -280,7 +280,7 @@ FrequencyManagerView::FrequencyManagerView(
if (database.empty()) {
database.push_back({0, 0, "", SINGLE});
}
auto new_view = nav.push<FrequencyKeypadView>(database[menu_view.get_index()].frequency_a);
auto new_view = nav.push<FrequencyKeypadView>(database[freqlist_view.get_index()].frequency_a);
new_view->on_changed = [this](rf::Frequency f) {
on_edit_freq(f);
};
@@ -290,7 +290,7 @@ FrequencyManagerView::FrequencyManagerView(
if (database.empty()) {
database.push_back({0, 0, "", SINGLE});
}
desc_buffer = database[menu_view.get_index()].description;
desc_buffer = database[freqlist_view.get_index()].description;
on_edit_desc(nav);
};

View File

@@ -64,7 +64,7 @@ class FreqManBaseView : public View {
14,
{}};
FreqManUIList menu_view{
FreqManUIList freqlist_view{
{0, 3 * 8, 240, 23 * 8}};
Text text_empty{
@@ -116,6 +116,7 @@ class FrequencyLoadView : public FreqManBaseView {
std::function<void(rf::Frequency, rf::Frequency)> on_range_loaded{};
FrequencyLoadView(NavigationView& nav);
~FrequencyLoadView();
std::string title() const override { return "Load freq."; };

View File

@@ -39,15 +39,13 @@ void ReconView::set_loop_config(bool v) {
void ReconView::clear_freqlist_for_ui_action() {
audio::output::stop();
// flag to detect and reload frequency_list
freqlist_cleared_for_ui_action = true;
// if in manual mode, there is enough memory to load freqman files, else we have to unload/reload
if (!manual_mode) {
// clear and shrink_to_fit are not enough to really start with a new, clean, empty vector
// swap is the only way to achieve a perfect memory liberation
std::vector<freqman_entry>().swap(frequency_list);
} else {
} else
frequency_list.shrink_to_fit();
}
freqlist_cleared_for_ui_action = true;
}
void ReconView::reset_indexes() {
@@ -683,7 +681,6 @@ ReconView::ReconView(NavigationView& nav)
nav_.display_modal("Error", "END freq\nis lower than START");
} else {
audio::output::stop();
// clear and shrink_to_fit are not enough to really start with a new, clean, empty vector
// swap is the only way to achieve a perfect memory liberation
std::vector<freqman_entry>().swap(frequency_list);
@@ -802,7 +799,6 @@ ReconView::ReconView(NavigationView& nav)
auto open_view = nav.push<ReconSetupView>(input_file, output_file);
open_view->on_changed = [this](std::vector<std::string> result) {
freqlist_cleared_for_ui_action = false;
input_file = result[0];
output_file = result[1];
freq_file_path = "/FREQMAN/" + output_file + ".TXT";
@@ -817,6 +813,7 @@ ReconView::ReconView(NavigationView& nav)
update_ranges = persistent_memory::recon_update_ranges_when_recon();
frequency_file_load(false);
freqlist_cleared_for_ui_action = false;
if (autostart) {
recon_resume();
@@ -894,10 +891,7 @@ void ReconView::frequency_file_load(bool stop_all_before) {
audio::output::stop();
def_step = step_mode.selected_index(); // use def_step from manual selector
// clear and shrink_to_fit are not enough to really start with a new, clean, empty vector
// swap is the only way to achieve a perfect memory liberation
std::vector<freqman_entry>().swap(frequency_list); // clear the existing frequency list (expected behavior)
std::string file_input = input_file; // default recon mode
std::string file_input = input_file; // default recon mode
if (scanner_mode) {
file_input = output_file;
file_name.set_style(&Styles::red);
@@ -909,7 +903,7 @@ void ReconView::frequency_file_load(bool stop_all_before) {
button_scanner_mode.set_text("RECON");
}
desc_cycle.set_style(&Styles::white);
if (!load_freqman_file_ex(file_input, frequency_list, load_freqs, load_ranges, load_hamradios, RECON_FREQMAN_MAX_PER_FILE)) {
if (!load_freqman_file(file_input, frequency_list, load_freqs, load_ranges, load_hamradios)) {
file_name.set_style(&Styles::red);
desc_cycle.set_style(&Styles::red);
desc_cycle.set(" NO " + file_input + ".TXT FILE ...");
@@ -922,7 +916,7 @@ void ReconView::frequency_file_load(bool stop_all_before) {
desc_cycle.set("/0 no entries in list");
file_name.set("BadOrEmpty " + file_input);
} else {
if (frequency_list.size() > RECON_FREQMAN_MAX_PER_FILE) {
if (frequency_list.size() > FREQMAN_MAX_PER_FILE) {
file_name.set_style(&Styles::yellow);
desc_cycle.set_style(&Styles::yellow);
}

View File

@@ -45,7 +45,6 @@
namespace ui {
#define RECON_CFG_FILE "SETTINGS/recon.cfg"
#define RECON_FREQMAN_MAX_PER_FILE 99 // maximum tested limit for load frequency from freqman to work
class ReconView : public View {
public: