From 1ec55ea9e6eea94b44fc907b98826cff18fa4fbe Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sat, 4 Jun 2022 17:42:36 +0200 Subject: [PATCH] [MIRROR] Adds logging to overlay overflow errors [MDB IGNORE] (#14084) * Adds logging to overlay overflow errors (#67497) So we've got this overlay cap of like 100 right? Prevents OOMs But right now if you overrun it we have no way of knowing how you got there, so we just end up with no info. This pr solves that, by adding a printout of icon-icon_state-dir = amount for each apperance. Note, we are basically cheating by typing these overlay members as mutable apperance, they can be just normal appearances, which we don't have an accessible type for. Fortunately we can cheat. Oh and if you overflow the limit you get the error overlay applied to you, for sniks * Adds logging to overlay overflow errors Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/controllers/subsystem/overlays.dm | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/code/controllers/subsystem/overlays.dm b/code/controllers/subsystem/overlays.dm index bc38254f1d3..34e22e1bde2 100644 --- a/code/controllers/subsystem/overlays.dm +++ b/code/controllers/subsystem/overlays.dm @@ -43,17 +43,21 @@ SUBSYSTEM_DEF(overlays) count++ if(!atom_to_compile) continue - if(length(atom_to_compile.overlays) >= MAX_ATOM_OVERLAYS) - //Break it real GOOD - stack_trace("Too many overlays on [atom_to_compile.type] - [length(atom_to_compile.overlays)], refusing to update and cutting") - atom_to_compile.overlays.Cut() - continue STAT_START_STOPWATCH COMPILE_OVERLAYS(atom_to_compile) UNSETEMPTY(atom_to_compile.add_overlays) UNSETEMPTY(atom_to_compile.remove_overlays) STAT_STOP_STOPWATCH STAT_LOG_ENTRY(stats, atom_to_compile.type) + if(length(atom_to_compile.overlays) >= MAX_ATOM_OVERLAYS) + //Break it real GOOD + var/text_lays = overlays2text(atom_to_compile.overlays) + stack_trace("Too many overlays on [atom_to_compile.type] - [length(atom_to_compile.overlays)], refusing to update and cutting.\ + \n What follows is a printout of all existing overlays at the time of the overflow \n[text_lays]") + atom_to_compile.overlays.Cut() + //Let them know they fucked up + atom_to_compile.add_overlay(mutable_appearance('icons/testing/greyscale_error.dmi')) + continue if(mc_check) if(MC_TICK_CHECK) break @@ -63,6 +67,19 @@ SUBSYSTEM_DEF(overlays) queue.Cut(1,count+1) count = 0 +/// Converts an overlay list into text for debug printing +/// Of note: overlays aren't actually mutable appearances, they're just appearances +/// Don't have access to that type tho, so this is the best you're gonna get +/proc/overlays2text(list/overlays) + var/list/unique_overlays = list() + // As anything because we're basically doing type coerrsion, rather then actually filtering for mutable apperances + for(var/mutable_appearance/overlay as anything in overlays) + var/key = "[overlay.icon]-[overlay.icon_state]-[overlay.dir]" + unique_overlays[key] += 1 + var/list/output_text = list() + for(var/key in unique_overlays) + output_text += "([key]) = [unique_overlays[key]]" + return output_text.Join("\n") /proc/iconstate2appearance(icon, iconstate) var/static/image/stringbro = new()