SF: log fatal if layer destroyed off main thread
We're seeing occasional nullptr errors when LayerFE accesses its
mSnapshot member during SurfaceFlinger::composite calls. One way this
may happen is if a Layer is destroyed during SurfaceFlinger::composite,
causing LayerFE to receive a null snapshot. Adding these logs should
help to identify the root cause and prevent LayerFE::mSnapshot nullptr
errors.
Bug: 261627672
Test: presubmits
Change-Id: I83b3fa304c65ae2dbe936f0f2bdc08045ed96d1f
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index b7abd95..1f159ae 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -216,6 +216,9 @@
}
Layer::~Layer() {
+ LOG_ALWAYS_FATAL_IF(std::this_thread::get_id() != mFlinger->mMainThreadId,
+ "Layer destructor called off the main thread.");
+
// The original layer and the clone layer share the same texture and buffer. Therefore, only
// one of the layers, in this case the original layer, needs to handle the deletion. The
// original layer and the clone should be removed at the same time so there shouldn't be any