Filters update late after setting Display
Opened this issue · 3 comments
Using ::fe.set_display
sometimes fails to update ::fe.filters
immediately.
Calling ::fe.set_display
a second time fixes ::fe.filters
.
Occurs on Windows 10, cannot reproduce in Ubuntu 22.04.4.
The loop is intended to scrape display filters to generate global stats.
layout.nut
local f_names = function() { local n = ""; foreach (f in ::fe.filters) n += f.name + ", "; return n; }
local nv_key = "STATS_RUNNING";
if (!(nv_key in ::fe.nv)) ::fe.nv[nv_key] <- false;
if (!::fe.nv[nv_key]) {
local original = ::fe.list.display_index;
local f1, f2, data = [];
foreach (i, display in ::fe.displays) {
::fe.set_display(i, false, false);
f1 = f_names();
data.push(format("Before %d: '%s' (%d filters) %s", ::fe.list.display_index, display.name, ::fe.filters.len(), f1));
::fe.set_display(i, false, false); // hack
f2 = f_names();
data.push(format("After %d: '%s' (%d filters)%s %s", ::fe.list.display_index, display.name, ::fe.filters.len(), f1 != f2 ? "<--" : " ", f2));
}
::fe.set_display(original, false, false);
::fe.nv[nv_key] <- true;
foreach (item in data) ::fe.log(item);
} else {
delete ::fe.nv[nv_key];
}
last_run.log
Before 0: 'Mame' (6 filters) All, Favourites, 2UP, MameFilter, Top, 4UP,
After 0: 'Mame' (6 filters) All, Favourites, 2UP, MameFilter, Top, 4UP,
Before 1: 'C64' (6 filters) All, Favourites, 2UP, MameFilter, Top, 4UP,
After 1: 'C64' (5 filters)<-- All, Favourites, Extra, More, C64Filter,
Before 2: 'MD' (4 filters) All, Favourites, Extra, MDFilter,
After 2: 'MD' (4 filters) All, Favourites, Extra, MDFilter,
Before 3: 'N64' (4 filters) All, Favourites, Extra, MDFilter,
After 3: 'N64' (4 filters)<-- All, Favourites, More, N64Filter,
Before 4: 'SMS' (4 filters) All, Favourites, More, N64Filter,
After 4: 'SMS' (5 filters)<-- All, Favourites, More, Extra, SMSFilter,
Before 5: 'SNES' (4 filters) All, Favourites, Extra, SNESFilter,
After 5: 'SNES' (4 filters) All, Favourites, Extra, SNESFilter,
The arrows <--
indicate where ::fe.filters
has changed on the second call.
Attract-Mode Plus v3.0.8
I think it's the time to consider adding the filters
table to fe.Displays
that would have size
field for each filter and make it cached, so the filter's list is not regenerated on every display change unless the cfg file has changed.
Catch me up on Discord so we can discuss the details.
I could fix the above code, but it's just a workaround for a long overdue AM shortcoming.
The loop is an edge-case, a non-standard (ab)use of AM, and is unlikely to occur "in the wild".
Not essential to fix, just keep it in mind if you ever refactor the lists.