Windows-Hacks icon indicating copy to clipboard operation
Windows-Hacks copied to clipboard

Catch "OutOfMemory" exceptions to prevent the program from crashing

Open RyanLaFauci opened this issue 7 years ago • 5 comments

I ran this program on a computer that only had 4 GB of RAM, and about half of the hacks crashed the program. Instead of crashing the program, you should catch these exceptions and alert the user that the specific hack they were trying to use is too intense for their PC.

RyanLaFauci avatar May 07 '17 17:05 RyanLaFauci

This is a good idea but this issue is strange because the PC that I built this on also has only 4 GB of RAM and I never experienced any crashing.

I added a try-catch to the second hack (Rotate Desktop) and I was just about to add try-catches to all the rest, but then it occurred to me that garbage collection should be cleaning up the memory and 4 GB should be more than enough.

Are you using some sort of ultra high resolution external monitor?

LazoCoder avatar May 21 '17 20:05 LazoCoder

Not at all, the 4 GB computer simply has two regularly sized monitors. The weird thing too is that I later tested it on my 8 GB laptop and it still threw these exceptions.

RyanLaFauci avatar May 23 '17 20:05 RyanLaFauci

Could you copy and paste the error message / stack trace on here so I can see which line of code is causing the issue? It would help a lot. Thanks.

LazoCoder avatar May 24 '17 20:05 LazoCoder

at System.Drawing.Bitmap.Clone(Rectangle rect, PixelFormat format)
   at ImageProcessing.Tools.Crop(Bitmap bmp, Rectangle rec)
   at WindowsHacks.HueShifter.Run() in C:\Users\RyanL\Downloads\Windows-Hacks-master\WindowsHacks\HueShifter.cs:line 36

Line 36 for me is the "bmp = Tools.Crop(bmp, new Rectangle(" line, may differ from what's on master.

RyanLaFauci avatar Jun 01 '17 20:06 RyanLaFauci

Awesome, thanks. I'll see what I can do about this.

LazoCoder avatar Jun 04 '17 17:06 LazoCoder