Fix crash when taking a screenshot in the editor

Fixes #1992