Skip to content

Commit

Permalink
Avoid infinite recursion if icon load fails
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Mar 14, 2024
1 parent d1e4118 commit 4d8b798
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions tray_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,23 @@ void _destroy_icon_cache() {
icon_info_count = 0;
}

HICON _fetch_cached_icon(const char * path, enum IconType icon_type) {
for (int i = 0; i < icon_info_count; ++i) {
if (strcmp(icon_infos[i].path, path) == 0) {
switch (icon_type) {
case REGULAR:
return icon_infos[i].icon;
case LARGE:
return icon_infos[i].large_icon;
case NOTIFICATION:
return icon_infos[i].notification_icon;
}
}
HICON _fetch_cached_icon(struct icon_info *icon_record, enum IconType icon_type) {
switch (icon_type) {
case REGULAR:
return icon_record->icon;
case LARGE:
return icon_record->large_icon;
case NOTIFICATION:
return icon_record->notification_icon;
}

return NULL;
}

HICON _fetch_icon(const char * path, enum IconType icon_type) {
HICON value = _fetch_cached_icon(path, icon_type);

if (value != NULL) {
return value;
// Find a cached icon by path
for (int i = 0; i < icon_info_count; ++i) {
if (strcmp(icon_infos[i].path, path) == 0) {
return _fetch_cached_icon(&icon_infos[i], icon_type);
}
}

// Expand cache, fetch, and retry
Expand All @@ -173,7 +168,7 @@ HICON _fetch_icon(const char * path, enum IconType icon_type) {
int index = icon_info_count - 1;
icon_infos[icon_info_count - 1] = _create_icon_info(path);

return _fetch_icon(path, icon_type);
return _fetch_cached_icon(&icon_infos[icon_info_count - 1], icon_type);
}

int tray_init(struct tray *tray) {
Expand Down

0 comments on commit 4d8b798

Please sign in to comment.