Skip to content

Commit

Permalink
Fix dead lock when jumping backwards in time during rendering
Browse files Browse the repository at this point in the history
A jump backwards in time entails unloading the current world and with it
the ChunkRenderDispatcher that the ChunkLoadingRenderGlobal has locked.
  • Loading branch information
Johni0702 committed Mar 11, 2018
1 parent 13d5586 commit 76be6c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Expand Up @@ -22,15 +22,30 @@
public class ChunkLoadingRenderGlobal {

private final RenderGlobal hooked;
private final ChunkRenderDispatcher renderDispatcher;
private final JailingQueue<ChunkCompileTaskGenerator> workerJailingQueue;
private final CustomChunkRenderWorker renderWorker;
private ChunkRenderDispatcher renderDispatcher;
private JailingQueue<ChunkCompileTaskGenerator> workerJailingQueue;
private CustomChunkRenderWorker renderWorker;
private int frame;

@SuppressWarnings("unchecked")
public ChunkLoadingRenderGlobal(RenderGlobal renderGlobal) {
this.hooked = renderGlobal;
this.renderDispatcher = renderGlobal.renderDispatcher;

setup(renderGlobal.renderDispatcher);
}

public void updateRenderDispatcher(ChunkRenderDispatcher renderDispatcher) {
if (this.renderDispatcher != null) {
workerJailingQueue.freeAll();
this.renderDispatcher = null;
}
if (renderDispatcher != null) {
setup(renderDispatcher);
}
}

private void setup(ChunkRenderDispatcher renderDispatcher) {
this.renderDispatcher = renderDispatcher;
this.renderWorker = new CustomChunkRenderWorker(renderDispatcher, new RegionRenderCacheBuilder());

int workerThreads = renderDispatcher.listThreadedWorkers.size();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/replaymod/render/mixin/MixinRenderGlobal.java
Expand Up @@ -9,6 +9,7 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC<10904
Expand Down Expand Up @@ -66,4 +67,18 @@ public void replayModRender_updateChunks(long finishTimeNano, CallbackInfo ci) {
ci.cancel();
}
}

@Inject(method = "setWorldAndLoadRenderers", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher;stopWorkerThreads()V"))
private void stopWorkerThreadsAndChunkLoadingRenderGlobal(CallbackInfo ci) {
if (replayModRender_hook != null) {
replayModRender_hook.updateRenderDispatcher(null);
}
}

@Inject(method = "loadRenderers", at = @At(value = "RETURN"))
private void setupChunkLoadingRenderGlobal(CallbackInfo ci) {
if (replayModRender_hook != null) {
replayModRender_hook.updateRenderDispatcher(renderDispatcher);
}
}
}

0 comments on commit 76be6c1

Please sign in to comment.