Fix crash when adding map object (fixes #312)