Skip to content

Commit 5ff2951

Browse files
committed
Work around Flywheel leaving freed buffers in BufferBuilder
1 parent 00fa822 commit 5ff2951

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/buffer_builder_leak/BufferBuilderMixin.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.embeddedt.modernfix.ModernFix;
55
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
66
import org.embeddedt.modernfix.render.UnsafeBufferHelper;
7+
import org.spongepowered.asm.mixin.Dynamic;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Shadow;
910
import org.spongepowered.asm.mixin.injection.At;
@@ -12,13 +13,21 @@
1213

1314
import java.nio.ByteBuffer;
1415

15-
@Mixin(BufferBuilder.class)
16+
@Mixin(value = BufferBuilder.class, priority = 1500)
1617
@ClientOnlyMixin
1718
public class BufferBuilderMixin {
1819
@Shadow private ByteBuffer buffer;
1920

2021
private static boolean leakReported = false;
2122

23+
private boolean mfix$shouldFree = true;
24+
25+
@Dynamic
26+
@Inject(method = "flywheel$injectForRender", at = @At("RETURN"), remap = false, require = 0)
27+
private void preventFree(CallbackInfo ci) {
28+
mfix$shouldFree = false;
29+
}
30+
2231
/**
2332
* Ensure UnsafeBufferHelper is classloaded early, to avoid Forge's event transformer showing an error in the log.
2433
*/
@@ -32,7 +41,7 @@ protected void finalize() throws Throwable {
3241
try {
3342
ByteBuffer buf = buffer;
3443
// can be null if a mod already tried to free the buffer
35-
if(buf != null) {
44+
if(buf != null && mfix$shouldFree) {
3645
if(!leakReported) {
3746
leakReported = true;
3847
ModernFix.LOGGER.warn("One or more BufferBuilders have been leaked, ModernFix will attempt to correct this.");

0 commit comments

Comments
 (0)