#Memory crash screen

60 messages · Page 1 of 1 (latest)

raven star
#

I have went back and I am getting an old modpack of mine to work with 1.21.4, which I named "the 128mb pack". The sole purpose of it is to make the game run on 128MB of allocated memory (which it does), but it also constantly runs out of memory if you do something it doesn't like. When it runs out of memory though, usually the game completely freezes.

The premise of catching this is to wait for an OutOfMemoryException, and then activate.

My idea with this is a mod that shows you an out of memory screen with a button to quit the game, so instead of it freezing you can just quit the game.

If this implementation uses too much memory, having it just instantaneously quit is also fine too.

rough sundial
#

this wouldn't work since the OutOfMemoryException is when the JVM shuts down the program since it cannot continue

#

you'd need to write a separate program that monitors MC and displays a screen when mc crashes, which isn't exactly what you'd be looking for

foggy knoll
#

if you're out of memory then yeah you kinda can't do anything else

#

you'd need to preempt it

raven star
#

let's see

#

maybe monitor and wait for a specified memory usage

#

then throw an exception

#

because the game is basically bound to crash if it gets higher than like 127MB flat

rough sundial
#

Well, hate to continue to bringing up the bad news, but Java likes to get very close to 100% memory utilization before dumping a portion of the heap, so it may be hard to tell if it will actually OOM

raven star
#

when the game is happy it stays at around 118 - 124MB

#

when you put a bit of a load on it, it averages from 120 - 125

raven star
raven star
#

it's just if it gets beyond a specified memory amount

#

just crash

raven star
#

range would likely work better here

#

so for instance a range of 5000 bytes would crash at 127995000 (assuming 128MB is allocated)

#

but probably 134212728 in reality (because of exponential stuff)

#

but I think you get the premise of range here

#

just
allocated memory - range = crash point (throws an exception and closes the game)

raven star
#

but with this mod the purpose would be to prematurely stop OOMs from freezing the game, memory leaks, and that kind of stuff

next surge
#
            if (this.running) {
               if (!this.crashed || this.crashReport == null) {
                  try {
                     this.runGame();
                  } catch (OutOfMemoryError var10) {
                     this.cleanHeap();
                     this.openScreen(new OutOfMemoryScreen());
                     System.gc();
                  }
                  continue;
               }

               this.printCrashReport(this.crashReport);
               return;
            }```
#

No idea if this was removed in some version since there's a request for it, but this is a snippet from vanilla 1.12.2

#
   public void cleanHeap() {
      try {
         MEMORY_RESERVED_FOR_CRASH = new byte[0];
         this.worldRenderer.clear();
      } catch (Throwable var3) {
      }

      try {
         System.gc();
         this.setWorld((ClientWorld)null);
      } catch (Throwable var2) {
      }

      System.gc();
   }

   static {
      MEMORY_RESERVED_FOR_CRASH = new byte[10485760];
   }```
raven star
#

usually it doesn't

#

but most of the time it just flat out freezes

raven star
#

so

#

what we could do here is likely allocate a configurable amount of memory as the crash range

#

and then show a screen (but probably just throw an exception)

raven star
raven star
#

but

#

with this I'm unsure as to why it triggers sometimes but a lot of times not

#

it exists

#

but I think the memory range is too small

#

if there were to be an option to only just quit the game that would be great

#

so I think this is how it'll go

#
  1. Make the allocated memory range a configurable size
#

and 2. Make the only button quit the game

raven star
#

when the game OOMs and the screen appears

#

if you can return to the menu the game kinda just

#

it becomes a brick

#

until you restart it

raven star
raven star
raven star
#

okay

#

I have made an advancement here

#

I have figured out why the game freezes when OOMing sometimes

#

it's when a stacktrace occurs while the OOM happens