From 64f1fbe400c0c854b854a4687003625128321051 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 6 Jul 2018 12:04:33 -0400 Subject: [PATCH] Fixed many various crashes --- .../annotations/RemoteWriteGenerator.java | 2 +- core/src/io/anuke/mindustry/core/Control.java | 10 +-- .../io/anuke/mindustry/core/NetServer.java | 4 +- core/src/io/anuke/mindustry/core/World.java | 4 +- .../mindustry/editor/MapEditorDialog.java | 6 +- .../anuke/mindustry/entities/effect/Fire.java | 2 +- .../anuke/mindustry/input/InputHandler.java | 67 +++++++++---------- .../ui/fragments/BlockInventoryFragment.java | 12 ++-- .../mindustry/world/blocks/BuildBlock.java | 2 + .../world/blocks/production/Separator.java | 1 + 10 files changed, 56 insertions(+), 54 deletions(-) diff --git a/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java b/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java index 1d80dcbc67..03be5844ac 100644 --- a/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java +++ b/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java @@ -129,7 +129,7 @@ public class RemoteWriteGenerator { method.beginControlFlow("if("+getCheckString(methodEntry.where)+")"); //add statement to create packet from pool - method.addStatement("$1N packet = $2N.obtain($1N.class)", "io.anuke.mindustry.net.Packets.InvokePacket", "com.badlogic.gdx.utils.Pools"); + method.addStatement("$1N packet = $2N.obtain($1N.class)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.ucore.util.Pooling"); //assign buffer method.addStatement("packet.writeBuffer = TEMP_BUFFER"); //assign priority diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 0fd0d87a66..70fce441cd 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -166,12 +166,14 @@ public class Control extends Module{ Player[] old = players; players = new Player[index + 1]; System.arraycopy(old, 0, players, 0, old.length); - - InputHandler[] oldi = inputs; - inputs = new InputHandler[index + 1]; - System.arraycopy(oldi, 0, inputs, 0, oldi.length); } + if(inputs.length != index + 1){ + InputHandler[] oldi = inputs; + inputs = new InputHandler[index + 1]; + System.arraycopy(oldi, 0, inputs, 0, oldi.length); + } + Player setTo = (index == 0 ? null : players[0]); Player player = new Player(); diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index c8659d38f6..22198bc7ae 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -494,14 +494,12 @@ public class NetServer extends Module{ return; } - String ip = player.con.address; - if(action == AdminAction.wave) { //no verification is done, so admins can hypothetically spam waves //not a real issue, because server owners may want to do just that state.wavetime = 0f; }else if(action == AdminAction.ban){ - netServer.admins.banPlayerIP(ip); + netServer.admins.banPlayerIP(other.con.address); netServer.kick(other.con.id, KickReason.banned); Log.info("&lc{0} has banned {1}.", player.name, other.name); }else if(action == AdminAction.kick){ diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index a139ecbf39..7dfaa3977f 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -93,11 +93,11 @@ public class World extends Module{ } public int width(){ - return tiles.length; + return tiles == null ? 0 : tiles.length; } public int height(){ - return tiles[0].length; + return tiles == null ? 0 : tiles[0].length; } public int toPacked(int x, int y){ diff --git a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java index d8624f7ef2..f1d0fa47db 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java @@ -368,13 +368,11 @@ public class MapEditorDialog extends Dialog implements Disposable{ public void updateSelectedBlock(){ Block block = editor.getDrawBlock(); - int i = 0; for(int j = 0; j < Block.all().size; j ++){ - if(block.id == j){ - blockgroup.getButtons().get(i).setChecked(true); + if(block.id == j && j < blockgroup.getButtons().size){ + blockgroup.getButtons().get(j).setChecked(true); break; } - i++; } } diff --git a/core/src/io/anuke/mindustry/entities/effect/Fire.java b/core/src/io/anuke/mindustry/entities/effect/Fire.java index 078bb4b1a0..37b559011b 100644 --- a/core/src/io/anuke/mindustry/entities/effect/Fire.java +++ b/core/src/io/anuke/mindustry/entities/effect/Fire.java @@ -91,7 +91,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable time = Mathf.clamp(time + Timers.delta(), 0, lifetime()); - if(time >= lifetime()){ + if(time >= lifetime() || tile == null){ CallEntity.onFireRemoved(getID()); remove(); } diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index aff1520cbd..57b3a99908 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -283,50 +283,49 @@ public abstract class InputHandler extends InputAdapter{ throw new ValidateException(player, "Player cannot transfer an item."); } - if(player == null) return; + threads.run(() -> { + if (player == null || tile.entity == null) return; - player.isTransferring = true; + player.isTransferring = true; - ItemStack stack = player.inventory.getItem(); - int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player); + ItemStack stack = player.inventory.getItem(); + int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player); - boolean clear = stack.amount == accepted; - int sent = Mathf.clamp(accepted/4, 1, 8); - int removed = accepted/sent; - int[] remaining = {accepted, accepted}; + boolean clear = stack.amount == accepted; + int sent = Mathf.clamp(accepted / 4, 1, 8); + int removed = accepted / sent; + int[] remaining = {accepted, accepted}; - for(int i = 0; i < sent; i ++){ - boolean end = i == sent-1; - Timers.run(i * 3, () -> { - tile.block().getStackOffset(stack.item, tile, stackTrns); + for (int i = 0; i < sent; i++) { + boolean end = i == sent - 1; + Timers.run(i * 3, () -> { + tile.block().getStackOffset(stack.item, tile, stackTrns); - ItemTransfer.create(stack.item, - player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns), - new Translator(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> { + ItemTransfer.create(stack.item, + player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns), + new Translator(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> { - tile.block().handleStack(stack.item, removed, tile, player); - remaining[1] -= removed; + tile.block().handleStack(stack.item, removed, tile, player); + remaining[1] -= removed; - if(end && remaining[1] > 0) { - tile.block().handleStack(stack.item, remaining[1], tile, player); - } - }); + if (end && remaining[1] > 0) { + tile.block().handleStack(stack.item, remaining[1], tile, player); + } + }); - stack.amount -= removed; - remaining[0] -= removed; + stack.amount -= removed; + remaining[0] -= removed; - if(end){ - stack.amount -= remaining[0]; - if(clear){ - player.inventory.clearItem(); + if (end) { + stack.amount -= remaining[0]; + if (clear) { + player.inventory.clearItem(); + } + player.isTransferring = false; } - player.isTransferring = false; - } - }); - } - - //ItemDrop.create(player.inventory.getItem().item, player.inventory.getItem().amount, player.x, player.y, angle); - //player.inventory.clearItem(); + }); + } + }); } @Remote(targets = Loc.both, called = Loc.server, forward = true, in = In.blocks) diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java index 4ac97e9f02..16e0dc602c 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java @@ -59,7 +59,7 @@ public class BlockInventoryFragment extends Fragment { public void showFor(Tile t){ this.tile = t.target(); if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.totalItems() == 0) return; - rebuild(); + rebuild(true); } public void hide(){ @@ -71,7 +71,7 @@ public class BlockInventoryFragment extends Fragment { tile = null; } - private void rebuild(){ + private void rebuild(boolean actions){ Player player = input.player; IntSet container = new IntSet(); @@ -99,7 +99,7 @@ public class BlockInventoryFragment extends Fragment { int[] items = tile.entity.items.items; for (int i = 0; i < items.length; i++) { if ((items[i] == 0) == container.contains(i)) { - rebuild(); + rebuild(false); } } } @@ -160,8 +160,10 @@ public class BlockInventoryFragment extends Fragment { updateTablePosition(); - table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true), - Actions.scaleTo(1f, 1f, 0.07f, Interpolation.pow3Out)); + if(actions){ + table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true), + Actions.scaleTo(1f, 1f, 0.07f, Interpolation.pow3Out)); + } } private String round(float f){ diff --git a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java index d20e61a56c..f672045459 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java @@ -100,6 +100,8 @@ public class BuildBlock extends Block { return; } + if(entity.previous == null) return; + for (TextureRegion region : entity.previous.getBlockIcon()) { Draw.rect(region, tile.drawx(), tile.drawy(), entity.previous.rotate ? tile.getRotation() * 90 : 0); } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Separator.java b/core/src/io/anuke/mindustry/world/blocks/production/Separator.java index 4c3c981d69..b150976239 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Separator.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Separator.java @@ -50,6 +50,7 @@ public class Separator extends Block { stats.add(BlockStat.liquidUse, liquidUse * 60f, StatUnit.liquidSecond); stats.add(BlockStat.inputLiquid, liquid); + stats.add(BlockStat.inputItem, item); stats.add(BlockStat.outputItem, new ItemFilterValue(item -> { for(Item i : results){ if(item == i) return true;