diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index adf4aee8b931f..79b938841bc29 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -153,10 +153,11 @@ JVMAttachHook RenderThread::getOnStartHook() { } RenderThread& RenderThread::getInstance() { - // This is a pointer because otherwise __cxa_finalize - // will try to delete it like a Good Citizen but that causes us to crash - // because we don't want to delete the RenderThread normally. - static RenderThread* sInstance = new RenderThread(); + [[clang::no_destroy]] static sp sInstance = []() { + sp thread = sp::make(); + thread->start("RenderThread"); + return thread; + }(); gHasRenderThreadInstance = true; return *sInstance; } @@ -171,7 +172,6 @@ RenderThread::RenderThread() , mFunctorManager(WebViewFunctorManager::instance()) , mGlobalProfileData(mJankDataMutex) { Properties::load(); - start("RenderThread"); } RenderThread::~RenderThread() { diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h index a7d1ba8dafd77..9e5bce76e228f 100644 --- a/libs/hwui/renderthread/RenderThread.h +++ b/libs/hwui/renderthread/RenderThread.h @@ -171,6 +171,7 @@ private: friend class android::uirenderer::WebViewFunctor; friend class android::uirenderer::skiapipeline::VkFunctorDrawHandler; friend class android::uirenderer::VectorDrawable::Tree; + friend class sp; RenderThread(); virtual ~RenderThread();