Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public int add (Image image) {
int count = OS.ImageList_GetImageCount (handle);
int index = 0;
while (index < count) {
if (images [index] != null) {
if (images [index].isDisposed ()) images [index] = null;
}
if (images [index] == null) break;
Image imageAtIndex = getOrClearIfDisposed(index);
if (imageAtIndex == null) break;
index++;
}
if (count == 0) {
Expand All @@ -71,6 +69,13 @@ public int add (Image image) {
return index;
}

private Image getOrClearIfDisposed(int index) {
if (images[index] != null && images[index].isDisposed()) {
images[index] = null;
}
return images[index];
}

public int addRef() {
return ++refCount;
}
Expand Down Expand Up @@ -337,7 +342,7 @@ public long getHandle(int targetZoom) {
long newImageListHandle = OS.ImageList_Create(scaledWidth, scaledHeight, flags, 16, 16);
int count = OS.ImageList_GetImageCount (handle);
for (int i = 0; i < count; i++) {
Image image = images[i];
Image image = getOrClearIfDisposed(i);
if (image != null) {
set(i, image, i, newImageListHandle, targetZoom);
} else {
Expand Down Expand Up @@ -372,9 +377,9 @@ public Point getImageSize() {
public int indexOf (Image image) {
int count = OS.ImageList_GetImageCount (handle);
for (int i=0; i<count; i++) {
if (images [i] != null) {
if (images [i].isDisposed ()) images [i] = null;
if (images [i] != null && images [i].equals (image)) return i;
Image potentialMatch = getOrClearIfDisposed(i);
if (potentialMatch != null && potentialMatch.equals(image)) {
return i;
}
}
return -1;
Expand Down Expand Up @@ -480,9 +485,9 @@ public int size () {
int result = 0;
int count = OS.ImageList_GetImageCount (handle);
for (int i=0; i<count; i++) {
if (images [i] != null) {
if (images [i].isDisposed ()) images [i] = null;
if (images [i] != null) result++;
Image image = getOrClearIfDisposed(i);
if (image != null) {
result++;
}
}
return result;
Expand Down
Loading