mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00: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
This commit is contained in:
parent
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
|
||||||
|
Loading…
Reference in New Issue
Block a user