Should fix #10090, #10046, #10179. This is only a workaround, but the proper fix requires some bigger refactoring (also related to fixing #10058), and this at least prevents the crash.