BinaryConstruct/Terraria-Map-Editor — Issue #178: Out of Memory & Random Freezing + Fix
Author: Pala22
Created: 2011-12-20 07:17:09+00:00
State: open

As someone who has only used TEdit for a few days I have to say I'm impressed by the ease of use and I know from experience that making a user friendly UI is tricky to say the least.

But that isn't why I'm here, my problem was that I was getting the odd crash with the out of memory error log but mostly I was getting random freezes and getting "this program is not responding" messages from OS. So I decided to look into it and found that for sum ppl it seemed disabling undo fixed it, but that didn't work for me.

So I decided to try my old friend LAA(Large-Address-Aware for those who don't know) now on a 32Bit OS this will probably not do anything but on a 64Bit OS (which is what about 90+% of Vista & Win7 OS's are) it allows a 32bit program to utilize the main part of the 64Bit architecture which is allowing more than 4,294,967,295 Bits (4Gb) of system memory the 32bit Architecture is limited to by complicated math. But even then almost all 32Bit OS's limited that down even further to 3.12GB for stability, which means that 32Bit programs were limited to being able to use only 2Gb of system memory. But that is Deceptive as I Stressed TEdit and it never went over 1.7Gb with LAA enabled so why does enabling LAA work?, it's because although it doesn't use over the 2Gb limit of 32bit it also means that it cannot do large read & writes to the memory a.k.a. large addresses without the LAA flag enabled. With LAA enabled using CFF Explorer http://www.ntcore.com/exsuite.php I haven’t had any more problems and with testing I can for example run the max eraser of 200 across the map and the program will slow down or even appear to have frozen but it will never crash or actually freeze and it then will recover when u stop doing the insane edit. Even when you undo that same edit there is a similar slow/freeze but still not a crash or proper freeze.

Now the fix is either everybody who has the problem can do the fix using CFF Explorer after downloading TEdit or u can add it to the program source code by doing a Post-build Event now I tested this myself a bit but not extensively, but LAA should not affect ppl using a 32bit OS it doesn’t really change anything as it only allows a program too use large addresses not forces it too. Steps for both options are as follows.

CFF Explorer:
1.	http://www.ntcore.com/exsuite.php Download “CFF Explorer (x86 Version, Stand-Alone, Zip Archive)” 3rd link under the opening info
2.	Extract and run CFF Explorer.exe
3.	File – Open and navigate to TEdit location and select TEdit.exe
Now it can be a little confusing to those who don’t understand but it’s pritty simple.
4.	On the left there should be a list now, under Nt Headers select File Header and it should bring up a list on the right
5.	At the bottom of the list “Characteristics” click on “Click Here”
6.	Now there should be a small window open, tick in the little box next to “App can handle > 2Gb address space” a.k.a. LAA, it should look like this http://img155.imageshack.us/img155/7749/cffscreen.jpg.
DO NOT!! Touch any other options they can do sum bad things
7.	Hit Ok then Save and Yes to "Overwrite Original File". Normally I would have said backup exe before doing all this but as TEdit is a small and simple download there isn’t much point

Add LAA Flag to exe in Post-Build Events of C# Project:
1.	Open Project file
2.	On the right in Solution Explorer right click on TEdit and open Properties
3.	On the left click on Build Events
4.	Now click on “Edit Post-build ...” add the following 2 lines then hit ok
call "$(DevEnvDir)..\tools\vsvars32.bat"
editbin /LARGEADDRESSAWARE "$(TargetPath)"
5.	Now save the project and recompile

Now these instructions are probably over simplified but that’s because I’m used to having to simplify things down to base levels for customers of my computer business who haven’t got a single clue about the things they are trying to do, and I just realised how long this is so I’ll stop typing now XD