Critical error detected c0000374


I have this code that iterates through a root file that contains a bunch of histograms. I’m fitting each one to a Gaussian and writing the results to a text file. Here is the essence of the code (Parameters is a function that estimates starting parameters and PeakFit is my fitting function–these are both defined in a straightforward way and not reproduced here):

void Parameters( TH1 *his, Double_t *par, Double_t xlow, Double_t xhigh );
Double_t PeakFit( Double_t *x, Double_t *par );

void MyFunction( TString filename ) {
	Double_t Params[6];		// six parameters
	TFile *inputFile = TFile::Open( filename );
	TIter next(inputFile->GetListOfKeys());
	TKey *key;
	Int_t fcounter = 0;
	TF1 *func;
	string fname;
	while ( ( key = (TKey*)next() ) ) {
		TClass *cl = gROOT->GetClass(key->GetClassName());
		if (!cl->InheritsFrom("TH1"))
		TH1 *h = (TH1*)key->ReadObj();
		ostringstream oss;
		oss << fcounter;
		fname = "peakfit_" + oss.str();
		Parameters( h, Params, 0, 1000 );
		func = new TF1( fname.c_str(), PeakFit, Params[4] - 200, Params[4] + 200, 6 );
		func->SetParameters( Params[0], Params[1], Params[2], Params[3], Params[4], Params[5] );
		h->Fit( fname.c_str(), "0R" );

Usually this crashes on the h->Fit() line the second time through. If I run without debugging, it sometimes makes it through the entire thing (fitting several hundred histograms). The error I get is given in the subject (critical error c0000374). A couple of years ago this same code worked reliably (back in root version 5).

Does anyone have a clue?


ROOT Version: v6.23.01
Platform: Windows 10
Compiler: Visual Studio 2019


When I go to root 6.24.00 I get the same problem. When I go to root 6.22.08, the problem goes away. How mysterious.


Hi Scott,

I think we need a way to reproduce this. Can you simplify the code as much as possible, removing as much code as possible while still making it crash? Is there a certain input file that causes the crash, or can you just run on the same input file multiple times, and you get the crash say at the 3rd iteration? We’ll need the input necessary to run the reproducing code.

Cheers, Axel.