Protect nullptr dereference and fix counters (follow !3188) See merge request !3256
mentioned in commit 2ba021cf
mentioned in commit 2d79b5d8
mentioned in merge request !3294 (merged)
mentioned in commit ac356b91