winscope: handle missing child layers gracefully
log a warning instead of failing to open the trace
Test: open traces in b/169708770
Change-Id: Iff327b2a6f41c231a379a698345e39b1d89e74e1
diff --git a/tools/winscope/src/sf_visibility.js b/tools/winscope/src/sf_visibility.js
index 11ff0cd..c980225 100644
--- a/tools/winscope/src/sf_visibility.js
+++ b/tools/winscope/src/sf_visibility.js
@@ -278,7 +278,7 @@
if (!layerMap.hasOwnProperty(id)) {
// TODO (b/162500053): so that this doesn't need to be checked here
console.warn(
- `Children layer with id ${id} not found in dumped layers... ` +
+ `Child layer with id ${id} not found in dumped layers... ` +
`Skipping layer in traversal...`);
} else {
children.push(layerMap[id]);
@@ -327,7 +327,16 @@
const parentId = rootLayers[i].parent;
const parent = parentId == -1 ? null : layerMap[parentId];
fn(rootLayers[i], parent);
- const children = rootLayers[i].children.map((id) => layerMap[id]);
+ const children = rootLayers[i].children.map(
+ (id) => {
+ const child = layerMap[id];
+ if (child == null) {
+ console.warn(
+ `Child layer with id ${id} in parent layer id ${rootLayers[i].id} not found... ` +
+ `Skipping layer in traversal...`);
+ }
+ return child;
+ }).filter(item => item !== undefined);
traverse(layerMap, children, fn);
}
}