Log an error and skip shadows instead of crashing when mods set maxSchematicSize too high
This commit is contained in:
@@ -59,7 +59,7 @@ public class Schematics implements Loadable{
|
|||||||
private ObjectSet<Schematic> errored = new ObjectSet<>();
|
private ObjectSet<Schematic> errored = new ObjectSet<>();
|
||||||
private ObjectMap<CoreBlock, Seq<Schematic>> loadouts = new ObjectMap<>();
|
private ObjectMap<CoreBlock, Seq<Schematic>> loadouts = new ObjectMap<>();
|
||||||
private ObjectMap<CoreBlock, Schematic> defaultLoadouts = new ObjectMap<>();
|
private ObjectMap<CoreBlock, Schematic> defaultLoadouts = new ObjectMap<>();
|
||||||
private FrameBuffer shadowBuffer;
|
private @Nullable FrameBuffer shadowBuffer;
|
||||||
private Texture errorTexture;
|
private Texture errorTexture;
|
||||||
private long lastClearTime;
|
private long lastClearTime;
|
||||||
|
|
||||||
@@ -99,7 +99,14 @@ public class Schematics implements Loadable{
|
|||||||
all.sort();
|
all.sort();
|
||||||
|
|
||||||
if(shadowBuffer == null && !headless){
|
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());
|
Tmp.m2.set(Draw.trans());
|
||||||
FrameBuffer buffer = new FrameBuffer((schematic.width + padding) * resolution, (schematic.height + padding) * resolution);
|
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.trans().idt();
|
||||||
Draw.proj().setOrtho(0, 0, shadowBuffer.getWidth(), shadowBuffer.getHeight());
|
Draw.proj().setOrtho(0, 0, shadowBuffer.getWidth(), shadowBuffer.getHeight());
|
||||||
|
|
||||||
Draw.color();
|
Draw.color();
|
||||||
schematic.tiles.each(t -> {
|
schematic.tiles.each(t -> {
|
||||||
int size = t.block.size;
|
int size = t.block.size;
|
||||||
int offsetx = -(size - 1) / 2;
|
int offsetx = -(size - 1) / 2;
|
||||||
int offsety = -(size - 1) / 2;
|
int offsety = -(size - 1) / 2;
|
||||||
for(int dx = 0; dx < size; dx++){
|
for(int dx = 0; dx < size; dx++){
|
||||||
for(int dy = 0; dy < size; dy++){
|
for(int dy = 0; dy < size; dy++){
|
||||||
int wx = t.x + dx + offsetx;
|
int wx = t.x + dx + offsetx;
|
||||||
int wy = t.y + dy + offsety;
|
int wy = t.y + dy + offsety;
|
||||||
Fill.square(padding/2f + wx + 0.5f, padding/2f + wy + 0.5f, 0.5f);
|
Fill.square(padding/2f + wx + 0.5f, padding/2f + wy + 0.5f, 0.5f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
shadowBuffer.end();
|
shadowBuffer.end();
|
||||||
|
}
|
||||||
|
|
||||||
buffer.begin(Color.clear);
|
buffer.begin(Color.clear);
|
||||||
|
|
||||||
Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight());
|
Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight());
|
||||||
|
|
||||||
Tmp.tr1.set(shadowBuffer.getTexture(), 0, 0, schematic.width + padding, schematic.height + padding);
|
if(shadowBuffer != null){
|
||||||
Draw.color(0f, 0f, 0f, 1f);
|
Tmp.tr1.set(shadowBuffer.getTexture(), 0, 0, schematic.width + padding, schematic.height + padding);
|
||||||
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
|
Draw.color(0f, 0f, 0f, 1f);
|
||||||
Draw.color();
|
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
|
||||||
|
Draw.color();
|
||||||
|
}
|
||||||
|
|
||||||
Seq<BuildPlan> plans = schematic.tiles.map(t -> new BuildPlan(t.x, t.y, t.rotation, t.block, t.config));
|
Seq<BuildPlan> 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)){
|
if(check && !(st.block instanceof CoreBlock)){
|
||||||
seq.clear();
|
seq.clear();
|
||||||
tile.getLinkedTilesAs(st.block, seq);
|
tile.getLinkedTilesAs(st.block, seq);
|
||||||
//remove env blocks, or not?
|
|
||||||
//if(seq.contains(t -> !t.block().alwaysReplace && !t.synthetic())){
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
for(var t : seq){
|
for(var t : seq){
|
||||||
if(t.block() != Blocks.air){
|
if(t.block() != Blocks.air){
|
||||||
t.remove();
|
t.remove();
|
||||||
|
|||||||
Reference in New Issue
Block a user