From 603f6de35f21d74ae242d52d501f4f5c25ff4f4c Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Fri, 14 Sep 2012 15:31:25 -0700 Subject: Fix occasional crash bug with layers Launcher occasionally crashes with a stack trace indicating that the memory of a Layer object is corrupt. It is possible for us to delete a Layer structure and then, briefly, use it to draw a DisplayList again before that DisplayList gets recreated (without the layer that got deleted). When this happens, if the memory got corrupted, it's possible to crash. The fix is to add Layer to the other objects which we currently refcount (bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the refcount. We increment when creating it, then increment it again when it's referenced from a DisplayList. Then we decrement the refcount instead of deleting it, and decrement when we clear a DisplayList that refers to it. Then when the refcount reaches 0, we delete it. Issue #6994632 Native crash in launcher when trying to launch all apps screen Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c --- libs/hwui/Layer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libs/hwui/Layer.cpp') diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp index 31e169beea64..76b274b00443 100644 --- a/libs/hwui/Layer.cpp +++ b/libs/hwui/Layer.cpp @@ -25,10 +25,29 @@ namespace android { namespace uirenderer { +Layer::Layer(const uint32_t layerWidth, const uint32_t layerHeight) { + mesh = NULL; + meshIndices = NULL; + meshElementCount = 0; + cacheable = true; + textureLayer = false; + renderTarget = GL_TEXTURE_2D; + texture.width = layerWidth; + texture.height = layerHeight; + colorFilter = NULL; + deferredUpdateScheduled = false; + renderer = NULL; + displayList = NULL; + fbo = 0; + Caches::getInstance().resourceCache.incrementRefcount(this); +} + Layer::~Layer() { if (mesh) delete mesh; if (meshIndices) delete meshIndices; if (colorFilter) Caches::getInstance().resourceCache.decrementRefcount(colorFilter); + if (fbo) Caches::getInstance().fboCache.put(fbo); + deleteTexture(); } void Layer::setPaint(SkPaint* paint) { -- cgit v1.2.3-59-g8ed1b