
Infinite loop in onBlockActivate
OneEyeMaker opened this issue ยท 3 comments
Hello.
Firstly, thank you for your mods (and for this mod especially).
I've simple suggestion.
Capability proxy blocks (accidentally or intentionally) can be placed to form loops. And it can lead to infinite cycles and StackOverflowException
(read: server crashes).
I suggest to add protection against such behavior.
It can be accomplished in 3 steps:
- Add similar method to code of TileCapabilityProxy:
public boolean isInLoop()
{
BlockPos pos = getPos();
TileEntity tileEntity = this;
do
{
TileCapabilityProxy proxy = (TileCapabilityProxy) tileEntity;
pos = proxy.getPos().offset(proxy.getOffset());
tileEntity = proxy.getWorld().getTileEntity(pos);
}
while (tileEntity instanceof TileCapabilityProxy && !pos.equals(getPos()));
return pos.equals(getPos());
}
- Call this method in
BlockCapabilityProxy.onBlockActivated
,TileCapabilityProxy.hasCapability
,TileCapabilityProxy.getCapability
. If this method return true, returnfalse
,false
,null
(respectively). - Deactivate proxy block, if this method returns
true
.
When exactly does the stackoverflow error occur? Can you send me the crashlog?
Because a stackoverflow protection actually already is in place.
@rubensworks
Place 4 proxy blocks in loop and right-click one of them.
BlockCapabilityProxy.onBlockActivate
just calls onBlockActivate
of next proxy block (in loop) and this causes StackOverflowException
.
Crash Report: https://pastebin.com/621eH87g