#588 ConsumeQueue does not check for empty queue

closed-fixed
Stage (103)
5
2010-11-04
2010-06-14
No

Hi,

currently the Stg::World::ConsumeQueue method has two exit conditions:
1. it stops early if the priority queue is empty when ConsumeQueue starts;
2. otherwise, it consumes events until ev.time > sim_time.

If the queue is not empty but ev.time <= sim_time holds for all events in
the queue, this results in a pop from an empty queue. This is not a problem
as long as an interface remains subscribed, since this continually causes
new events to be pushed to the queue (with ev.time > sim_time). This happens
while ConsumeQueue is executed. But when the last interface is unsubscribed,
no further event will be enqueued, and this triggers the bug.

What happens when one pops from an empty priority_queue depends on the
C++ library vendor, but on my system (Gentoo, GCC 4.3.3, GNU C++ library
20100121) it returns bogus values. For example, it sometimes returns
(Model*) 0x11 as the ev.mod pointer, and then Stage crashes.

The attached patch changes ConsumeQueue so that is calls queue.empty()
after each handled event and finishes when that becomes true.

Might fix bug 2989947: http://sourceforge.net/tracker/?func=detail&aid=2989947&group_id=42445&atid=433164

Discussion

  • Richard Vaughan

    Richard Vaughan - 2010-11-04

    Fixed/patched in master at http://github.com/rtv/Stage. Thanks very much for your bugfix!

     
  • Richard Vaughan

    Richard Vaughan - 2010-11-04
    • status: open --> closed-fixed
     

Log in to post a comment.