Fatal I/O crash when writing object deriving from static libarary class

I am building a group of classes in a combination of static library (.lib file) and dynamic librarys (.dll) under visual studio 2012 using root version 5.34.36. Everything builds as normal and I am able to :
[li]load the dll in CINT[/li]
[li]Create an object of classes existing in in the static or dynamic library.[/li]
[li]Write any object of the static library to a ROOT file[/li]
[li]Write any object of the dynamic library NOT deriving from a class from the static library to a ROOT file[/li][/ol]
Attempting to write an object of the dynamic library deriving from a class from the static library ALWAYS fails with the same exception. For anyone interested in reproducing the crash I’ am attaching the full VS2012 solution plus scripts( see LibIssue.zip).

My base library (called Base.lib) contains just one class with the following layout

class VObject:public TObject { public: VObject(const string name_tag = "") { NameTag = name_tag; } virtual ~VObject() {} VObject(VObject& from) { NameTag = "Copy of "+from.NameTag; } inline virtual void SetTag(const std::string name) { NameTag = name; } inline virtual const string GetTag() const { return NameTag; } protected: string NameTag; private: ClassDef(VObject,1) };

My dynamic library comprises of a single class which derives from VObject as follows:

class VTimeObject:public virtual VObject { public: VTimeObject(const string name_tag = "", int dt = -1):VObject(name_tag) { DateTime = dt; } virtual ~VTimeObject() {} VTimeObject(VTimeObject& from) { NameTag = "Copy of "+from.NameTag; DateTime = from.DateTime; } inline virtual void SetDatatime(const int dt) { DateTime = dt; } inline virtual const int GetDatatime() const { return DateTime; } protected: int DateTime; private: ClassDef(VTimeObject,1) };

Everything work out OK and the dictionaries are built with no errors. I then attempt to write an object of each type to a root file using the following script:

	#include <TFile.h>
	TFile f("E:/ROOT_ISSUE/Object_Write.root","RECREATE");
	VObject o("An Object");
	//This is written successfully
	f.WriteObjectAny(&o,o.Class(),"Basic Object 1");
	//This ALWAYS causes a crash
	VTimeObject to("time object");
	f.WriteObjectAny(&to,to.Class(),"Time Object 1");

The base VObject object is written with no errors. Writing the VTimeObject however ALWAYS causes an Unhandled exception/memory violation:

After the exception I inspect the running root instance using the Visual Studio debugger and it seems that the crash is coming from TClass.cxx, at line 5437 (inside the TClass::StreamerTObject method see the stack trace bellow)

I would be very grateful for any help.
LibIssue.zip (30.1 KB)


I think it is a virtual inheritance issue (not sure how far this is supported in ROOT 5).
For example using this:class VTimeObject : public VObject instead ofclass VTimeObject : public virtual VObjectsolves the problem

And note you can use TFile::WriteObject() instead of TFile::WriteObjectAny()

root [0] gSystem->Load("bin/Time.dll"); root [1] TFile *f = TFile::Open("Object_Write.root", "RECREATE"); root [2] VTimeObject to("time object"); root [3] f->WriteObject(&to, "Time Object 1"); root [4] f->WriteObjectAny(&to,to.Class(),"Time Object 1"); root [5] f->ls() TFile** Object_Write.root TFile* Object_Write.root KEY: VTimeObject Time Object 1;2 object title KEY: VTimeObject Time Object 1;1 object title root [6]
I’ll ask our I/O expert for a confirmation about virtual inheritance.

Cheers, Bertrand.

P.S. See also [url=https://root-forum.cern.ch/t/i-o-with-tobject-as-virtual-base/17151/2 post[/url]

Cheers, Bertrand.