Work around Flywheel leaving freed buffers in BufferBuilder
This commit is contained in:
parent
00fa8227c3
commit
5ff2951b5a
|
|
@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||||
import org.embeddedt.modernfix.render.UnsafeBufferHelper;
|
import org.embeddedt.modernfix.render.UnsafeBufferHelper;
|
||||||
|
import org.spongepowered.asm.mixin.Dynamic;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
@ -12,13 +13,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@Mixin(BufferBuilder.class)
|
@Mixin(value = BufferBuilder.class, priority = 1500)
|
||||||
@ClientOnlyMixin
|
@ClientOnlyMixin
|
||||||
public class BufferBuilderMixin {
|
public class BufferBuilderMixin {
|
||||||
@Shadow private ByteBuffer buffer;
|
@Shadow private ByteBuffer buffer;
|
||||||
|
|
||||||
private static boolean leakReported = false;
|
private static boolean leakReported = false;
|
||||||
|
|
||||||
|
private boolean mfix$shouldFree = true;
|
||||||
|
|
||||||
|
@Dynamic
|
||||||
|
@Inject(method = "flywheel$injectForRender", at = @At("RETURN"), remap = false, require = 0)
|
||||||
|
private void preventFree(CallbackInfo ci) {
|
||||||
|
mfix$shouldFree = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure UnsafeBufferHelper is classloaded early, to avoid Forge's event transformer showing an error in the log.
|
* Ensure UnsafeBufferHelper is classloaded early, to avoid Forge's event transformer showing an error in the log.
|
||||||
*/
|
*/
|
||||||
|
|
@ -32,7 +41,7 @@ public class BufferBuilderMixin {
|
||||||
try {
|
try {
|
||||||
ByteBuffer buf = buffer;
|
ByteBuffer buf = buffer;
|
||||||
// can be null if a mod already tried to free the buffer
|
// can be null if a mod already tried to free the buffer
|
||||||
if(buf != null) {
|
if(buf != null && mfix$shouldFree) {
|
||||||
if(!leakReported) {
|
if(!leakReported) {
|
||||||
leakReported = true;
|
leakReported = true;
|
||||||
ModernFix.LOGGER.warn("One or more BufferBuilders have been leaked, ModernFix will attempt to correct this.");
|
ModernFix.LOGGER.warn("One or more BufferBuilders have been leaked, ModernFix will attempt to correct this.");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user