Prevent CGContextDrawImage: invalid context 0x0 error