diff options
author | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-31 22:25:04 +0000 |
---|---|---|
committer | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-31 22:25:04 +0000 |
commit | f65dc7566712c0f7c85575109a89541b46c10d81 (patch) | |
tree | 31d40632ea8edf55c274a60ccc9e518541089ac5 | |
parent | b6f16c5aa38ad57fe6e92cdef3d5d4db70df72e6 (diff) | |
download | chromium_src-f65dc7566712c0f7c85575109a89541b46c10d81.zip chromium_src-f65dc7566712c0f7c85575109a89541b46c10d81.tar.gz chromium_src-f65dc7566712c0f7c85575109a89541b46c10d81.tar.bz2 |
Debug checks to make it easier to find reason for CanvasT<>::initialize crash
BUG=101934
TEST=none
Review URL: http://codereview.chromium.org/8341090
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108023 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | skia/ext/bitmap_platform_device_win.cc | 34 | ||||
-rw-r--r-- | skia/ext/canvas_paint_win.h | 5 |
2 files changed, 35 insertions, 4 deletions
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc index 3a2a5b4..03ebca6 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -7,12 +7,45 @@ #include "skia/ext/bitmap_platform_device_win.h" +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "base/process_util.h" #include "skia/ext/bitmap_platform_device_data.h" #include "third_party/skia/include/core/SkMatrix.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkUtils.h" +namespace { +// Crashes the process. This is called when a bitmap allocation fails, and this +// function tries to determine why it might have failed, and crash on different +// lines. This allows us to see in crash dumps the most likely reason for the +// failure. It takes the size of the bitmap we were trying to allocate as its +// arguments so we can check that as well. +void CrashForBitmapAllocationFailure(int w, int h) { + // The maximum number of GDI objects per process is 10K. If we're very close + // to that, it's probably the problem. + const int kLotsOfGDIObjs = 9990; + CHECK(GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS) < kLotsOfGDIObjs); + + // If the bitmap is ginormous, then we probably can't allocate it. + // We use 64M pixels. + const int64 kGinormousBitmapPxl = 64000000; + CHECK(static_cast<int64>(w) * static_cast<int64>(h) < kGinormousBitmapPxl); + + // If we're using a crazy amount of virtual address space, then maybe there + // isn't enough for our bitmap. + const int64 kLotsOfMem = 1500000000; // 1.5GB. + scoped_ptr<base::ProcessMetrics> process_metrics( + base::ProcessMetrics::CreateProcessMetrics(GetCurrentProcess())); + CHECK(process_metrics->GetPagefileUsage() < kLotsOfMem); + + // Everything else. + CHECK(false); +} + +} + namespace skia { BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( @@ -122,6 +155,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::create( &data, shared_section, 0); if (!hbitmap) { + CrashForBitmapAllocationFailure(width, height); return NULL; } diff --git a/skia/ext/canvas_paint_win.h b/skia/ext/canvas_paint_win.h index 9610025..f03ef55 100644 --- a/skia/ext/canvas_paint_win.h +++ b/skia/ext/canvas_paint_win.h @@ -109,10 +109,7 @@ class CanvasPaintT : public T { // inset pixels to the screen. const int width = ps_.rcPaint.right - ps_.rcPaint.left; const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; - if (!canvas->initialize(width, height, opaque, NULL)) { - // Cause a deliberate crash; - *(char*) 0 = 0; - } + CHECK(canvas->initialize(width, height, opaque, NULL)); // This will bring the canvas into the screen coordinate system for the // dirty rect |