Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-20 01:40:06 +01:00
fix: clear player's history away from main thread if lock locked (#2457)
* fix: clear player's history away from main thread if lock locked - addresses crashing of #2448 * Correct lock usage * remove possibility for race condition
Dieser Commit ist enthalten in:
Ursprung
9fff77c088
Commit
50cc9bc528
@ -33,6 +33,7 @@ import com.fastasyncworldedit.core.limit.FaweLimit;
|
|||||||
import com.fastasyncworldedit.core.util.BrushCache;
|
import com.fastasyncworldedit.core.util.BrushCache;
|
||||||
import com.fastasyncworldedit.core.util.MainUtil;
|
import com.fastasyncworldedit.core.util.MainUtil;
|
||||||
import com.fastasyncworldedit.core.util.StringMan;
|
import com.fastasyncworldedit.core.util.StringMan;
|
||||||
|
import com.fastasyncworldedit.core.util.TaskManager;
|
||||||
import com.fastasyncworldedit.core.util.TextureHolder;
|
import com.fastasyncworldedit.core.util.TextureHolder;
|
||||||
import com.fastasyncworldedit.core.util.TextureUtil;
|
import com.fastasyncworldedit.core.util.TextureUtil;
|
||||||
import com.fastasyncworldedit.core.wrappers.WorldWrapper;
|
import com.fastasyncworldedit.core.wrappers.WorldWrapper;
|
||||||
@ -143,7 +144,7 @@ public class LocalSession implements TextureHolder {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
private transient volatile Integer historyNegativeIndex;
|
private transient volatile Integer historyNegativeIndex;
|
||||||
private transient final Lock historyWriteLock = new ReentrantLock(true);
|
private transient final ReentrantLock historyWriteLock = new ReentrantLock(true);
|
||||||
private final transient Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
|
private final transient Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
|
||||||
private transient Mask sourceMask;
|
private transient Mask sourceMask;
|
||||||
private transient TextureUtil texture;
|
private transient TextureUtil texture;
|
||||||
@ -405,6 +406,19 @@ public class LocalSession implements TextureHolder {
|
|||||||
*/
|
*/
|
||||||
public void clearHistory() {
|
public void clearHistory() {
|
||||||
//FAWE start
|
//FAWE start
|
||||||
|
if (Fawe.isMainThread() && !historyWriteLock.tryLock()) {
|
||||||
|
// Do not make main thread wait if we cannot immediately clear history (on player logout usually)
|
||||||
|
TaskManager.taskManager().async(this::clearHistoryTask);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
clearHistoryTask();
|
||||||
|
} finally {
|
||||||
|
historyWriteLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearHistoryTask() {
|
||||||
historyWriteLock.lock();
|
historyWriteLock.lock();
|
||||||
try {
|
try {
|
||||||
// Ensure that changesets are properly removed
|
// Ensure that changesets are properly removed
|
||||||
@ -420,8 +434,8 @@ public class LocalSession implements TextureHolder {
|
|||||||
save();
|
save();
|
||||||
historySize = 0;
|
historySize = 0;
|
||||||
currentWorld = null;
|
currentWorld = null;
|
||||||
//FAWE end
|
|
||||||
}
|
}
|
||||||
|
//FAWE end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remember an edit session for the undo history. If the history maximum
|
* Remember an edit session for the undo history. If the history maximum
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren