fix race loading modicons
It can't be assumed the array passed to setModIcons is still correct in the async image callbacks. Instead, fetch the current modicons array in the callback and use that.
This commit is contained in:
@@ -125,14 +125,13 @@ public class ChatIconManager
|
||||
friendsChatRankImages = new BufferedImage[friendsChatIcons.size()];
|
||||
clanRankImages = new BufferedImage[clanIcons.size()];
|
||||
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
|
||||
for (int i = 0; i < friendsChatIcons.size(); i++)
|
||||
{
|
||||
final int fi = i;
|
||||
|
||||
spriteManager.getSpriteAsync(friendsChatIcons.getIntValue(friendsChatIcons.getKeys()[i]), 0, sprite ->
|
||||
{
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
friendsChatRankImages[fi] = friendsChatImageFromSprite(sprite);
|
||||
modIcons[friendsChatOffset + fi] = ImageUtil.getImageIndexedSprite(friendsChatRankImages[fi], client);
|
||||
});
|
||||
@@ -147,6 +146,7 @@ public class ChatIconManager
|
||||
|
||||
spriteManager.getSpriteAsync(clanIcons.getIntValue(key), 0, sprite ->
|
||||
{
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
final BufferedImage img = ImageUtil.resizeCanvas(sprite, IMAGE_DIMENSION.width, IMAGE_DIMENSION.height);
|
||||
clanRankImages[idx] = img;
|
||||
modIcons[clanOffset + idx] = ImageUtil.getImageIndexedSprite(img, client);
|
||||
|
||||
@@ -313,9 +313,12 @@ public class ChatCommandsPlugin extends Plugin
|
||||
final Pet[] pets = Pet.values();
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
assert modIcons != null;
|
||||
|
||||
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + pets.length);
|
||||
modIconIdx = modIcons.length;
|
||||
|
||||
client.setModIcons(newModIcons);
|
||||
|
||||
for (int i = 0; i < pets.length; i++)
|
||||
{
|
||||
final Pet pet = pets[i];
|
||||
@@ -326,13 +329,13 @@ public class ChatCommandsPlugin extends Plugin
|
||||
{
|
||||
final BufferedImage image = ImageUtil.resizeImage(abi, 18, 16);
|
||||
final IndexedSprite sprite = ImageUtil.getImageIndexedSprite(image, client);
|
||||
newModIcons[idx] = sprite;
|
||||
// modicons array might be replaced in between when we assign it and the callback,
|
||||
// so fetch modicons again
|
||||
client.getModIcons()[idx] = sprite;
|
||||
};
|
||||
abi.onLoaded(r);
|
||||
r.run();
|
||||
}
|
||||
|
||||
client.setModIcons(newModIcons);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user