diff --git a/core/src/mindustry/game/Schematics.java b/core/src/mindustry/game/Schematics.java index 2333f83d45..f46c50f00e 100644 --- a/core/src/mindustry/game/Schematics.java +++ b/core/src/mindustry/game/Schematics.java @@ -59,7 +59,7 @@ public class Schematics implements Loadable{ private ObjectSet errored = new ObjectSet<>(); private ObjectMap> loadouts = new ObjectMap<>(); private ObjectMap defaultLoadouts = new ObjectMap<>(); - private FrameBuffer shadowBuffer; + private @Nullable FrameBuffer shadowBuffer; private Texture errorTexture; private long lastClearTime; @@ -99,7 +99,14 @@ public class Schematics implements Loadable{ all.sort(); if(shadowBuffer == null && !headless){ - Core.app.post(() -> shadowBuffer = new FrameBuffer(maxSchematicSize + padding + 8, maxSchematicSize + padding + 8)); + Core.app.post(() -> { + try{ + shadowBuffer = new FrameBuffer(maxSchematicSize + padding + 8, maxSchematicSize + padding + 8); + }catch(Exception e){ + Log.err(Strings.format("Failed to create shadow buffer (@x@): @. This is likely because a mod is setting maxSchematicSize too high. Don't do that.", + maxSchematicSize + padding + 8, maxSchematicSize + padding + 8, Strings.getSimpleMessage(e))); + } + }); } } @@ -215,35 +222,39 @@ public class Schematics implements Loadable{ Tmp.m2.set(Draw.trans()); FrameBuffer buffer = new FrameBuffer((schematic.width + padding) * resolution, (schematic.height + padding) * resolution); - shadowBuffer.begin(Color.clear); + if(shadowBuffer != null){ + shadowBuffer.begin(Color.clear); - Draw.trans().idt(); - Draw.proj().setOrtho(0, 0, shadowBuffer.getWidth(), shadowBuffer.getHeight()); + Draw.trans().idt(); + Draw.proj().setOrtho(0, 0, shadowBuffer.getWidth(), shadowBuffer.getHeight()); - Draw.color(); - schematic.tiles.each(t -> { - int size = t.block.size; - int offsetx = -(size - 1) / 2; - int offsety = -(size - 1) / 2; - for(int dx = 0; dx < size; dx++){ - for(int dy = 0; dy < size; dy++){ - int wx = t.x + dx + offsetx; - int wy = t.y + dy + offsety; - Fill.square(padding/2f + wx + 0.5f, padding/2f + wy + 0.5f, 0.5f); + Draw.color(); + schematic.tiles.each(t -> { + int size = t.block.size; + int offsetx = -(size - 1) / 2; + int offsety = -(size - 1) / 2; + for(int dx = 0; dx < size; dx++){ + for(int dy = 0; dy < size; dy++){ + int wx = t.x + dx + offsetx; + int wy = t.y + dy + offsety; + Fill.square(padding/2f + wx + 0.5f, padding/2f + wy + 0.5f, 0.5f); + } } - } - }); + }); - shadowBuffer.end(); + shadowBuffer.end(); + } buffer.begin(Color.clear); Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight()); - Tmp.tr1.set(shadowBuffer.getTexture(), 0, 0, schematic.width + padding, schematic.height + padding); - Draw.color(0f, 0f, 0f, 1f); - Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight()); - Draw.color(); + if(shadowBuffer != null){ + Tmp.tr1.set(shadowBuffer.getTexture(), 0, 0, schematic.width + padding, schematic.height + padding); + Draw.color(0f, 0f, 0f, 1f); + Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight()); + Draw.color(); + } Seq plans = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block, t.config)); @@ -473,10 +484,6 @@ public class Schematics implements Loadable{ if(check && !(st.block instanceof CoreBlock)){ seq.clear(); tile.getLinkedTilesAs(st.block, seq); - //remove env blocks, or not? - //if(seq.contains(t -> !t.block().alwaysReplace && !t.synthetic())){ - // return; - //} for(var t : seq){ if(t.block() != Blocks.air){ t.remove();