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()];
|
friendsChatRankImages = new BufferedImage[friendsChatIcons.size()];
|
||||||
clanRankImages = new BufferedImage[clanIcons.size()];
|
clanRankImages = new BufferedImage[clanIcons.size()];
|
||||||
|
|
||||||
final IndexedSprite[] modIcons = client.getModIcons();
|
|
||||||
|
|
||||||
for (int i = 0; i < friendsChatIcons.size(); i++)
|
for (int i = 0; i < friendsChatIcons.size(); i++)
|
||||||
{
|
{
|
||||||
final int fi = i;
|
final int fi = i;
|
||||||
|
|
||||||
spriteManager.getSpriteAsync(friendsChatIcons.getIntValue(friendsChatIcons.getKeys()[i]), 0, sprite ->
|
spriteManager.getSpriteAsync(friendsChatIcons.getIntValue(friendsChatIcons.getKeys()[i]), 0, sprite ->
|
||||||
{
|
{
|
||||||
|
final IndexedSprite[] modIcons = client.getModIcons();
|
||||||
friendsChatRankImages[fi] = friendsChatImageFromSprite(sprite);
|
friendsChatRankImages[fi] = friendsChatImageFromSprite(sprite);
|
||||||
modIcons[friendsChatOffset + fi] = ImageUtil.getImageIndexedSprite(friendsChatRankImages[fi], client);
|
modIcons[friendsChatOffset + fi] = ImageUtil.getImageIndexedSprite(friendsChatRankImages[fi], client);
|
||||||
});
|
});
|
||||||
@@ -147,6 +146,7 @@ public class ChatIconManager
|
|||||||
|
|
||||||
spriteManager.getSpriteAsync(clanIcons.getIntValue(key), 0, sprite ->
|
spriteManager.getSpriteAsync(clanIcons.getIntValue(key), 0, sprite ->
|
||||||
{
|
{
|
||||||
|
final IndexedSprite[] modIcons = client.getModIcons();
|
||||||
final BufferedImage img = ImageUtil.resizeCanvas(sprite, IMAGE_DIMENSION.width, IMAGE_DIMENSION.height);
|
final BufferedImage img = ImageUtil.resizeCanvas(sprite, IMAGE_DIMENSION.width, IMAGE_DIMENSION.height);
|
||||||
clanRankImages[idx] = img;
|
clanRankImages[idx] = img;
|
||||||
modIcons[clanOffset + idx] = ImageUtil.getImageIndexedSprite(img, client);
|
modIcons[clanOffset + idx] = ImageUtil.getImageIndexedSprite(img, client);
|
||||||
|
|||||||
@@ -313,9 +313,12 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
final Pet[] pets = Pet.values();
|
final Pet[] pets = Pet.values();
|
||||||
final IndexedSprite[] modIcons = client.getModIcons();
|
final IndexedSprite[] modIcons = client.getModIcons();
|
||||||
assert modIcons != null;
|
assert modIcons != null;
|
||||||
|
|
||||||
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + pets.length);
|
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + pets.length);
|
||||||
modIconIdx = modIcons.length;
|
modIconIdx = modIcons.length;
|
||||||
|
|
||||||
|
client.setModIcons(newModIcons);
|
||||||
|
|
||||||
for (int i = 0; i < pets.length; i++)
|
for (int i = 0; i < pets.length; i++)
|
||||||
{
|
{
|
||||||
final Pet pet = pets[i];
|
final Pet pet = pets[i];
|
||||||
@@ -326,13 +329,13 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
final BufferedImage image = ImageUtil.resizeImage(abi, 18, 16);
|
final BufferedImage image = ImageUtil.resizeImage(abi, 18, 16);
|
||||||
final IndexedSprite sprite = ImageUtil.getImageIndexedSprite(image, client);
|
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);
|
abi.onLoaded(r);
|
||||||
r.run();
|
r.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
client.setModIcons(newModIcons);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user