Ubuntu 20 fail to update plot automatically when using animate()


ROOT Version: 6.22.0
Platform: windows
Compiler: Cling


Hello,

I am trying to combine tutorials example graphics/anim.C and hist/h2proj.C. I find something strange: the animate can update the plot automatically on Win10 but can’t on WSL. I need to click the image to update the plot.

Another strange thing is when I run graphics/anim.C on Win10 using root. The animation works well but when I put the mouse pointer on the plot, it will freeze! The animation will recover if I move the mouse pointer away. I don’t know if the animation stops or actually the program stops.

The code is simple:

#include "TStyle.h"
#include "TCanvas.h"
#include "TH2.h"
#include "TTimer.h"
#include "TMath.h"
using namespace std;
//using namespace TMath;

TH2F *h2;
TH1D * projh2X;
TH1D * projh2Y;
TPad *right_pad, *top_pad;
Double_t pi;
Float_t tt = 0;

void frog(){

  gStyle->SetCanvasPreferGL(true);
  TCanvas *c1 = new TCanvas("c1", "c1",900,900);
  gStyle->SetOptStat(0);

  TPad *center_pad = new TPad("center_pad", "center_pad",0.0,0.0,0.6,0.6);
  center_pad->Draw();

  right_pad = new TPad("right_pad", "right_pad",0.55,0.0,1.0,0.6);
  right_pad->Draw();

  top_pad = new TPad("top_pad", "top_pad",0.0,0.55,0.6,1.0);
  top_pad->Draw();

  h2 = new TH2F("h2","",40,-4,4,40,-20,20);

  Float_t px, py;
  for (Int_t i = 0; i < 25000; i++) {
   gRandom->Rannor(px,py);
   h2->Fill(px,5*py);
  }
  projh2X = h2->ProjectionX();
  projh2Y = h2->ProjectionY();

  center_pad->cd();
  gStyle->SetPalette(1);
  h2->Draw("COL");

  top_pad->cd();
  projh2X->SetFillColor(kBlue+1);
  projh2X->Draw("bar");

  right_pad->cd();
  projh2Y->SetFillColor(kBlue-2);
  projh2Y->Draw("hbar");

  c1->cd();
  TLatex *t = new TLatex();
  t->SetTextFont(42);
  t->SetTextSize(0.02);
  t->DrawLatex(0.6,0.88,"This example demonstrates how to display");
  t->DrawLatex(0.6,0.85,"a histogram and its two projections.");
/////////////////////////////////
  TTimer *timer = new TTimer(200);
  timer->SetCommand("Animate()");
  timer->TurnOn();
}

void ZoomExec()
{
   int xfirst = h2->GetXaxis()->GetFirst();
   int xlast = h2->GetXaxis()->GetLast();
   double xmin = h2->GetXaxis()->GetBinLowEdge(xfirst);
   double xmax = h2->GetXaxis()->GetBinUpEdge(xlast);
   projh2X->GetXaxis()->SetRangeUser(xmin, xmax);
   top_pad->Modified();

   int yfirst = h2->GetYaxis()->GetFirst();
   int ylast = h2->GetYaxis()->GetLast();
   double ymin = h2->GetYaxis()->GetBinLowEdge(yfirst);
   double ymax = h2->GetYaxis()->GetBinUpEdge(ylast);
   projh2Y->GetXaxis()->SetRangeUser(ymin, ymax);
   right_pad->Modified();
}

void Animate()
{
   //just in case the canvas has been deleted
   if (!gROOT->GetListOfCanvases()->FindObject("c1")) return;
   /////////////////////
//   stage.move_onestep();
//   spec.readSpec();
   ////////////////////////
   tt +=10;
   Float_t px, py;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      h2->Fill(px,5*py*tt);
   }
   projh2X = h2->ProjectionX();
   projh2Y = h2->ProjectionY();
   gPad->cd(0);
   gPad->Modified();
   gPad->Update();
   gPad->cd(1);
   gPad->Modified();
   gPad->Update();
   gPad->cd(2);
   gPad->Modified();
   gPad->Update();
}

I find the animate consumes a lot of CPU and memory when the picture is big. I don’t know if there is a better solution to do the same thing.

Thank you very much for any suggestion!

Hello @Zhenhao,

I guess @couet should know about this, but he is on vacation this week. I guess we should wait a bit.

Great! It’s not emergency. @StephanH

I tried your macro on Mac. I see the animation.
Usually it is Mac having issues with Update().
What is WSL ? Ubuntu ?
May be try:

gSystem->ProcessEvents();

Thank you very much! I find this situation only happens once for me and I posted it.:frowning: Now I don’t have this problem.