From 59e29ac9584fac149b9f6809440254bf2be58d0d Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 23 Jan 2021 23:32:23 -0800 Subject: [PATCH] that was a nasty crash os memory exception because memory that was being sent to the gpu was getting modified by another thread --- .../create/foundation/render/light/LightVolume.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index e0f251bcf..54b56b982 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -102,7 +102,7 @@ public class LightVolume { * Completely (re)populate this volume with block and sky lighting data. * This is expensive and should be avoided. */ - public void initialize(ILightReader world) { + public synchronized void initialize(ILightReader world) { BlockPos.Mutable pos = new BlockPos.Mutable(); int shiftX = textureVolume.minX; @@ -125,7 +125,7 @@ public class LightVolume { * Copy block light from the world into this volume. * @param worldVolume the region in the world to copy data from. */ - public void copyBlock(ILightReader world, GridAlignedBB worldVolume) { + public synchronized void copyBlock(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); int xShift = textureVolume.minX; @@ -147,7 +147,7 @@ public class LightVolume { * Copy sky light from the world into this volume. * @param worldVolume the region in the world to copy data from. */ - public void copySky(ILightReader world, GridAlignedBB worldVolume) { + public synchronized void copySky(ILightReader world, GridAlignedBB worldVolume) { BlockPos.Mutable pos = new BlockPos.Mutable(); int xShift = textureVolume.minX; @@ -177,11 +177,15 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); if (bufferDirty) { - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + uploadTexture(); bufferDirty = false; } } + private synchronized void uploadTexture() { + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + } + public void release() { GL12.glBindTexture(GL12.GL_TEXTURE_3D, 0); }