Bitmap creation failed in wxFreeChart

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
TSib
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jun 16, 2016 8:22 am

Bitmap creation failed in wxFreeChart

Post by TSib »

Hi,
I use wxFreeChart to display graph. Recently, I've got a warning with the following message :
"warning: ../../src/msw/bitmap.cpp(741): assert ""w > 0 && h > 0"" failed in DoCreate(): invalid bitmap size". I found that this warning comes from the following function :
"void AxisPlot::DrawDataAreaBackground(wxDC &dc, wxRect rc)" at this line :
" m_plotBackgroundBitmap.Create(m_drawRect.GetWidth(), m_drawRect.GetHeight());".
How can figure out this warning ?Thanks you in advance

S.T.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bitmap creation failed in wxFreeChart

Post by PB »

viewtopic.php?t=42067

I wish people used search before posting and created their thread in the proper forums sections, but I guess both are things of a distant past. [/rant]
TSib
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jun 16, 2016 8:22 am

Re: Bitmap creation failed in wxFreeChart

Post by TSib »

Thanks you for your answer. In fact I've already seen that topic. I've downloaded the recent version of wxFreeChart which already contains the solution. Unfortunately, I still have the same warning but now in the function "void AxisPlot::DrawDataAreaBackground(wxDC &dc, wxRect rc)". Please help me

S.T.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bitmap creation failed in wxFreeChart

Post by PB »

Where did you download your version of wxFreeChart from? I can't even find AxisPlot::DrawDataAreaBackground() in the wxFreeChart source I have.

Nevertheless, the solution should be still the same as in the post I referenced earlier: Make sure the bitmap dimensions are correct, i.e. neither is smaller than 1, using e.g. the posted fix.

Edit
You must be using iwbnwif's version of wxFreeChart, where the method was added

Code: Select all

// Draw the background of the data area, basically everything except the data.
void AxisPlot::DrawDataAreaBackground(wxDC &dc, wxRect rc)
{
    wxRect rcData;
    wxRect rcLegend;

    // Hackish test to see if the background needs to be redrawn 
    // due to a size change.
    if (rc.GetSize() != m_drawRect)
    {
        m_redrawDataArea = true;
        m_drawRect.SetSize(rc.GetSize());
        m_drawRect.SetTopLeft(wxPoint(0, 0));
    }

    // Calculate the rectangle where the actual data is plotted.
    CalcDataArea(dc, m_drawRect, rcData, rcLegend);
    
    // The plot area has changed (size change, axis change).
    if (m_redrawDataArea) {
.....
I believe the code is missing a check for m_drawRect and/or rc being empty or invalid. If either of these two is empty no drawing including bitmap creation should be even necessary...
TSib
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jun 16, 2016 8:22 am

Re: Bitmap creation failed in wxFreeChart

Post by TSib »

I've downloaded wxFreechart from "https://github.com/iwbnwif/wxFreeChart". So I've the same code that you wrote. :?

S.T.
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: Bitmap creation failed in wxFreeChart

Post by iwbnwif »

Hi,

Sorry that you are having this problem. I will try to create a fix within the next few days, but in the meantime if someone likes to make a pull request that is also very welcome :)
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Post Reply