TCanvasWidget crashes

I’m using ROOT version 6.26/10 on Suse- Linux tumbleweed.

Hi, all, I have been using the the Web-based TCanvasWidget embedded in my qt-based program.to draw markers, Lines Graphs etc for quite some time. I now want to draw objects on the screen which change repeatedly their position when I call the proper subroutine with a pushbutton. If I do this several times in sequence, the program crashes.This happens independently if I call gPad =KWidget->getCanvas(); (KWidget is my TCanvasWidget) only once in the calling routine or allways the inside the called subroutine. Unfortunartely I do not get useful information with the debugger. The crash seems to happen, when gPad->Update(); gPad->Modified(); is called.Someone experienced this and knows how to overcome the problem? Thank you very much in advance Best regards Karl

It is not easy to help without a reproducer. I found it weird you assign gPad yourself. gPad points to the current and usually is not set by the user program.

As your problem seems connected with GUI, I guess @bellenot might have some hints to propose to you.

Let’s ask @linev , the author of the TCanvasWidget class

1 Like

Hi,

As Olivier said, we need reproducer to understand the problem.

But main remark is - one have to be sure that any changes in canvas performed from the main thread where QApplication runs. Typically one do it with QTimer.

Regards,
Sergey

Thank you all for replying. @Linev:

Hi Sergey, I started from your ExampleWidget program. In the ExampleWidget constructor we have

gPad = fxTCanvasWidget->getCanvas();
Histo->Draw();

I do something similar, but since I want to draw things several times with with different parameters
I packed

{
.
.
 gPad = KWidget->getCanvas();
..
Draw something ....
..
something.Draw();
 ..
gPad->Modified()
gPad->Update()

}

in a Subroutine ExampleWidget::Doit() which is executed with different parameters each time I press my button.
The drawing looks fine the first few times (about 5) but the the program crashes.
I also tried to call the gPad = KWidget->getCanvas(); outside the subroutine only once and then used gPad->Clear() inside the subroutine before doing the next drawing because I thought that perhaps a repeated call of gPad = KWidget->getCanvas(); could cause the problem. However the result was the same: the program crashed after a few calls

So, very simply stated: What I want to do is:
Setup the canvas
Draw something
Change Datetime
with button: Redraw with drawing changed according to new datetime.
do this as often as I like

best regards Karl

Hi,

Strange, I just modify qt5web example with the method:

void ExampleWidget::DrawGeometryInCanvas()
{
   auto canv = fxTCanvasWidget->getCanvas();
   canv->Clear();

   int nth2points = 40;

   auto histo2 = new TH2I("test2", "Testing TH2 drawing in TCanvas", nth2points, -5, 5, nth2points, -5, 5);
   histo2->SetDirectory(nullptr);
   for (int n=0;n<nth2points;++n) {
      for (int k=0;k<nth2points;++k) {
         double x = 10.*n/nth2points-5.;
         double y = 10.*k/nth2points-5.;
         histo2->SetBinContent(histo2->GetBin(n+1, k+1), (int) (1000*TMath::Gaus(x)*TMath::Gaus(y)));
      }
   }
   canv->GetListOfPrimitives()->Add(histo2,"colz");

   canv->Modified();
   canv->Update();
}

And I can press button any number of times.

Regards,
Sergey

Hi Sergey, I investigated more the problem i am facing. As it seems now, it does not have to do with multiple calls to ui->KWidget->getCanvas(). My program was quite big so I broke it down to the essential parts and coded from scratch.

#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <iostream>
#include "TMarker.h"
#include "TCanvas.h"
#include "TEllipse.h"
#include "TMath.h"
#include <cmath>

#include "TCanvasWidget.h"


using namespace std;

double getProjectionRadius(double Dec)
{

    double Radius = 2*cos(Dec)/(1+sin(Dec));
    return Radius;

}


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose);
    ui->dateTimeEdit->setDisplayFormat("dd.MM.yyyy hh:mm:ss");
    ui->dateTimeEdit->setDateTime(QDateTime::currentDateTimeUtc()); //Visualizza UTC
    ui->dateTimeEdit->setCalendarPopup(true);


    DoDisplay();


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::DoDisplay()
{
   auto canv= ui->KWidget->getCanvas();
   canv->Range(-5,-5,5,5);
   canv->Clear();

   /*
       for(int i=0;i<14;i++)
       {

           double ang =(90.-10*i)*TMath::DegToRad();
           double radius = getProjectionRadius(ang);

           cout << 90-10*i << " " << radius << " Ang Rad "<< endl;

           TEllipse e = TEllipse(0.,0.,radius,radius);
           e.SetFillStyle(0); // <-- Stroke only
           if(i==9)
               e.SetLineColor(4);
           else
               e.SetLineColor(2);
           e.SetLineWidth(1);
           e.Draw("L");

       }
   */
           for (int k=0;k<360;k++){


                double Dec =0.0;

                double azimut = k*TMath::DegToRad();

                double radius = 2.0;
                TMarker *ma = new TMarker();

                double circx=radius*TMath::Cos(azimut);
                ma->SetX(circx);
                double circy=radius*TMath::Sin(azimut);
                ma->SetY(circy);



                ma->SetMarkerStyle(20);
                ma->SetMarkerSize(1);
                ma->SetMarkerColor(2);
                ma->Draw();
            }

    canv->Update();
    canv->Modified();

}

This part of the program is for projecting points on the surface of a sphere to a plane. The program as I am posting it, works fine. It displays 360 points on the circumference of a circle. If however I uncomment the commented part which should draw a bunch of concentric circles, it crashes. when canv->Update(); is called. It seens that the crash is caused by a Resize event issued at the end of the subroutine:

Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x0000000000000000 in  ()
#6  0x00007f7415c3127f in TPad::ResizePad(char const*) () at /home/karl/rootbin/lib/libGpad.so
#7  0x00007f7415c053cd in TCanvas::SetCanvasSize(unsigned int, unsigned int) () at /home/karl/rootbin/lib/libGpad.so
#8  0x0000000000408c1f in TCanvasWidget::resizeEvent(QResizeEvent*) (this=0x4a07110, event=0x7fffc16ec560) at /home/karl/startest/TCanvasWidget.cpp:114

I could send you the .ui file and the other files of the project as well as well, but i do not know how to attach them.
At the start of the program I also get this message, but I don’t know what I should do about it:

Please register the custom scheme ‘rootscheme’ via QWebEngineUrlScheme::registerScheme() before installing the custom scheme handler.

best regards Karl

As it seems, I am not even capable of posting the program code correctly, because the #include instructions with the “triangular brackets” (I dont’t know how to call them correctly) have the second part missing in my post

I apologise for that

karl

Hi,

Please try to use new TEllipse in your code like:

TEllipse *e = new TEllipse(0.,0.,radius,radius);
e->SetFillStyle(0); // <-- Stroke only
if(i==9)
  e->SetLineColor(4);
else
  e->SetLineColor(2);
e->SetLineWidth(1);
e->Draw("L");

Hi Sergey,
thank you very much indeed ! Your suggestion solves the problem. I’m sorry I overlooked the obvious. I should sleep more :wink:

Best regards Karl