Jump to content

(Solved)GUI handling causing game to crash with no crash report?


Recommended Posts

Posted

After a little bit of testing (perhaps not enough) I've discovered that my server-side GUI handler is causing the game to freeze indefinitely. I have successfully managed to print to the console all the way through my class ContainerWindmilll and also in my class BlockWindmill, giving me the feeling that something somewhere else is affected. If anybody can locate the cause of this crash (no errors are shown, it's only when I right-click it crashes) I would be very grateful.

 

EDIT: I've edited my code around a bit and now the FMLNetworkHandler.openGUI line from the BlockWindmill class seems to not freeze the game but freezes console output (perhaps freezes the thread?)

 

Gui Handler:

 

package testmod.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import testmod.gui.container.ContainerWindmill;
import testmod.tileEntities.TileEntityWindmill;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler
{
public static final int guiIDWindmill = 0;

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) 
{
	TileEntity tileEntity = world.getTileEntity(x, y, z);

	switch(ID)
	{
		case guiIDWindmill:
			if(tileEntity instanceof TileEntityWindmill)
			{
				return new ContainerWindmill(player.inventory, (TileEntityWindmill) tileEntity);
			}
	}
	return null;
}

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) 
{
	TileEntity tileEntity = world.getTileEntity(x, y, z);

	switch(ID)
	{
		case guiIDWindmill:
			while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;
			{
				System.out.println(y);
				y++;
			}

			return new GuiWindmill(player.inventory, (TileEntityWindmill) tileEntity);
	}
	return null;
}
}

 

 

ContainerWindmill:

 

package testmod.gui.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import testmod.tileEntities.TileEntityWindmill;

public class ContainerWindmill extends Container 
{
public TileEntityWindmill windmill;

public ContainerWindmill(InventoryPlayer inventoryPlayer, TileEntityWindmill windmill)
{
	this.windmill = windmill;

	this.addSlotToContainer(new Slot(windmill, 0, 61, 33));
	this.addSlotToContainer(new Slot(windmill, 1, 100, 33));

	for(int i = 0; i < 3; i++) //Create the inventory slots
	{
		for(int j = 0; j < 9; j++)
		{
			this.addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+j*18, 84+18*i));
		}
	}

	for(int i = 0; i < 9; i++) //Create the hotbar slots
	{
		this.addSlotToContainer(new Slot(inventoryPlayer, i, 8+18*i, 142));
	}
}

public boolean canInteractWith(EntityPlayer player) 
{
	return true;
}
}

/*
* ~~Notes~~
* this.addSlotToContainer(new Slot(inventoryPlayer, ID, xPos, yPos)
* 
* Inventory IDs: Hotbar: 0-8
* 				  Inventory: 9-27
* */

 

 

TileEntityWindmill:

 

package testmod.tileEntities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityWindmill extends TileEntity implements ISidedInventory
{
private ItemStack[] slot = new ItemStack[2];

public float rotation = 0F;

public int maxPower = 10000;
public float power = 0F;
public float powerPerRotation = 1F;

public void updateEntity() //TODO increase power
{
	rotation++;

	powerPerRotation = 5;

	power+=powerPerRotation;

	if(power > maxPower) power = maxPower;

}

public int getPowerScaled(int scaled)
{
	return (int) (this.power * scaled / this.maxPower);
}

public void readFromNBT(NBTTagCompound nbt)
{

}

public void writeToNBT(NBTTagCompound nbt)
{

}

public void closeInventory() 
{

}

public ItemStack decrStackSize(int i, int j) 
{
	if(this.slot[i] != null)
	{
		ItemStack itemStack;

		if(this.slot[i].stackSize <= j)
		{
			itemStack = this.slot[i];
			this.slot[i] = null;
			return itemStack;
		}
		else
		{
			itemStack = this.slot[i].splitStack(j);

			if(this.slot[i].stackSize == 0)
			{
				this.slot[i] = null;
			}

			return itemStack;
		}
	}

	return null;
}

public String getInventoryName() 
{
	return null;
}

public int getInventoryStackLimit()
{
	return 64;
}

public int getSizeInventory() 
{

	return this.slot.length;
}

public ItemStack getStackInSlot(int i) 
{

	return this.slot[i];
}

public ItemStack getStackInSlotOnClosing(int i) 
{
	if(this.slot[i] != null)
	{
		ItemStack itemStack = this.slot[i];
		this.slot[i] = null;
		return itemStack;
	}

	return null;
}

public boolean hasCustomInventoryName()
{

	return false;
}

public boolean isItemValidForSlot(int var1, ItemStack var2)
{

	return false;
}

public boolean isUseableByPlayer(EntityPlayer var1)
{

	return false;
}

public void openInventory() 
{


}

public void setInventorySlotContents(int i, ItemStack itemStack) 
{
	this.slot[i] = itemStack;

	if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
	{
		itemStack.stackSize = this.getInventoryStackLimit();
	}
}

public boolean canExtractItem(int var1, ItemStack var2, int var3) 
{

	return false;
}

public boolean canInsertItem(int var1, ItemStack var2, int var3) 
{

	return false;
}

public int[] getAccessibleSlotsFromSide(int var1) 
{

	return null;
}
}

 

 

BlockWindmill:

 

package testmod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import testmod.Main;
import testmod.gui.GuiHandler;
import testmod.tileEntities.TileEntityWindmill;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;

public class BlockWindmill extends BlockContainer //Class for the windmill block. The block is turned into a tileEntity when placed
{
public BlockWindmill(Material material)
{
	super(material);
}

public int getRenderType()
{
	return -1;
}

public boolean isOpaqueCube()
{
	return false;
}

public boolean renderAsNormalBlock()
{
	return false;
}

public TileEntity createNewTileEntity(World var1, int var2) //Replaces the block with its tileEntity counterpart
{
	return new TileEntityWindmill();
}

public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
{
	if (world.getBlock(x, y+1, z) == CreateBlocks.blockWindmill) world.setBlockToAir(x, y+1, z);
	if (world.getBlock(x, y-1, z) == CreateBlocks.blockWindmill) world.setBlockToAir(x, y-1, z);
}

public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
	float pixel = 1F/16F;

	if(world.getBlockMetadata(x, y, z) < 7) this.setBlockBounds(pixel*4, 0, pixel*4, 1-pixel*4, 1, 1-pixel*4);
	else this.setBlockBounds(0, 0, 0, 1, 1, 1);
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
	if(!world.isRemote)
	{
		FMLNetworkHandler.openGui(player, Main.instance, GuiHandler.guiIDWindmill, world, x, y, z);
		return true;
	}
	return false;
}
}

 

I have no idea what I'm doing.

Posted

Such "crashes" are mostly caused because of an infinite loop. Try stopping Minecraft with the debugger and it should show you the point where the program was at the time you stopped it.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

When you start it with the debugger (bug button) it keeps track of certain stats and vars. You can then use the Terminate button to kill the process and it should show you the breakpoint.

 

 

bbc501943d.png

 

 

Its not crashing when there is no log its just stuck in an infinite loop and windows stops it when the user tries to interact with it.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Ok I tried that and all it did was paste

 AL lib: (EE) alc_cleanup: 1 device not closed 

to the console. What might be worth noting is that the game no longer freezes. In the method below, it prints "before", but "after" is never printed.

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{	
	if(!world.isRemote)
	{
		Main.print("before"); //Just a custom print method to put my mod name on there
		FMLNetworkHandler.openGui(player, Main.instance, GuiHandler.guiIDWindmill, world, x, y, z);
		Main.print("after");
		return true;
	}
	return false;
}

I have no idea what I'm doing.

Posted

Eclipse and debuggers in general usage involves placing breakpoints and stepping through code a line at a time while examining variables in the method. Use eclipse help if you need to learn how.

Posted

while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;

Yeah, that is an infinite loop.

 

Sorry I'm sure I'm being an idiot here. Could you explain how please? I copied that piece of code from a tutorial video, and theirs worked fine.

I have no idea what I'm doing.

Posted

Eclipse and debuggers in general usage involves placing breakpoints and stepping through code a line at a time while examining variables in the method. Use eclipse help if you need to learn how.

 

I thought that, but the buttons were disabled. I will make sure to look into the help for them, thanks.

I have no idea what I'm doing.

Posted

while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;

Yeah, that is an infinite loop.

 

Sorry I'm sure I'm being an idiot here. Could you explain how please? I copied that piece of code from a tutorial video, and theirs worked fine.

 

Okay, there are two kinds of loops that use

while

. One is:

do BLOCK while (boolean-expression);

(note the ';' after the keyword. The other is:

while (boolean-expression) BLOCK;

(notice the ';' after the body of the loop). In both cases BLOCK is usually an actualy block ('

{ statement; ... }

'), but it may also be a single statement.

 

Your while loop appears to be executing a null statement (';' alone is a null statement), and that is why the loop repeats forever.

Posted

while(tileEntity instanceof TileEntityWindmill && world.getBlockMetadata(x, y, z) < ;

Yeah, that is an infinite loop.

 

Sorry I'm sure I'm being an idiot here. Could you explain how please? I copied that piece of code from a tutorial video, and theirs worked fine.

 

Okay, there are two kinds of loops that use

while

. One is:

do BLOCK while (boolean-expression);

(note the ';' after the keyword. The other is:

while (boolean-expression) BLOCK;

(notice the ';' after the body of the loop). In both cases BLOCK is usually an actualy block ('

{ statement; ... }

'), but it may also be a single statement.

 

Your while loop appears to be executing a null statement (';' alone is a null statement), and that is why the loop repeats forever.

 

Oh my whatever the supreme being(s) may or may not be. In other words, I misplaced a semicolon on a block like I do so often. Thanks!

I have no idea what I'm doing.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.