Merge "Fix crash when a layer is destroyed immediately after creation" into main