How to read TCanvas from TTree?

Hello!

I have signal x vs y.
I want to save in a tree TCanvas with several TGraphs and several double values from fit.
Then I want to read the tree, set diffetent cuts for fit values and watch canvases corresponding to this selection.

I wrote test code in VS2015 (14.0.25123.00 update 2), root version is 5.34.34, windows 7:

#include <iostream>
#include <sstream>
#include <vector>
#include <iomanip>
#include <fstream>

#include "TF1.h"
#include "TGraph.h"
#include "TFile.h"
#include "TRandom.h"
#include "TMath.h"
#include "TObjArray.h"
#include "TGraphErrors.h"
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TChain.h"
#include "TROOT.h"

void test_save()
{
	TFile f_tree("D:\\Data_work\\test_folder\\test_save.root", "RECREATE");
	TTree tree("t1", "Parser tree save");

	TCanvas canv("c", "c", 0, 0, 1900, 1000);
	tree.Branch("canvas_tr", "TCanvas", &canv);

	tree.Fill();
	tree.Write();

	f_tree.Close();
}


void test_read()
{
	TObjArray Hlist_gr(0);
	Hlist_gr.SetOwner(kTRUE);

	TCanvas* canv_read = 0;

	TChain chain("t1");
	chain.Add("D:\\Data_work\\test_folder\\test_save.root");
	chain.SetBranchAddress("canvas_tr", &canv_read);

	chain.GetEntry(0);
	Hlist_gr.Add(canv_read->Clone());

	TFile ofile_Hlist_gr("D:\\Data_work\\test_folder\\test_result.root", "RECREATE");
	Hlist_gr.Write();
	ofile_Hlist_gr.Close();
}



int main(int argc, char *argv[])
{
	test_save();
	test_read();

	system("pause");
	return 0;
}

This code generates two files.
test_save() generates test_save.root. This is file with “t1” tree.
“t1” tree contains “canvas_tr” canvas.

test_read() generates test_result.root. This is file with “c” canvas.

I can open this canvas and all is ok:

Now I want to open test_save.root without new generation.
I commented this line:" test_save();" (line 58).
So my new code is:

#include <iostream>
#include <sstream>
#include <vector>
#include <iomanip>
#include <fstream>

#include "TF1.h"
#include "TGraph.h"
#include "TFile.h"
#include "TRandom.h"
#include "TMath.h"
#include "TObjArray.h"
#include "TGraphErrors.h"
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TChain.h"
#include "TROOT.h"

void test_save()
{
	TFile f_tree("D:\\Data_work\\test_folder\\test_save.root", "RECREATE");
	TTree tree("t1", "Parser tree save");

	TCanvas canv("c", "c", 0, 0, 1900, 1000);
	tree.Branch("canvas_tr", "TCanvas", &canv);

	tree.Fill();
	tree.Write();

	f_tree.Close();
}


void test_read()
{
	TObjArray Hlist_gr(0);
	Hlist_gr.SetOwner(kTRUE);

	TCanvas* canv_read = 0;

	TChain chain("t1");
	chain.Add("D:\\Data_work\\test_folder\\test_save.root");
	chain.SetBranchAddress("canvas_tr", &canv_read);

	chain.GetEntry(0);
	Hlist_gr.Add(canv_read->Clone());

	TFile ofile_Hlist_gr("D:\\Data_work\\test_folder\\test_result.root", "RECREATE");
	Hlist_gr.Write();
	ofile_Hlist_gr.Close();
}



int main(int argc, char *argv[])
{
	//test_save();
	test_read();

	system("pause");
	return 0;
}

I deleted test_result.root and run new code.

I see strange warnings.
When I open test_result.root I see “TObject” instead of “c” canvas.
And I can’t open this “TObject”.

What is wrong in my code?
Could you help me?

P.S. how to insert pictures in a post correctly?

Thank you in advance.
Best regards, Vladislav.

I understood my error!

I have installed binary root builded in debug mode, but I used it in release mode(because my final program is CPU hard). When I changed build mode to debug this error disappeared.

Sorry for troubling.