diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 0043e61df6..635430017f 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -86,6 +86,8 @@ public class Vars implements Loadable{ public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md"; /** list of built-in servers.*/ public static final Seq defaultServers = Seq.with(); + /** maximum openGL errors logged */ + public static final int maxGlErrors = 100; /** maximum size of any block, do not change unless you know what you're doing */ public static final int maxBlockSize = 16; /** maximum distance between mine and core that supports automatic transferring */ diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index e7e5ebe317..22a2db65ab 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -71,6 +71,7 @@ public class Renderer implements ApplicationListener{ //for landTime > 0: if true, core is currently *launching*, otherwise landing. private boolean launching; private Vec2 camShakeOffset = new Vec2(); + private int glErrors; public Renderer(){ camera = new Camera(); @@ -222,6 +223,24 @@ public class Renderer implements ApplicationListener{ camera.position.sub(camShakeOffset); } + //glGetError can be expensive, so only check it periodically + if(glErrors < maxGlErrors && graphics.getFrameId() % 10 == 0){ + int error = Gl.getError(); + if(error != Gl.noError){ + String message = switch(error){ + case Gl.invalidValue -> "invalid value"; + case Gl.invalidOperation -> "invalid operation"; + case Gl.invalidFramebufferOperation -> "invalid framebuffer operation"; + case Gl.invalidEnum -> "invalid enum"; + case Gl.outOfMemory -> "out of memory"; + default -> "unknown error " + (error); + }; + + Log.err("[GL] Error: @", message); + glErrors ++; + } + } + PerfCounter.render.end(); }