Fix crash on load when backend is off

- Closes #81
 - Disabled crashing on error poll
This commit is contained in:
Jozufozu 2021-12-28 20:39:32 -08:00
parent 92ad07c779
commit 123a548474
8 changed files with 50 additions and 33 deletions

View file

@ -12,7 +12,6 @@ import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.GlFence; import com.jozufozu.flywheel.backend.gl.GlFence;
import com.jozufozu.flywheel.backend.gl.error.GlError; import com.jozufozu.flywheel.backend.gl.error.GlError;
import com.jozufozu.flywheel.backend.gl.error.GlException; import com.jozufozu.flywheel.backend.gl.error.GlException;
import com.jozufozu.flywheel.util.StringUtil;
public class PersistentGlBuffer extends GlBuffer implements Mappable { public class PersistentGlBuffer extends GlBuffer implements Mappable {
@ -49,13 +48,6 @@ public class PersistentGlBuffer extends GlBuffer implements Mappable {
Backend.getInstance().compat.bufferStorage.bufferStorage(type, size, flags); Backend.getInstance().compat.bufferStorage.bufferStorage(type, size, flags);
GlError error = GlError.poll();
if (error != null) {
// If this error is being thrown but everything seems fine,
// GlError.poll() might be returning an error from something earlier.
throw new GlException(error, StringUtil.args("bufferStorage", type, size, flags));
}
ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags); ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags);
if (byteBuffer == null) { if (byteBuffer == null) {

View file

@ -5,8 +5,6 @@ import java.util.function.Supplier;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;
import com.jozufozu.flywheel.Flywheel;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -41,10 +39,10 @@ public enum GlError {
} }
public static void pollAndThrow(Supplier<String> context) { public static void pollAndThrow(Supplier<String> context) {
// TODO: build flag? to enable or disable this function // This was a bad idea.
GlError err = GlError.poll(); // GlError err = GlError.poll();
if (err != null) { // if (err != null) {
Flywheel.LOGGER.error("{}: {}", err.name(), context.get()); // Flywheel.LOGGER.error("{}: {}", err.name(), context.get());
} // }
} }
} }

View file

@ -29,8 +29,11 @@ public class InstancedRenderDispatcher {
* @param te The tile whose instance you want to update. * @param te The tile whose instance you want to update.
*/ */
public static void enqueueUpdate(BlockEntity te) { public static void enqueueUpdate(BlockEntity te) {
if (te.hasLevel() && te.getLevel() instanceof ClientLevel) if (Backend.isOn() && te.hasLevel() && te.getLevel() instanceof ClientLevel) {
getTiles(te.getLevel()).queueUpdate(te); instanceWorlds.get(te.getLevel())
.getTileEntityInstanceManager()
.queueUpdate(te);
}
} }
/** /**
@ -38,17 +41,29 @@ public class InstancedRenderDispatcher {
* @param entity The entity whose instance you want to update. * @param entity The entity whose instance you want to update.
*/ */
public static void enqueueUpdate(Entity entity) { public static void enqueueUpdate(Entity entity) {
getEntities(entity.level).queueUpdate(entity); if (Backend.isOn()) {
instanceWorlds.get(entity.level)
.getEntityInstanceManager()
.queueUpdate(entity);
}
} }
public static InstanceManager<BlockEntity> getTiles(LevelAccessor world) { public static InstanceManager<BlockEntity> getTiles(LevelAccessor world) {
return instanceWorlds.get(world) if (Backend.isOn()) {
.getTileEntityInstanceManager(); return instanceWorlds.get(world)
.getTileEntityInstanceManager();
} else {
throw new NullPointerException("Backend is off, cannot retrieve instance world.");
}
} }
public static InstanceManager<Entity> getEntities(LevelAccessor world) { public static InstanceManager<Entity> getEntities(LevelAccessor world) {
return instanceWorlds.get(world) if (Backend.isOn()) {
.getEntityInstanceManager(); return instanceWorlds.get(world)
.getEntityInstanceManager();
} else {
throw new NullPointerException("Backend is off, cannot retrieve instance world.");
}
} }
@SubscribeEvent @SubscribeEvent
@ -61,12 +76,15 @@ public class InstancedRenderDispatcher {
ClientLevel world = mc.level; ClientLevel world = mc.level;
AnimationTickHolder.tick(); AnimationTickHolder.tick();
instanceWorlds.get(world).tick(); if (Backend.isOn()) {
instanceWorlds.get(world)
.tick();
}
} }
@SubscribeEvent @SubscribeEvent
public static void onBeginFrame(BeginFrameEvent event) { public static void onBeginFrame(BeginFrameEvent event) {
if (Backend.isGameActive()) { if (Backend.isGameActive() && Backend.isOn()) {
instanceWorlds.get(event.getWorld()) instanceWorlds.get(event.getWorld())
.beginFrame(event); .beginFrame(event);
} }

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.event; package com.jozufozu.flywheel.event;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@ -13,13 +14,13 @@ public class EntityWorldHandler {
@SubscribeEvent @SubscribeEvent
public static void onEntityJoinWorld(EntityJoinWorldEvent event) { public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (event.getWorld().isClientSide) InstancedRenderDispatcher.getEntities(event.getWorld()) if (event.getWorld().isClientSide && Backend.isOn()) InstancedRenderDispatcher.getEntities(event.getWorld())
.queueAdd(event.getEntity()); .queueAdd(event.getEntity());
} }
@SubscribeEvent @SubscribeEvent
public static void onEntityLeaveWorld(EntityLeaveWorldEvent event) { public static void onEntityLeaveWorld(EntityLeaveWorldEvent event) {
if (event.getWorld().isClientSide) InstancedRenderDispatcher.getEntities(event.getWorld()) if (event.getWorld().isClientSide && Backend.isOn()) InstancedRenderDispatcher.getEntities(event.getWorld())
.remove(event.getEntity()); .remove(event.getEntity());
} }
} }

View file

@ -23,7 +23,7 @@ public class ChunkRebuildHooksMixin {
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true) @Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
private <E extends BlockEntity> void addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) { private <E extends BlockEntity> void addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) {
if (Backend.isOn() && Backend.isFlywheelWorld(be.getLevel())) { if (Backend.canUseInstancing(be.getLevel())) {
InstancedRenderRegistry registry = InstancedRenderRegistry.getInstance(); InstancedRenderRegistry registry = InstancedRenderRegistry.getInstance();
if (registry.canInstance(be.getType())) if (registry.canInstance(be.getType()))

View file

@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
@ -26,7 +27,9 @@ public class InstanceAddMixin {
@Inject(method = "setBlockEntity", @Inject(method = "setBlockEntity",
at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
private void tileAdded(BlockEntity be, CallbackInfo ci) { private void tileAdded(BlockEntity be, CallbackInfo ci) {
if (level.isClientSide) InstancedRenderDispatcher.getTiles(this.level) if (level.isClientSide && Backend.isOn()) {
.add(be); InstancedRenderDispatcher.getTiles(this.level)
.add(be);
}
} }
} }

View file

@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
@ -23,8 +24,10 @@ public class InstanceRemoveMixin {
@Inject(at = @At("TAIL"), method = "setRemoved") @Inject(at = @At("TAIL"), method = "setRemoved")
private void removeInstance(CallbackInfo ci) { private void removeInstance(CallbackInfo ci) {
if (level instanceof ClientLevel) InstancedRenderDispatcher.getTiles(this.level) if (level instanceof ClientLevel && Backend.isOn()) {
.remove((BlockEntity) (Object) this); InstancedRenderDispatcher.getTiles(this.level)
.remove((BlockEntity) (Object) this);
}
} }
// /** // /**

View file

@ -86,7 +86,9 @@ public class RenderHooksMixin {
*/ */
@Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V") @Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")
private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) { private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) {
InstancedRenderDispatcher.getTiles(level) if (Backend.isOn()) {
.update(level.getBlockEntity(pos)); InstancedRenderDispatcher.getTiles(level)
.update(level.getBlockEntity(pos));
}
} }
} }