TGText crashes upon destruction


I’m using Root 5.26 under Visual C++ Express 2008 and everything works fine except for example the following lines of code:

TGText *t = new TGText();
delete t;

The program crashes with an exception like “Invalid Address specified to RtlFreeHeap…”

A similar thing happens when to following procedure is followed:

TGTextEdit *te = new TGTextEdit(...);
TGText *te1 = new TGText();
te->SetText(te1); // ok
TGText *te2 = new TGText();
te->SetText(te); // program crashes with exception - due to deletion of te1?

There must be something wrong with the destruction of a TGText objecet, but I cannot figure out what. Has anybody an idea?

Thanks, Jürgen

Hi Jürgen,

Sorry, but I cannot reproduce the problem (I tried with svn trunk and v5.26.00).
How do you compile your code? Could you post a short piece of code reproducing the problem (with the makefile or the Visual Studio project/solution)?

Cheers, Bertrand.

Hi Bertrand,

I enclosed a sample VC project (remove *.txt extension) and the .cpp file with the source containing main(). The source is as follows:

#include <TGText.h>
#include <TGFrame.h>
#include <TApplication.h>

void main() {

	TApplication *ta = new TApplication("TEST", 0, 0);
	TGMainFrame *mf = new TGMainFrame(0);
	delete mf;

	TGText *t=new TGText();
	delete t;

mf can be created and deleted, t however crashes the program upon deletion.

Thank you for your support!

Cheers, Jürgen
TGTextTest.cpp (240 Bytes)
TGTextTest.vcproj.txt (4.29 KB)

Hi Jürgen,

This is due to a mix between debug & release versions of the runtime libraries. In debug mode, you have to use the debug version of ROOT, and in release mode, the release version of ROOT.

And the crash is actually in TString destructor. To illustrate the problem, this short piece of code is enough:

[code]#include <TString.h>
// To compile in release mode:
// cl -MD -EHsc delstring.cxx -I%ROOTSYS%\include -FIw32pragma.h -link -LIBPATH:%ROOTSYS%\lib libCore.lib

// To compile in debug mode:
// cl -MDd -EHsc delstring.cxx -I%ROOTSYS%\include -FIw32pragma.h -link -debug -LIBPATH:%ROOTSYS%\lib libCore.lib

void main()
TString *str = new TString();
delete str;
}[/code]Compiling it in debug mode with the release version of ROOT make it crash (and vice versa).

Cheers, Bertrand.