another attempt to fix async item view crashes
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ aebuild=7
|
|||||||
aegroup=appeng
|
aegroup=appeng
|
||||||
aebasename=appliedenergistics2
|
aebasename=appliedenergistics2
|
||||||
extended=extended_life
|
extended=extended_life
|
||||||
extendedversion=v0.54.11
|
extendedversion=v0.54.12
|
||||||
#########################################################
|
#########################################################
|
||||||
# Versions #
|
# Versions #
|
||||||
#########################################################
|
#########################################################
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ public class ItemRepo {
|
|||||||
|
|
||||||
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||||
private final List<IAEItemStack> view;
|
private final List<IAEItemStack> view;
|
||||||
|
private List<IAEItemStack> asyncUpdatedView;
|
||||||
|
private boolean updated;
|
||||||
private final IScrollSource src;
|
private final IScrollSource src;
|
||||||
private final ISortSource sortSrc;
|
private final ISortSource sortSrc;
|
||||||
|
|
||||||
@@ -62,17 +64,16 @@ public class ItemRepo {
|
|||||||
this.sortSrc = sortSrc;
|
this.sortSrc = sortSrc;
|
||||||
|
|
||||||
this.view = Collections.synchronizedList(new ArrayList<>());
|
this.view = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
this.asyncUpdatedView = Collections.synchronizedList(new ArrayList<>());
|
||||||
list.forEach(this.view::add);
|
list.forEach(this.view::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAEItemStack getReferenceItem(int idx) {
|
public IAEItemStack getReferenceItem(int idx) {
|
||||||
idx += this.src.getCurrentScroll() * this.rowSize;
|
idx += this.src.getCurrentScroll() * this.rowSize;
|
||||||
synchronized (this.view) {
|
if (idx >= this.view.size()) {
|
||||||
if (idx >= this.view.size()) {
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this.view.get(idx);
|
|
||||||
}
|
}
|
||||||
|
return this.view.get(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSearch(final String search) {
|
void setSearch(final String search) {
|
||||||
@@ -107,6 +108,13 @@ public class ItemRepo {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updated) {
|
||||||
|
this.view.clear();
|
||||||
|
this.view.addAll(asyncUpdatedView);
|
||||||
|
this.asyncUpdatedView.clear();
|
||||||
|
this.updated = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Since sortSrc is final, so we can safely call it inside lambda
|
// Since sortSrc is final, so we can safely call it inside lambda
|
||||||
searchTask = CompletableFuture.supplyAsync(() -> {
|
searchTask = CompletableFuture.supplyAsync(() -> {
|
||||||
IItemList<IAEItemStack> list = this.list.clone();
|
IItemList<IAEItemStack> list = this.list.clone();
|
||||||
@@ -210,15 +218,11 @@ public class ItemRepo {
|
|||||||
|
|
||||||
return view;
|
return view;
|
||||||
}).thenAcceptAsync(view -> {
|
}).thenAcceptAsync(view -> {
|
||||||
synchronized (this.view) {
|
this.updated = true;
|
||||||
this.view.clear();
|
this.asyncUpdatedView.addAll(view);
|
||||||
}
|
|
||||||
this.view.addAll(view);
|
|
||||||
}).thenRunAsync(() -> {
|
}).thenRunAsync(() -> {
|
||||||
this.searchTask = null; // Prevent redundant cancellation
|
this.searchTask = null; // Prevent redundant cancellation
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateJEI(String filter) {
|
private void updateJEI(String filter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user