Skip to content

Commit

Permalink
4.4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfudge committed Aug 12, 2024
1 parent 2a9c9dc commit f4635c1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 55 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### 4.4.8
- Removed a fringe feature that was eating away at the computer's memory
### 4.4.7
- Fixed crash in certain cases
### 4.4.6
Expand Down
61 changes: 30 additions & 31 deletions common/src/main/java/fudge/notenoughcrashes/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@
import java.util.Iterator;
import java.util.Set;

/**
* Allows registering objects to be reset after a crash. Objects registered
* use WeakReferences, so they will be garbage-collected despite still being
* registered here.
*/
public class StateManager {

// Use WeakReference to allow garbage collection, preventing memory leaks
private static final Set<WeakReference<IResettable>> resettableRefs = new HashSet<>();

public static void resetStates() {
Iterator<WeakReference<IResettable>> iterator = resettableRefs.iterator();
while (iterator.hasNext()) {
IResettable ref = iterator.next().get();
if (ref != null) {
ref.resetState();
} else {
iterator.remove();
}
}
}

public interface IResettable {

default void register() {
resettableRefs.add(new WeakReference<>(this));
}

void resetState();
}
}
///**
// * Allows registering objects to be reset after a crash. Objects registered
// * use WeakReferences, so they will be garbage-collected despite still being
// * registered here.
// */
//public class StateManager {
//
// // Use WeakReference to allow garbage collection, preventing memory leaks
// private static final Set<WeakReference<IResettable>> resettableRefs = new HashSet<>();
//
// public static void resetStates() {
// Iterator<WeakReference<IResettable>> iterator = resettableRefs.iterator();
// while (iterator.hasNext()) {
// IResettable ref = iterator.next().get();
// if (ref != null) {
// ref.resetState();
// } else {
// iterator.remove();
// }
// }
// }
//
// public interface IResettable {
// default void register() {
// resettableRefs.add(new WeakReference<>(this));
// }
//
// void resetState();
// }
//}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fudge.notenoughcrashes.mixinhandlers;

import fudge.notenoughcrashes.NotEnoughCrashes;
import fudge.notenoughcrashes.StateManager;
import fudge.notenoughcrashes.config.NecConfig;
import fudge.notenoughcrashes.gui.CrashScreen;
import fudge.notenoughcrashes.patches.MinecraftClientAccess;
Expand Down Expand Up @@ -40,7 +39,7 @@ public static void handleClientCrash(CrashReport report) {

private static void resetStates() {
GlUtil.resetState();
StateManager.resetStates();
// StateManager.resetStates();
resetModState();
resetCriticalGameState();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fudge.notenoughcrashes.mixins.client;

import fudge.notenoughcrashes.StateManager;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BuiltBuffer;
import net.minecraft.client.render.VertexFormat;
Expand All @@ -11,22 +10,22 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BufferBuilder.class)
public abstract class MixinBufferBuilder implements StateManager.IResettable {

@Shadow private boolean building;

@Shadow public abstract BuiltBuffer end();

@Inject(method = "<init>", at = @At("RETURN"))
public void onInit(BufferAllocator allocator, VertexFormat.DrawMode drawMode, VertexFormat format, CallbackInfo ci) {
register();
}

@Override
public void resetState() {
if (building) {
end();
}
}
}
//@Mixin(BufferBuilder.class)
//public abstract class MixinBufferBuilder implements StateManager.IResettable {
//
// @Shadow private boolean building;
//
// @Shadow public abstract BuiltBuffer end();
//
// @Inject(method = "<init>", at = @At("RETURN"))
// public void onInit(BufferAllocator allocator, VertexFormat.DrawMode drawMode, VertexFormat format, CallbackInfo ci) {
//// register();
// }
//
// @Override
// public void resetState() {
// if (building) {
// end();
// }
// }
//}
1 change: 0 additions & 1 deletion common/src/main/resources/notenoughcrashes.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"MixinTileEntity"
],
"client": [
"client.MixinBufferBuilder",
"client.MixinKeyboard",
"client.MixinMinecraftClient",
"client.MixinMinecraftServerClientOnly"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ task_tree = { id = "com.dorongold.task-tree", version.ref = "task_tree" }
[versions]

# This Mod Version
mod_version = "4.4.7"
mod_version = "4.4.8"

# Gradle Plugins
architectury_plugin = "3.4-SNAPSHOT"
Expand Down

0 comments on commit f4635c1

Please sign in to comment.