masks: make removal of gui forms more bullet proof (should fix #9762)

still needs to be found out if there is a deeper lying root cause