THStack crashes when modyfing axis and wrong painting of pads

Using THStack I noticed two problems:

  1. When making any action on the stack’s axis before drawing it, root crashesh. See the example below in line 22 with comment // crash here (uncomment the line).
  2. When modyfing the pad margins after the stack was drawn, it draws a frame around the histogram equivalent to the margins before change (pad 2, lines 26-27 in mwe below).

Non of this I found documented.

Here is the MWE:

#include <TCanvas.h>
#include <THStack.h>
#include <TText.h>

void mwe() {
   THStack *hs = new THStack("hs","");
   TH1F *h1 = new TH1F("h1","test hstack",10,-4,4);
   h1->FillRandom("gaus",20000);
   h1->SetFillColor(kRed);
   hs->Add(h1);
   TH1F *h2 = new TH1F("h2","test hstack",10,-4,4);
   h2->FillRandom("gaus",15000);
   h2->SetFillColor(kBlue);
   hs->Add(h2);
   TH1F *h3 = new TH1F("h3","test hstack",10,-4,4);
   h3->FillRandom("gaus",10000);
   h3->SetFillColor(kGreen);
   hs->Add(h3);
   TCanvas *cs = new TCanvas("cs","cs",10,10,700,450);
   TText T; T.SetTextFont(42); T.SetTextAlign(21);
   cs->Divide(2,1);
//    hs->GetXaxis()->SetLabelSize(0.05);  // crash here
   cs->cd(1); hs->Draw(); T.DrawTextNDC(.5,.95,"Default drawing option");
   cs->cd(2); hs->Draw("nostack"); T.DrawTextNDC(.5,.95,"Option \"nostack\"");
   hs->GetXaxis()->SetLabelSize(0.05);
   gPad->SetLeftMargin(0.2); // box around the histogram here
   gPad->SetBottomMargin(0.2); // box around the histogram here

   cs->Print("mwe.png");
}

ROOT Version: 6.22.02
Platform: Linux
Compiler: g++ 10.2.0


THStack axis exist only when the stack has been drawn.
Use GetXaxis() after Draw() not before.