GL error checker

This commit is contained in:
Anuken 2025-04-11 10:18:05 -04:00
parent 6e17f88c09
commit 0b9564abd5
2 changed files with 21 additions and 0 deletions

View file

@ -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<ServerGroup> 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 */

View file

@ -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();
}