Protection added against gPad==0 in order to fix https://sft.its.cern.ch/jira/browse/ROOT-6777.