Skip to content

Commit

Permalink
prevent crash on book copy
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored and Wide-Cat committed Nov 29, 2023
1 parent 66544a9 commit a4d3cac
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
import meteordevelopment.meteorclient.gui.GuiThemes;
import meteordevelopment.meteorclient.gui.screens.EditBookTitleAndAuthorScreen;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.BookScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
Expand All @@ -20,6 +21,8 @@
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -63,7 +66,17 @@ private void onInit(CallbackInfo info) {
e.printStackTrace();
}

GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
String encoded = Base64.getEncoder().encodeToString(bytes.array);

@SuppressWarnings("resource")
long available = MemoryStack.stackGet().getPointer();
long size = MemoryUtil.memLengthUTF8(encoded, true);

if (size > available) {
ChatUtils.error("Could not copy to clipboard: Out of memory.");
} else {
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), encoded);
}
})
.position(4, 4)
.size(120, 20)
Expand Down

0 comments on commit a4d3cac

Please sign in to comment.