From 9521a01999dca553b6cc478ee93df96e6b061665 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 8 Apr 2025 13:50:21 +0200 Subject: [PATCH] rate limit some error messages --- glhr.cpp | 10 ++++------ hprint.cpp | 11 +++++++++++ hyperpoint.cpp | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/glhr.cpp b/glhr.cpp index 2ef59911..1ccc46a9 100644 --- a/glhr.cpp +++ b/glhr.cpp @@ -56,9 +56,8 @@ EX } EX void glError(const char* GLcall, const char* file, const int line) { GLenum errCode = glGetError(); - if(errCode!=GL_NO_ERROR) { - println(hlog, hr::format("OPENGL ERROR #%i: in file %s on line %i :: %s",errCode,file, line, GLcall)); - } + if(errCode!=GL_NO_ERROR) + rate_limited_error(hr::format("OPENGL ERROR #%i: in file %s on line %i :: %s",errCode,file, line, GLcall)); } #if HDR @@ -74,9 +73,8 @@ struct glwrap { void glwrap::act(const char *when) { GLenum errCode = glGetError(); - if(errCode!=GL_NO_ERROR) { - println(hlog, hr::format("GL error %i %s: %s:%i", errCode, when, msg, line)); - } + if(errCode!=GL_NO_ERROR) + rate_limited_error(hr::format("GL error %i %s: %s:%i", errCode, when, msg, line)); } #if HDR diff --git a/hprint.cpp b/hprint.cpp index d6fb75c9..0dccde33 100644 --- a/hprint.cpp +++ b/hprint.cpp @@ -575,4 +575,15 @@ EX vector split_string(const string& s, char sep) { return res; } +map last_rlerr; +int err_freq = 10000; + +EX void rate_limited_error(const string& s, const string& t IS("")) { + auto& last = last_rlerr[s]; + if(!last || ticks > last + err_freq) { + last = ticks; + println(hlog, s, t); + } + } + } diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 0dfdb6ca..9c1b6380 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -1122,7 +1122,7 @@ EX ld det(const transmatrix& T) { /** warning about incorrect inverse */ void inverse_error(const transmatrix& T) { - println(hlog, "Warning: inverting a singular matrix: ", T); + rate_limited_error("Warning: inverting a singular matrix", lalign(0, ": ", T)); } /** inverse of a 3x3 matrix */