Fixed many various crashes

This commit is contained in:
Anuken
2018-07-06 12:04:33 -04:00
parent c2c837329c
commit 64f1fbe400
10 changed files with 56 additions and 54 deletions
@@ -129,7 +129,7 @@ public class RemoteWriteGenerator {
method.beginControlFlow("if("+getCheckString(methodEntry.where)+")"); method.beginControlFlow("if("+getCheckString(methodEntry.where)+")");
//add statement to create packet from pool //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 //assign buffer
method.addStatement("packet.writeBuffer = TEMP_BUFFER"); method.addStatement("packet.writeBuffer = TEMP_BUFFER");
//assign priority //assign priority
@@ -166,12 +166,14 @@ public class Control extends Module{
Player[] old = players; Player[] old = players;
players = new Player[index + 1]; players = new Player[index + 1];
System.arraycopy(old, 0, players, 0, old.length); 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 setTo = (index == 0 ? null : players[0]);
Player player = new Player(); Player player = new Player();
@@ -494,14 +494,12 @@ public class NetServer extends Module{
return; return;
} }
String ip = player.con.address;
if(action == AdminAction.wave) { if(action == AdminAction.wave) {
//no verification is done, so admins can hypothetically spam waves //no verification is done, so admins can hypothetically spam waves
//not a real issue, because server owners may want to do just that //not a real issue, because server owners may want to do just that
state.wavetime = 0f; state.wavetime = 0f;
}else if(action == AdminAction.ban){ }else if(action == AdminAction.ban){
netServer.admins.banPlayerIP(ip); netServer.admins.banPlayerIP(other.con.address);
netServer.kick(other.con.id, KickReason.banned); netServer.kick(other.con.id, KickReason.banned);
Log.info("&lc{0} has banned {1}.", player.name, other.name); Log.info("&lc{0} has banned {1}.", player.name, other.name);
}else if(action == AdminAction.kick){ }else if(action == AdminAction.kick){
+2 -2
View File
@@ -93,11 +93,11 @@ public class World extends Module{
} }
public int width(){ public int width(){
return tiles.length; return tiles == null ? 0 : tiles.length;
} }
public int height(){ public int height(){
return tiles[0].length; return tiles == null ? 0 : tiles[0].length;
} }
public int toPacked(int x, int y){ public int toPacked(int x, int y){
@@ -368,13 +368,11 @@ public class MapEditorDialog extends Dialog implements Disposable{
public void updateSelectedBlock(){ public void updateSelectedBlock(){
Block block = editor.getDrawBlock(); Block block = editor.getDrawBlock();
int i = 0;
for(int j = 0; j < Block.all().size; j ++){ for(int j = 0; j < Block.all().size; j ++){
if(block.id == j){ if(block.id == j && j < blockgroup.getButtons().size){
blockgroup.getButtons().get(i).setChecked(true); blockgroup.getButtons().get(j).setChecked(true);
break; break;
} }
i++;
} }
} }
@@ -91,7 +91,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable
time = Mathf.clamp(time + Timers.delta(), 0, lifetime()); time = Mathf.clamp(time + Timers.delta(), 0, lifetime());
if(time >= lifetime()){ if(time >= lifetime() || tile == null){
CallEntity.onFireRemoved(getID()); CallEntity.onFireRemoved(getID());
remove(); remove();
} }
@@ -283,50 +283,49 @@ public abstract class InputHandler extends InputAdapter{
throw new ValidateException(player, "Player cannot transfer an item."); 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(); ItemStack stack = player.inventory.getItem();
int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player); int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player);
boolean clear = stack.amount == accepted; boolean clear = stack.amount == accepted;
int sent = Mathf.clamp(accepted/4, 1, 8); int sent = Mathf.clamp(accepted / 4, 1, 8);
int removed = accepted/sent; int removed = accepted / sent;
int[] remaining = {accepted, accepted}; int[] remaining = {accepted, accepted};
for(int i = 0; i < sent; i ++){ for (int i = 0; i < sent; i++) {
boolean end = i == sent-1; boolean end = i == sent - 1;
Timers.run(i * 3, () -> { Timers.run(i * 3, () -> {
tile.block().getStackOffset(stack.item, tile, stackTrns); tile.block().getStackOffset(stack.item, tile, stackTrns);
ItemTransfer.create(stack.item, ItemTransfer.create(stack.item,
player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns), 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), () -> { new Translator(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> {
tile.block().handleStack(stack.item, removed, tile, player); tile.block().handleStack(stack.item, removed, tile, player);
remaining[1] -= removed; remaining[1] -= removed;
if(end && remaining[1] > 0) { if (end && remaining[1] > 0) {
tile.block().handleStack(stack.item, remaining[1], tile, player); tile.block().handleStack(stack.item, remaining[1], tile, player);
} }
}); });
stack.amount -= removed; stack.amount -= removed;
remaining[0] -= removed; remaining[0] -= removed;
if(end){ if (end) {
stack.amount -= remaining[0]; stack.amount -= remaining[0];
if(clear){ if (clear) {
player.inventory.clearItem(); 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) @Remote(targets = Loc.both, called = Loc.server, forward = true, in = In.blocks)
@@ -59,7 +59,7 @@ public class BlockInventoryFragment extends Fragment {
public void showFor(Tile t){ public void showFor(Tile t){
this.tile = t.target(); this.tile = t.target();
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.totalItems() == 0) return; if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.totalItems() == 0) return;
rebuild(); rebuild(true);
} }
public void hide(){ public void hide(){
@@ -71,7 +71,7 @@ public class BlockInventoryFragment extends Fragment {
tile = null; tile = null;
} }
private void rebuild(){ private void rebuild(boolean actions){
Player player = input.player; Player player = input.player;
IntSet container = new IntSet(); IntSet container = new IntSet();
@@ -99,7 +99,7 @@ public class BlockInventoryFragment extends Fragment {
int[] items = tile.entity.items.items; int[] items = tile.entity.items.items;
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
if ((items[i] == 0) == container.contains(i)) { if ((items[i] == 0) == container.contains(i)) {
rebuild(); rebuild(false);
} }
} }
} }
@@ -160,8 +160,10 @@ public class BlockInventoryFragment extends Fragment {
updateTablePosition(); updateTablePosition();
table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true), if(actions){
Actions.scaleTo(1f, 1f, 0.07f, Interpolation.pow3Out)); table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true),
Actions.scaleTo(1f, 1f, 0.07f, Interpolation.pow3Out));
}
} }
private String round(float f){ private String round(float f){
@@ -100,6 +100,8 @@ public class BuildBlock extends Block {
return; return;
} }
if(entity.previous == null) return;
for (TextureRegion region : entity.previous.getBlockIcon()) { for (TextureRegion region : entity.previous.getBlockIcon()) {
Draw.rect(region, tile.drawx(), tile.drawy(), entity.previous.rotate ? tile.getRotation() * 90 : 0); Draw.rect(region, tile.drawx(), tile.drawy(), entity.previous.rotate ? tile.getRotation() * 90 : 0);
} }
@@ -50,6 +50,7 @@ public class Separator extends Block {
stats.add(BlockStat.liquidUse, liquidUse * 60f, StatUnit.liquidSecond); stats.add(BlockStat.liquidUse, liquidUse * 60f, StatUnit.liquidSecond);
stats.add(BlockStat.inputLiquid, liquid); stats.add(BlockStat.inputLiquid, liquid);
stats.add(BlockStat.inputItem, item);
stats.add(BlockStat.outputItem, new ItemFilterValue(item -> { stats.add(BlockStat.outputItem, new ItemFilterValue(item -> {
for(Item i : results){ for(Item i : results){
if(item == i) return true; if(item == i) return true;