Project

General

Profile

Wt::WTimer stops ticking

Added by Richel Bilderbeek almost 14 years ago

Dear fellow Wt users,

From the documentation I could not find out what causes a Wt::WTimer to stop ticking. But in my program it does: its does its job correctly, until suddenly it somehow loses its timeout ('ticking') event! The time it stops ticking varies between 10 seconds and never.

I have checked the following:

- the timer starts and works correctly, until it stops

- the timer is not deleted, stopped or disconnected by me

- the dialog, of which the timer is a member of, is not copied or deleted

  • valgrid's memcheck did not detect any memory usage problems

Below I have put the extracted problem in code, with all precautions I have taken.

The full code (+10.000 lines) can be viewed at http://richelbilderbeek.nl/ProjectGtstSource_0_43.htm, where the dialog is called 'ParticipantDialog'.

Thanks for your help, Bilderbikkel

//---------------------------------------------------------------------------
//dialog.h
//---------------------------------------------------------------------------
#ifndef DIALOG_H
#define DIALOG_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#include <Wt/WContainerWidget>
namespace Wt { struct WTimer; }
//---------------------------------------------------------------------------
///Dialog handles the user interface for a Participant.
struct Dialog : public Wt::WContainerWidget
{
  Dialog();
  ~Dialog();

  private:
  //Disable copying
  ParticipantDialog( const ParticipantDialog& );
  const ParticipantDialog& operator=( const ParticipantDialog& );

  const boost::scoped_ptr<Wt::WTimer> m_timer;

  void OnTimer();
};
//---------------------------------------------------------------------------
#endif // DIALOG_H

//---------------------------------------------------------------------------
//dialog.cpp
//---------------------------------------------------------------------------
#include <cassert>
#include <iostream
#include <Wt/WTimer>
#include "dialog.h"
//---------------------------------------------------------------------------
///to prevent it being delete by Wt classes
Dialog::Dialog()
  : m_timer(new Wt::WTimer)
{
  assert(m_timer);

  m_timer->timeout().connect(this,&Dialog::OnTimer);
  m_timer->setInterval(100);
  m_timer->start();
}
//---------------------------------------------------------------------------
Dialog::~Dialog()
{
  assert(!"I am never called, except for the end of the program")
}
//---------------------------------------------------------------------------
void Dialog::OnTimer()
{
  std::clog << "ParticipantDialog::OnTimer()\n";
}
//---------------------------------------------------------------------------

Replies (5)

RE: Wt::WTimer stops ticking - Added by Koen Deforche almost 14 years ago

Hey Richel,

I failed to reproduce this. Perhaps there is more to it, perhaps a specific browser or your configuration file ?

The test case I am trying is based on your code, is in attachment.

Regards,

koen

test26.cc (1.92 KB) test26.cc

RE: Wt::WTimer stops ticking - Added by Richel Bilderbeek almost 14 years ago

Hey Koen,

Thanks for your help.

The problem occurred on the following browsers and browser OS:

- Chromium under Lubuntu

- Firefox under Lubuntu

  • Internet Explorer under Windows

There are three servers I have this problem on:

- 2x Ubuntu Server edition 32-bit Maverick Meerkat (Natty changes the console windows to unreadable characters at all three servers)

  • 1x Lubuntu (Natty Narwhal), only as localhost
    On each server, I have never changed my wt_config.xml files, but when you are in doubt, I have added it as an attachment.

I am thinking of wrapping a non-destructable Wt::WTimer in a Singleton. Do you think that would be a good idea?

Thanks for thinking with me, Richel

RE: Wt::WTimer stops ticking: solution - Added by Richel Bilderbeek almost 14 years ago

The problem appears not to be in the code posted, because the code posted does not make heavy use of forward declarations [1]. Simply replacing a Wt::WTimer by a is-the-type-complete-checked version (using boost::checked_delete, see http://richelbilderbeek.nl/CppWtSafeTimer.htm) solves the problem.

Cheers, Bilderbikkel

[1] from http://www.boost.org/libs/utility/checked_delete.html: The C Standard allows, in 5.3.5/5, pointers to incomplete class types to be deleted with a delete-expression. When the class has a non-trivial destructor, or a class-specific operator delete, the behavior is undefined. Some compilers issue a warning when an incomplete type is deleted, but unfortunately, not all do, and programmers sometimes ignore or disable warnings.

RE: Wt::WTimer stops ticking - Added by Koen Deforche almost 14 years ago

Hey Richel,

What forward declaration caused the problem then? While a timer is running, and events are received by the application, no delete operation should be happening (and certainly not the WTimer should be deleted). Therefore I cannot understand what delete operation would have had "unspecified" behaviour ?

And, asfaik, gcc (which is one of the compilers we support) will not allow you to delete an object which is only forward-declarated.

I'ld still appreciate it if I can somehow reproduce the original problem.

Regards,

koen

RE: Wt::WTimer stops ticking - Added by Richel Bilderbeek almost 14 years ago

Hi Koen,

What forward declaration caused the problem then? While a timer is running, and events are received by the

application, no delete operation should be happening (and certainly not the WTimer should be deleted).

Therefore I cannot understand what delete operation would have had "unspecified" behaviour ?

I totally agree, so I was amazed (too) that creating a 'safe timer' solved the problem.

If you really want to reproduce the error: download the attached (Qt Creator) source, compile it (Projects -> ProjectGtst -> ProjectGtst.pro), start it, click 'Debug' and upload the attached parameter file. You will see virtual participants doing random things (and their timers will display a log message each timeout), until suddenly, they stop doing anything...

The code can be viewed at http://richelbilderbeek.nl/ProjectGtstSource_0_45.htm

The code with only Wt::WTimer replaced by 'safe timers' can be viewed at http://richelbilderbeek.nl/ProjectGtstSource_0_46.htm

Good luck and thanks, Richel

    (1-5/5)