Ensures a dialog is instantiated before calling 'close'. Fixes #366