Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak of Server Player if any Fake Player is created with UUID that does not match any player #1487

Open
pietro-lopes opened this issue Aug 24, 2024 · 0 comments
Labels
1.21.1 Targeted at Minecraft 1.21.1 bug A bug or error triage Needs triaging and confirmation

Comments

@pietro-lopes
Copy link

pietro-lopes commented Aug 24, 2024

Minecraft Version: 1.21.1

NeoForge Version: 21.1.22

Logs:
image

Steps to Reproduce:

   private static int sequential = 0;
   private void requestFakePlayer(PlayerInteractEvent.RightClickItem event) {
       if (event.getEntity() instanceof ServerPlayer player && player.level() instanceof ServerLevel level) {
           // This one does NOT leaked because when you have
           // the same UUID as player you grab the same advancement
           // so this FakePlayer is not added to Criteria Triggers listeners
           if (event.getItemStack().getItem() == Items.STONE) {
               var fakePlayer = FakePlayerFactory.get(level, player.getGameProfile());
               reportFakePlayerCreated(player, fakePlayer);
           }
           // This one leaks, fails the uuid check and generate new PlayerAdvancements
           // triggering Criteria listeners
           if (event.getItemStack().getItem() == Items.STICK) {
               var gameProfile = new GameProfile(UUID.randomUUID(), "FakePlayer" + sequential++);
               var fakePlayer = FakePlayerFactory.get(level, gameProfile);
               reportFakePlayerCreated(player, fakePlayer);
           }
           // This also leaks, fails the uuid check and generate new PlayerAdvancements
          // triggering Criteria listeners
           if (event.getItemStack().getItem() == Items.ACACIA_BUTTON) {
               var fakePlayer = FakePlayerFactory.getMinecraft(level);
               reportFakePlayerCreated(player, fakePlayer);
           }
       }
   }

   private static void reportFakePlayerCreated(ServerPlayer player, FakePlayer fakePlayer) {
       player.sendSystemMessage(Component.translatable("FakePlayer %s created with profile: %s", fakePlayer.getDisplayName(), fakePlayer.getGameProfile().toString()));
   }
  1. Code for reference
  2. Grab one of the 3 items (stone, stick, acacia button) to test
  3. Use it
  4. Leave world, come back, check objects

Description of issue:
Comments in code
I have seen a lot of modders do not use same UUID as the player, and from what I tested, if you fakePlayer.getAdvancements().stopListening() it bandaid fixes this issue.

@pietro-lopes pietro-lopes added the triage Needs triaging and confirmation label Aug 24, 2024
@sciwhiz12 sciwhiz12 added bug A bug or error 1.21.1 Targeted at Minecraft 1.21.1 labels Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.1 Targeted at Minecraft 1.21.1 bug A bug or error triage Needs triaging and confirmation
Projects
None yet
Development

No branches or pull requests

2 participants