Custom control occur,Fatal IO error on X server :0.0 Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
yuson
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Jul 07, 2019 8:33 pm

Custom control occur,Fatal IO error on X server :0.0

Post by yuson » Mon Jul 08, 2019 12:55 am

I customize a control (DevButton) in wxScrolled, which overrides the OnPaint function. This control is drawn in the main thread, sometimes XIO error occurs, "Fatal IO error 104 on X server: 0.0"or"Fatal IO error 0 on X server: 0.0." Can you help me?
Environment:
wxWidgets-3.0.4
gtk+-2.24.29
arm-linux-4.1.15

Code: Select all

 void DevButton::OnPaint(wxPaintEvent& event)
{
  wxBufferedPaintDC dc(this);

  PrepareDC(dc);

  wxString channelName;
  bool leftStatus, rightStatus;
  wxRect childRect, leftRect, rightRect;
  wxPoint ptStart, ptEnd;
  wxPoint ptLeftStart, ptRightStart, ptLeftEnd, ptRightEnd;
  wxRect clientRect = GetClientRect();

  if (dc.IsOk())
  {
    if (GetCapture() != this)
      dc.GradientFillLinear(clientRect, m_normalColourTop, m_normalColourBottom, wxSOUTH);
    else
      dc.GradientFillLinear(clientRect, m_pressedColourTop, m_pressedColourBottom, wxSOUTH);

    if (GetCapture() == this)
      clientRect.Offset(1, 1);

    /* step1
     * .--------.
     * |        |
     * |        |
     * |        |
     * |        |
     * `--------`
     */

    //step2 draw name section
    childRect.SetTopLeft(clientRect.GetTopLeft());
    ptStart = clientRect.GetTopLeft() + wxPoint(0, clientRect.GetHeight() * 2 / (2 + DEV_PAIR_CH_NUM));
    ptEnd = clientRect.GetTopRight() + wxPoint(0, clientRect.GetHeight() * 2 / (2 + DEV_PAIR_CH_NUM));
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)));
    dc.DrawLine(ptStart, ptEnd);
    /* step2
     * .--------.
     * |        |
     * |        |
     * ..........
     * |        |
     * `--------`
     */

    childRect.SetBottomRight(ptEnd);
    dc.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD));//FIXME:max length == 9
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)));
    dc.DrawLabel(m_name, childRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);

    //step3 draw left channel section
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)));
    ptStart += wxPoint(clientRect.GetWidth() / 3, 0);
    ptEnd = ptStart + wxPoint(0, clientRect.GetHeight() * DEV_PAIR_CH_NUM / (2 + DEV_PAIR_CH_NUM));
    dc.DrawLine(ptStart, ptEnd);
    /* step3
     * .--------.
     * |        |
     * |        |
     * ..........
     * |  |     |
     * `--------`
     */

    //step4 draw address section
    childRect.SetTopLeft(ptStart);
    ptStart += wxPoint(clientRect.GetWidth() / 3, 0);
    ptEnd += wxPoint(clientRect.GetWidth() / 3, 0);
    dc.DrawLine(ptStart, ptEnd);
    /* step4
     * .--------.
     * |        |
     * |        |
     * ..........
     * |  |  |  |
     * `--------`
     */

    childRect.SetBottomRight(ptEnd);
    dc.SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD));
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)));
    dc.DrawLabel(m_addr, childRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);

    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)));
    ptLeftStart = clientRect.GetTopLeft() + wxPoint(0, clientRect.GetHeight() * 2 / (2 + DEV_PAIR_CH_NUM));
    ptLeftEnd = ptLeftStart + wxPoint(clientRect.GetWidth() / 3, 0);
    ptRightStart = ptLeftStart + wxPoint(clientRect.GetWidth() * 2 / 3, 0);
    ptRightEnd = ptLeftEnd + wxPoint(clientRect.GetWidth() * 2 / 3, 0);
    for (int i = 0; i < DEV_PAIR_CH_NUM; i++)
    {
      leftRect.SetTopLeft(ptLeftStart + wxPoint(0, 1));
      rightRect.SetTopLeft(ptRightStart + wxPoint(1, 1));
      ptLeftStart.y += clientRect.GetHeight() / (2 + DEV_PAIR_CH_NUM);
      ptLeftEnd.y += clientRect.GetHeight() / (2 + DEV_PAIR_CH_NUM);
      ptRightStart.y += clientRect.GetHeight() / (2 + DEV_PAIR_CH_NUM);
      ptRightEnd.y += clientRect.GetHeight() / (2 + DEV_PAIR_CH_NUM);
      leftRect.SetBottomRight(ptLeftEnd - wxPoint(1, 1));
      rightRect.SetBottomRight(ptRightEnd - wxPoint(0, 1));

      leftStatus = rightStatus = false;
      if (m_channelStatus != 0)
      {
        channelName = wxString::Format(wxT("CH%d"), (int)(m_channelStatus >> (8 * (i * 2))) & 0x7F);
        if ((m_channelStatus >> (8 * (i * 2))) & 0x80)
        {
          if (i * 2 < m_channel.GetCount() && channelName == m_channel[i * 2])
            leftStatus = true;
          else if (i * 2 + 1 < m_channel.GetCount() && channelName == m_channel[i * 2 + 1])
            rightStatus = true;
        }

        channelName = wxString::Format(wxT("CH%d"), (int)(m_channelStatus >> (8 * (i * 2 + 1))) & 0x7F);
        if ((m_channelStatus >> (8 * (i * 2 + 1))) & 0x80)
        {
          if (i * 2 < m_channel.GetCount() && channelName == m_channel[i * 2])
            leftStatus = true;
          else if (i * 2 + 1 < m_channel.GetCount() && channelName == m_channel[i * 2 + 1])
            rightStatus = true;
        }
      }

      dc.GradientFillLinear(leftRect, leftStatus ? DEV_CH_ACTIVATE_COLOUR : DEV_CH_INACTIVATE_COLOUR, leftStatus ? DEV_CH_ACTIVATE_COLOUR : DEV_CH_INACTIVATE_COLOUR);
      dc.GradientFillLinear(rightRect, rightStatus ? DEV_CH_ACTIVATE_COLOUR : DEV_CH_INACTIVATE_COLOUR, rightStatus ? DEV_CH_ACTIVATE_COLOUR : DEV_CH_INACTIVATE_COLOUR);

      if (i < DEV_PAIR_CH_NUM - 1)
      {
        dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)));
        dc.DrawLine(ptLeftStart, ptLeftEnd);
        dc.DrawLine(ptRightStart, ptRightEnd);
      }

      dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)));
      dc.DrawLabel(i * 2 < m_channel.GetCount() ? m_channel[i * 2] : wxT(""), leftRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
      dc.DrawLabel(i * 2 + 1 < m_channel.GetCount() ? m_channel[i * 2 + 1] : wxT(""), rightRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
    }
  }
}

void DevButton::OnLeftDown(wxMouseEvent& event)
{
  if (GetCapture() != this)
  {
    CaptureMouse();
    //m_bCapture = true;
    Refresh();
  }

  if (m_bDragging)
  {
    m_bMotion = false;
    m_curPt = event.GetPosition();
  }
}

void DevButton::OnLeftUp(wxMouseEvent& event)
{
  if (GetCapture() == this)
  {
    ReleaseMouse();
    //m_bCapture = false;
    Refresh();

    if (GetClientRect().Contains(event.GetPosition()))
    {
      if (!m_bMotion)
      {
        wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
        GetEventHandler()->AddPendingEvent(evt);
      }

      //Feedback
#if FEEDBACK_USE_TIMER
      UiFeedBack(FEEDBACK_TONE_OPEN, FEEDBACK_TIME);
#else
      UiFeedBack(FEEDBACK_TIME);
#endif // FEEDBACK_USE_TIMER
    }

    if (m_bDragging)
    {
      wxCommandEvent evt(wxEVT_COMMAND_DEV_BUTTON_DRAGGING, GetId());
      evt.SetEventObject(this);
      wxQueueEvent(m_parent, evt.Clone());
    }
  }
}
Thanks.

User avatar
doublemax
Moderator
Moderator
Posts: 14198
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom control occur,Fatal IO error on X server :0.0

Post by doublemax » Mon Jul 08, 2019 5:18 am

I can't spot any obvious errors. Are you sure the error is caused by this code? Can you try to build and run some of the wxWidgets samples and check if they cause the same error?
Use the source, Luke!

yuson
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Jul 07, 2019 8:33 pm

Re: Custom control occur,Fatal IO error on X server :0.0

Post by yuson » Mon Jul 08, 2019 11:58 pm

Thank you for your reply.
The CPU occupancy is DebButton: 33%, xorg: 20%, and it works well when I change the wxBufferedPaintDC into wxClientDC and reduce the refresh frequency. I don't quite understand why. Can you give me some advice? My hardware is imx6ull.

Post Reply