Added memory verification option
This commit is contained in:
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.21
|
minecraft_version=1.21
|
||||||
yarn_mappings=1.21+build.2
|
yarn_mappings=1.21+build.2
|
||||||
loader_version=0.15.11
|
loader_version=0.16.5
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.6-alpha
|
mod_version = 0.1.6-alpha
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
|
|||||||
Arrays.stream(world.getMapper().getBiomeEntries()).forEach(this.modelService::addBiome);
|
Arrays.stream(world.getMapper().getBiomeEntries()).forEach(this.modelService::addBiome);
|
||||||
world.getMapper().setBiomeCallback(this.modelService::addBiome);
|
world.getMapper().setBiomeCallback(this.modelService::addBiome);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
final int H_WIDTH = 1;
|
final int H_WIDTH = 1;
|
||||||
for (int x = -H_WIDTH; x <= H_WIDTH; x++) {
|
for (int x = -H_WIDTH; x <= H_WIDTH; x++) {
|
||||||
@@ -80,8 +81,8 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
|
|||||||
this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, x, y, z));
|
this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
*/
|
router.watch(WorldEngine.getWorldSectionId(4, 0,0,0), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup(Camera camera) {
|
public void setup(Camera camera) {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package me.cortex.voxy.client.core.rendering.building;
|
package me.cortex.voxy.client.core.rendering.building;
|
||||||
|
|
||||||
import me.cortex.voxy.common.util.MemoryBuffer;
|
import me.cortex.voxy.common.util.MemoryBuffer;
|
||||||
|
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
//TODO: also have an AABB size stored
|
//TODO: also have an AABB size stored
|
||||||
public final class BuiltSection {
|
public final class BuiltSection {
|
||||||
public static final boolean VERIFY_BUILT_SECTION_OFFSETS = System.getProperty("voxy.verifyBuiltSectionOffsets", "true").equals("true");
|
public static final boolean VERIFY_BUILT_SECTION_OFFSETS = VoxyCommon.isVerificationFlagOn("verifyBuiltSectionOffsets");
|
||||||
public final long position;
|
public final long position;
|
||||||
public final int aabb;
|
public final int aabb;
|
||||||
public final MemoryBuffer geometryBuffer;
|
public final MemoryBuffer geometryBuffer;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package me.cortex.voxy.common.util;
|
package me.cortex.voxy.common.util;
|
||||||
|
|
||||||
|
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||||
|
|
||||||
import java.lang.ref.Cleaner;
|
import java.lang.ref.Cleaner;
|
||||||
|
|
||||||
public abstract class TrackedObject {
|
public abstract class TrackedObject {
|
||||||
//TODO: maybe make this false? for performance overhead?
|
//TODO: maybe make this false? for performance overhead?
|
||||||
public static final boolean TRACK_OBJECT_ALLOCATIONS = System.getProperty("voxy.ensureTrackedObjectsAreFreed", "true").equals("true");
|
public static final boolean TRACK_OBJECT_ALLOCATIONS = VoxyCommon.isVerificationFlagOn("ensureTrackedObjectsAreFreed");
|
||||||
public static final boolean TRACK_OBJECT_ALLOCATION_STACKS = System.getProperty("voxy.trackObjectAllocationStacks", "true").equals("true");
|
public static final boolean TRACK_OBJECT_ALLOCATION_STACKS = VoxyCommon.isVerificationFlagOn("trackObjectAllocationStacks");
|
||||||
|
|
||||||
private final Ref ref;
|
private final Ref ref;
|
||||||
protected TrackedObject() {
|
protected TrackedObject() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.longs.LongArrayList;
|
|||||||
import me.cortex.voxy.common.util.MemoryBuffer;
|
import me.cortex.voxy.common.util.MemoryBuffer;
|
||||||
import me.cortex.voxy.common.util.UnsafeUtil;
|
import me.cortex.voxy.common.util.UnsafeUtil;
|
||||||
import me.cortex.voxy.common.world.other.Mapper;
|
import me.cortex.voxy.common.world.other.Mapper;
|
||||||
|
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -13,7 +14,8 @@ import java.nio.ByteBuffer;
|
|||||||
import static org.lwjgl.util.zstd.Zstd.*;
|
import static org.lwjgl.util.zstd.Zstd.*;
|
||||||
|
|
||||||
public class SaveLoadSystem {
|
public class SaveLoadSystem {
|
||||||
public static final boolean VERIFY_HASH_ON_LOAD = System.getProperty("voxy.verifySectionOnLoad", "true").equals("true");
|
public static final boolean VERIFY_HASH_ON_LOAD = VoxyCommon.isVerificationFlagOn("verifySectionHash");
|
||||||
|
public static final boolean VERIFY_MEMORY_ACCESS = VoxyCommon.isVerificationFlagOn("verifyMemoryAccess");
|
||||||
public static final int BIGGEST_SERIALIZED_SECTION_SIZE = 32 * 32 * 32 * 8 * 2 + 8;
|
public static final int BIGGEST_SERIALIZED_SECTION_SIZE = 32 * 32 * 32 * 8 * 2 + 8;
|
||||||
|
|
||||||
public static int lin2z(int i) {//y,z,x
|
public static int lin2z(int i) {//y,z,x
|
||||||
@@ -86,12 +88,15 @@ public class SaveLoadSystem {
|
|||||||
|
|
||||||
public static boolean deserialize(WorldSection section, MemoryBuffer data) {
|
public static boolean deserialize(WorldSection section, MemoryBuffer data) {
|
||||||
long ptr = data.address;
|
long ptr = data.address;
|
||||||
long key = MemoryUtil.memGetLong(ptr); ptr += 8;
|
long key = MemoryUtil.memGetLong(ptr); ptr += 8; if (VERIFY_MEMORY_ACCESS && data.size<=(ptr-data.address)) throw new IllegalStateException("Memory access OOB");
|
||||||
|
|
||||||
long metadata = MemoryUtil.memGetLong(ptr); ptr += 8;
|
long metadata = MemoryUtil.memGetLong(ptr); ptr += 8; if (VERIFY_MEMORY_ACCESS && data.size<=(ptr-data.address)) throw new IllegalStateException("Memory access OOB");
|
||||||
section.nonEmptyChildren = (byte) (metadata&0xFF);
|
section.nonEmptyChildren = (byte) (metadata&0xFF);
|
||||||
|
|
||||||
int lutLen = MemoryUtil.memGetInt(ptr); ptr += 4;
|
int lutLen = MemoryUtil.memGetInt(ptr); ptr += 4; if (VERIFY_MEMORY_ACCESS && data.size<=(ptr-data.address)) throw new IllegalStateException("Memory access OOB");
|
||||||
|
if (lutLen > 32*32*32) {
|
||||||
|
throw new IllegalStateException("lutLen impossibly large, max size should be 32768 but got size " + lutLen);
|
||||||
|
}
|
||||||
long[] lut = new long[lutLen];
|
long[] lut = new long[lutLen];
|
||||||
long hash = 0;
|
long hash = 0;
|
||||||
if (VERIFY_HASH_ON_LOAD) {
|
if (VERIFY_HASH_ON_LOAD) {
|
||||||
@@ -99,7 +104,7 @@ public class SaveLoadSystem {
|
|||||||
hash ^= metadata; hash *= 1242629872171L;
|
hash ^= metadata; hash *= 1242629872171L;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < lutLen; i++) {
|
for (int i = 0; i < lutLen; i++) {
|
||||||
lut[i] = MemoryUtil.memGetLong(ptr); ptr += 8;
|
lut[i] = MemoryUtil.memGetLong(ptr); ptr += 8; if (VERIFY_MEMORY_ACCESS && data.size<=(ptr-data.address)) throw new IllegalStateException("Memory access OOB");
|
||||||
if (VERIFY_HASH_ON_LOAD) {
|
if (VERIFY_HASH_ON_LOAD) {
|
||||||
hash *= 1230987149811L;
|
hash *= 1230987149811L;
|
||||||
hash += 12831;
|
hash += 12831;
|
||||||
@@ -115,7 +120,7 @@ public class SaveLoadSystem {
|
|||||||
|
|
||||||
int nonEmptyBlockCount = 0;
|
int nonEmptyBlockCount = 0;
|
||||||
for (int i = 0; i < section.data.length; i++) {
|
for (int i = 0; i < section.data.length; i++) {
|
||||||
long state = lut[MemoryUtil.memGetShort(ptr)]; ptr += 2;
|
long state = lut[MemoryUtil.memGetShort(ptr)]; ptr += 2; if (VERIFY_MEMORY_ACCESS && data.size<=(ptr-data.address)) throw new IllegalStateException("Memory access OOB");
|
||||||
nonEmptyBlockCount += Mapper.isAir(state)?0:1;
|
nonEmptyBlockCount += Mapper.isAir(state)?0:1;
|
||||||
section.data[z2lin(i)] = state;
|
section.data[z2lin(i)] = state;
|
||||||
}
|
}
|
||||||
@@ -131,7 +136,7 @@ public class SaveLoadSystem {
|
|||||||
}
|
}
|
||||||
hash ^= pHash;
|
hash ^= pHash;
|
||||||
|
|
||||||
long expectedHash = MemoryUtil.memGetLong(ptr); ptr += 8;
|
long expectedHash = MemoryUtil.memGetLong(ptr); ptr += 8; if (VERIFY_MEMORY_ACCESS && data.size<(ptr-data.address)) throw new IllegalStateException("Memory access OOB");
|
||||||
if (expectedHash != hash) {
|
if (expectedHash != hash) {
|
||||||
//throw new IllegalStateException("Hash mismatch got: " + hash + " expected: " + expectedHash);
|
//throw new IllegalStateException("Hash mismatch got: " + hash + " expected: " + expectedHash);
|
||||||
System.err.println("Hash mismatch got: " + hash + " expected: " + expectedHash + " removing region");
|
System.err.println("Hash mismatch got: " + hash + " expected: " + expectedHash + " removing region");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package me.cortex.voxy.common.world;
|
|||||||
|
|
||||||
|
|
||||||
import me.cortex.voxy.client.Voxy;
|
import me.cortex.voxy.client.Voxy;
|
||||||
|
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||||
import net.minecraft.util.Pair;
|
import net.minecraft.util.Pair;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
@@ -14,7 +15,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
//Represents a loaded world section at a specific detail level
|
//Represents a loaded world section at a specific detail level
|
||||||
// holds a 32x32x32 region of detail
|
// holds a 32x32x32 region of detail
|
||||||
public final class WorldSection {
|
public final class WorldSection {
|
||||||
public static final boolean VERIFY_WORLD_SECTION_EXECUTION = System.getProperty("voxy.verifyWorldSectionExecution", "true").equals("true");
|
public static final boolean VERIFY_WORLD_SECTION_EXECUTION = VoxyCommon.isVerificationFlagOn("verifyWorldSectionExecution");
|
||||||
|
|
||||||
|
|
||||||
private static final VarHandle ATOMIC_STATE_HANDLE;
|
private static final VarHandle ATOMIC_STATE_HANDLE;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package me.cortex.voxy.commonImpl;
|
package me.cortex.voxy.commonImpl;
|
||||||
|
|
||||||
import me.cortex.voxy.common.config.Serialization;
|
import me.cortex.voxy.common.config.Serialization;
|
||||||
import me.cortex.voxy.common.thread.ServiceThreadPool;
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
|
||||||
@@ -34,4 +32,11 @@ public class VoxyCommon implements ModInitializer {
|
|||||||
public static void breakpoint() {
|
public static void breakpoint() {
|
||||||
int breakpoint = 0;
|
int breakpoint = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//This is hardcoded like this because people do not understand what they are doing
|
||||||
|
private static final boolean GlobalVerificationDisableOverride = false;//System.getProperty("voxy.verificationDisableOverride", "false").equals("true");
|
||||||
|
public static boolean isVerificationFlagOn(String name) {
|
||||||
|
return (!GlobalVerificationDisableOverride) && System.getProperty("voxy."+name, "true").equals("true");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ layout(local_size_x=LOCAL_SIZE) in;//, local_size_y=1
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
uint node = getCurrentNode();
|
uint node = getCurrentNode();
|
||||||
if (node != SENTINAL_OUT_OF_BOUNDS) {
|
if (node != SENTINAL_OUT_OF_BOUNDS && queueIdx != 4) {
|
||||||
printf("GID:%d, NODE %d, %d, AA, %d, %d, %d, %d", gl_GlobalInvocationID.x, node, queueIdx, nodeQueueMetadata[queueIdx].x, nodeQueueMetadata[queueIdx].y, nodeQueueMetadata[queueIdx].z, nodeQueueMetadata[queueIdx].w);
|
printf("GID:%d, NODE %d, %d, AA, %d, %d, %d, %d", gl_GlobalInvocationID.x, node, queueIdx, nodeQueueMetadata[queueIdx].x, nodeQueueMetadata[queueIdx].y, nodeQueueMetadata[queueIdx].z, nodeQueueMetadata[queueIdx].w);
|
||||||
pushNodesInit(1);
|
pushNodesInit(1);
|
||||||
pushNode(node);
|
pushNode(node);
|
||||||
|
|||||||
Reference in New Issue
Block a user