terrarium-earth / Common-Storage-Lib

A Cross platform library for transferring and storing fluids, items and energy
MIT License
25 stars 4 forks source link

[1.19.2][Fabric] PlatformFluidItemHandler.getTankAmount causes Infinite Loop #10

Closed gisellevonbingen closed 1 year ago

gisellevonbingen commented 1 year ago

I saw ServerThread be paused when called PlatformFluidItemHandler.getTankAmount in fabric. Because occur Infinite loop by 'while (storage.iterator().hasNext())' in below codes. Looks incorrect usage of iterator.

https://github.com/terrarium-earth/Botarium/blob/6c9133a87739175682c49809fde89527bb41deef/fabric/src/main/java/earth/terrarium/botarium/fabric/fluid/FabricFluidHandler.java#L39-L46 https://github.com/terrarium-earth/Botarium/blob/b8cbebf32758abf48b9d22b17fcfbedea81f2b85/fabric/src/main/java/earth/terrarium/botarium/fabric/fluid/FabricFluidItemHandler.java#L53-L60

Must call next() of iterator in loop. This is just example. (Not tested)

@Override
public int getTankAmount() {
    int size = 0;
    Iterator<StorageView<FluidVariant>> iterator = storage.iterator();
    while (iterator.hasNext()) {
        iterator.next();
        size++;
    }
    return size;
}
CodexAdrian commented 1 year ago

Fixed in 1.17.12