V5.15.08 problem with SetRGB()

Hi Rooters,

I’ve moved to v5.15.08 and get a segmentation fault when I run the attached macro.

The attached macro is a section of a larger macro which sets the colours I want to use in a contour plot and works fine in v5.11.02.
The problem appears to be the col->SetRGB(double, double, double) command.

I can call it interactively:

TColor* col;
col = gROOT->GetColor(100);
col->SetRGB(0,0,0);

But it dies in the macro :(.

Does anyone have any ideas why the seg fault occurs and how I might correct the macro so it retains the same funtionality?

Thanks in advance,

Paul.
mycolor.C (354 Bytes)

Hi Paul,

It looks like ROOT colors are not initialized. Will your macro work if you call TColor::InitializeColors() in the beginning?

Cheers, Ilka

Hi,

Now I get:

Error: illegal pointer to class object col 0x0 295 mycolor.C:8:

If I just include:

col->InitializeColors();

Or the seg fault if I just include:

TColor::InitializeColors();

Any ideas?

Paul.
mycolor.C (414 Bytes)

Hi Paul,

No idea right now - I will investigate on Monday if nobody answers your question.

Cheers, Ilka

BTW, what happens if you create a canvas on the first line in your macro?

Running this macro which creates a canvas object before i set my colors has exactly the same pointer error.

void mycolor(char* name=“h_example”){
//Set up the colours I wish to use:
const Int_t ncol = 9;
Int_t colors[ncol];
TCanvas* tcan = new TCanvas(“myCanvas”,“myCanvas”,550,550);
TColor col;
Double_t dg=1.0/(1.0
(Double_t)ncol);
// TColor::InitializeColors();
col->InitializeColors();
Double_t grey=0.;
for (Int_t i=0; i<ncol; i++) {
colors[i]= i+100;
col = gROOT->GetColor(colors[i]);
col->SetRGB(grey, grey, grey);
grey += dg;
}
}

The macro works in v5.14/00e if I remove the InitializeColors() line.

void mycolor(char* name=“h_example”){
//Set up the colours I wish to use:
const Int_t ncol = 3;
Int_t colors[ncol];
TCanvas* tcan = new TCanvas(“myCanvas”,“myCanvas”,550,550);
TColor col;
Double_t dg=1.0/(1.0
(Double_t)ncol);
// TColor::InitializeColors();
// col->InitializeColors();
Double_t grey=0.;
for (Int_t i=0; i<ncol; i++) {
colors[i]= i+100;
col = gROOT->GetColor(colors[i]);
col->SetRGB(grey, grey, grey);
grey += dg;
}
}

Color management has changed. Now the colors above 100 are not created as before. Therefore gROOT->GetColor() returns 0 because the color does not exist. The following macro takes this into account:

{
   TF2 *f2 = new TF2("f2","0.1+1000*((1-(x-2)*(x-2))*(1-(y-2)*(y-2)))",1,3,1,3);   
   Int_t ncol = 50;
   Int_t colors[ncol];
   TColor *col;
   Double_t dg=1/(Double_t)ncol;
   Double_t grey=0;
   for (Int_t i=0; i<ncol; i++) {
      colors[i]= i+101;
      if (gROOT->GetColor(colors[i])) {
         gROOT->GetColor(colors[i])->SetRGB(grey, grey, grey);
      } else {
         TColor *c = new TColor(colors[i], grey, grey, grey);
      }
      grey = grey+dg;
   }
   f2->SetContour(ncol);
   gStyle->SetPalette(ncol,colors);
   f2->Draw("cont4 z");
}

Thanks, that has fixed it.