handle common OOM situations due to huge images in gdiplus-device.cpp (fixes issue 2522)