Program: 30247
Project: 30247
Buggy source:
public void resize(int width,int height){
  Inventory inventory=World.getInstance().getInventory();
  tileSize=(int)DPIUtils.getTouchMinSize() * 2;
  margin=(int)DPIUtils.getMarginSize();
  rowSpace=DPIUtils.getSpacing();
  int w=(int)(width * .7f / tileSize) * tileSize;
  int h=(int)(height * .7f / tileSize) * tileSize;
  if (autosize) {
    if (inventoryPos == InventoryPos.LEFT || inventoryPos == InventoryPos.RIGHT) {
      int w2=tileSize * ((inventory.getNumItems() - 1) / (h / tileSize) + 1);
      if (w2 < w)       w=w2;
    }
 else {
      int h2=tileSize * ((inventory.getNumItems() - 1) / (w / tileSize) + 1);
      if (h2 < h)       h=h2;
    }
  }
  cols=w / tileSize;
  rows=h / tileSize;
  setVisible(false);
  setSize(w + (cols - 1) * rowSpace + margin * 2,h + (rows - 1) * rowSpace + margin * 2);
  int capacity=cols * rows;
  if (inventory.getNumItems() > capacity)   EngineLogger.error("String_Node_Str");
  if (inventoryPos == InventoryPos.TOP) {
    orgPos.set((width - getWidth()) / 2,height + getHeight());
    targetPos.set((width - getWidth()) / 2,height - getHeight() - DPIUtils.getSpacing());
  }
 else   if (inventoryPos == InventoryPos.DOWN) {
    orgPos.set((width - getWidth()) / 2,-getHeight());
    targetPos.set((width - getWidth()) / 2,DPIUtils.getSpacing());
  }
 else   if (inventoryPos == InventoryPos.LEFT) {
    orgPos.set(-getWidth(),(height - getHeight()) / 2);
    targetPos.set(DPIUtils.getSpacing(),(height - getHeight()) / 2);
  }
 else   if (inventoryPos == InventoryPos.RIGHT) {
    orgPos.set(width + getWidth(),(height - getHeight()) / 2);
    targetPos.set(width - getWidth() - DPIUtils.getSpacing(),(height - getHeight()) / 2);
  }
 else {
    orgPos.set((width - getWidth()) / 2,-getHeight());
    targetPos.set((width - getWidth()) / 2,(height - getHeight()) / 2);
  }
  setX(orgPos.x);
  setY(orgPos.y);
  if (menuButton != null) {
    menuButton.setPosition(getWidth() - menuButton.getWidth() / 2,(getHeight() - menuButton.getHeight()) / 2);
    float iconSize=DPIUtils.getPrefButtonSize();
    menuButton.setSize(iconSize,iconSize);
  }
}

Fixed version (ground truth):
public void resize(int width,int height){
  Inventory inventory=World.getInstance().getInventory();
  tileSize=(int)DPIUtils.getTouchMinSize() * 2;
  margin=(int)DPIUtils.getMarginSize();
  rowSpace=DPIUtils.getSpacing();
  int capacity=0;
  do {
    int w=(int)(width * .7f / tileSize) * tileSize;
    int h=(int)(height * .7f / tileSize) * tileSize;
    if (autosize) {
      if (inventoryPos == InventoryPos.LEFT || inventoryPos == InventoryPos.RIGHT) {
        int w2=tileSize * ((inventory.getNumItems() - 1) / (h / tileSize) + 1);
        if (w2 < w)         w=w2;
      }
 else {
        int h2=tileSize * ((inventory.getNumItems() - 1) / (w / tileSize) + 1);
        if (h2 < h)         h=h2;
      }
    }
    cols=w / tileSize;
    rows=h / tileSize;
    setSize(w + (cols - 1) * rowSpace + margin * 2,h + (rows - 1) * rowSpace + margin * 2);
    capacity=cols * rows;
    if (inventory.getNumItems() > capacity) {
      tileSize*=.8;
    }
  }
 while (inventory.getNumItems() > capacity);
  if (inventory.getNumItems() > capacity)   EngineLogger.error("String_Node_Str");
  setVisible(false);
  if (inventoryPos == InventoryPos.TOP) {
    orgPos.set((width - getWidth()) / 2,height + getHeight());
    targetPos.set((width - getWidth()) / 2,height - getHeight() - DPIUtils.getSpacing());
  }
 else   if (inventoryPos == InventoryPos.DOWN) {
    orgPos.set((width - getWidth()) / 2,-getHeight());
    targetPos.set((width - getWidth()) / 2,DPIUtils.getSpacing());
  }
 else   if (inventoryPos == InventoryPos.LEFT) {
    orgPos.set(-getWidth(),(height - getHeight()) / 2);
    targetPos.set(DPIUtils.getSpacing(),(height - getHeight()) / 2);
  }
 else   if (inventoryPos == InventoryPos.RIGHT) {
    orgPos.set(width + getWidth(),(height - getHeight()) / 2);
    targetPos.set(width - getWidth() - DPIUtils.getSpacing(),(height - getHeight()) / 2);
  }
 else {
    orgPos.set((width - getWidth()) / 2,-getHeight());
    targetPos.set((width - getWidth()) / 2,(height - getHeight()) / 2);
  }
  setX(orgPos.x);
  setY(orgPos.y);
  if (menuButton != null) {
    menuButton.setPosition(getWidth() - menuButton.getWidth() / 2,(getHeight() - menuButton.getHeight()) / 2);
    float iconSize=DPIUtils.getPrefButtonSize();
    menuButton.setSize(iconSize,iconSize);
  }
}