Project

General

Profile

WCanvasPaintDevice::measureText breaks application

Added by Ulf Johnsson about 5 years ago

My application breaks when I set a default-font to a painter and attempt to measure text.

The following example illustrates the problem.

The example also works if I assign 'defaultFont' a size with WFont::setSize(12)

class PWid : public Wt::WPaintedWidget
    {
    public:
        PWid(Wt::WContainerWidget *pParent) : Wt::WPaintedWidget(pParent) {}

    protected:
        void paintEvent(Wt::WPaintDevice *paintDevice)
        {
            Wt::WPainter painter(paintDevice);
            Wt::WFont defaultFont,monospaceFont(Wt::WFont::Monospace);
            painter.setFont(defaultFont);
            painter.fillRect(0, 0, 200, 200, Wt::red);
            paintDevice->measureText(" 00:00:00.000 "); // this causes crash/exception? If I switch to 'monospaceFont' it works!
        }
    };

Replies (10)

RE: WCanvasPaintDevice::measureText breaks application - Added by lm at about 5 years ago

Please describe the nature of the "break". An unhandled exception? If so, what exception and what is the stack trace. Segmentation fault? What is the stack trace?

RE: WCanvasPaintDevice::measureText breaks application - Added by Ulf Johnsson about 5 years ago

An exception is thrown, I am however unclear if this is the cause:

Exception thrown at 0x00007FFC228C54D8 in wqwebd.exe: Microsoft C exception: Wt::WException at memory location 0x0000004FD83F52F0.

Exception thrown at 0x00007FFC228C54D8 in wqwebd.exe: Microsoft C exception: [rethrow] at memory location 0x0000000000000000.

Exception thrown at 0x00007FFC228C54D8 in wqwebd.exe: Microsoft C exception: Wt::WException at memory location 0x0000004FD83F5900.

When this problem occurs it takes my debugger with it, so I cannot see exactly what happends, but it looks alot like an unhandled exception (or a heap corruption).

I cannot extract a stack trace since my debugger seems to fail for some reason.

Running the provided example will reproduce the described problem.

BR, Ulf.

RE: WCanvasPaintDevice::measureText breaks application - Added by Roel Standaert about 5 years ago

Hello Ulf,

So you can't break on the WException being thrown to see which exception it is?

How is the WPaintedWidget being rendered? I assume you are referring to the default of being rendered out using a <canvas> element? Or is this when using server side rendering?

Regards,

Roel

RE: WCanvasPaintDevice::measureText breaks application - Added by Ulf Johnsson about 5 years ago

Hi!

No, I believe the exception has already been caught, otherwise my debbuger would have automatically stopped to give me the chance to check it out.

The ouput I posted is simply the output from the binary that I could see in the application output, I do not necessarily think the two are related.

Yes, that is correct, the example I posted is the entire program, appart from the code that creates the Application-object. The created PWid widget is simply added as a child to root().

BR, Ulf.

RE: WCanvasPaintDevice::measureText breaks application - Added by Ulf Johnsson about 5 years ago

Forgot to mention that I use WT3 not WT4, in case it makes a difference, sorry about that.

BR, Ulf

RE: WCanvasPaintDevice::measureText breaks application - Added by Roel Standaert about 5 years ago

Are you building Wt with or without Haru?

RE: WCanvasPaintDevice::measureText breaks application - Added by Roel Standaert about 5 years ago

Hm. I tried to reproduce it with our Wt 3.3.12 build (the Windows installer), and when using that it works fine for me, so that makes this a bit tricky to debug. Is it working correctly if you use our build?

RE: WCanvasPaintDevice::measureText breaks application - Added by Ulf Johnsson about 5 years ago

I am in the process of testing the latest Wt3, it seems to work differently there, I will post more after I have completed my tests.

In Wt3 version 3.3.10 (we are using a build based on a trunk version that should roughly correspond to that version) . there occurs an access violation in the example, looks like access to a nullptr, output:

Exception thrown at 0x00007FF61092ADCA in wqwebd.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

callstack:

application.exe!Wt::FontSupport::layoutText(class Wt::WFont const &,class std::vector<struct Wt::FontSupport::TextFragment,class std::allocator<struct Wt::FontSupport::TextFragment> > &,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,double &,double &,double,bool)
application.exe!Wt::FontSupport::measureText(class Wt::WFont const &,class Wt::WString const &,double,bool)
application.exe!Wt::WPdfImage::measureText(class Wt::WString const &,double,bool)
application.exe!Wt::ServerSideFontMetrics::measureText(class Wt::WFont const &,class Wt::WString const &,double,bool)
application.exe!Wt::WCanvasPaintDevice::measureText(class Wt::WString const &,double,bool)
application.exe!Application::PWid::paintEvent(Wt::WPaintDevice * paintDevice)

I will look into the latest version of Wt3 as soon as possible.

BR, Ulf.

RE: WCanvasPaintDevice::measureText breaks application - Added by Ulf Johnsson about 5 years ago

Hi again!

We built the latest trunk-version of WT3 with a new version of boost (v1.69), and the problem does not seem to be present anymore, so thats good.

Perhaps the recent changes you have made to WPdfImage or the changes to the session-id-managment has fixed this issue?

BR, Ulf.

    (1-10/10)