Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your output sequence, the pointers are alternating between <code>0xc1e048</code> and <code>0x696828</code>, implying that <code>0xc1e048</code> is the first item in the list and <code>0x696828</code> is the second. Based on that, it looks like the object at <code>0xc1e048</code> is getting unlinked while <code>GameTurn::GameTurn</code> is in the middle of the loop, most likely in the call to <code>timeobject-&gt;mapobject_-&gt;Tick()</code>, or by another thread as mentioned by @hmjd. Removing an object from the list makes the iterator pointing to the object invalid.</p> <p>Assuming the code is single threaded and the call to <code>Tick</code> is causing the problem, then something like this might work:</p> <pre><code>void GameTime::GameTurn(uint16_t _time) { tick_ += _time; for(std::list&lt;TimeObject*&gt;::iterator it = TimeObject::list_.begin(); it != TimeObject::list_.end(); ) { TimeObject *timeobject = *it; ++it; printf("GameTurn %p\n", timeobject); if(timeobject == NULL) { printf("continue\n"); continue; } timeobject-&gt;time_ += _time; if(timeobject-&gt;speed_ &amp;&amp; timeobject-&gt;time_ &gt;= timeobject-&gt;speed_) { while(timeobject-&gt;timeobject_flags_.linked_ &amp;&amp; timeobject-&gt;time_ - timeobject-&gt;speed_ &gt; 0) { timeobject-&gt;time_ -= timeobject-&gt;speed_; if(timeobject-&gt;mapobject_) { timeobject-&gt;mapobject_-&gt;Tick(); } } } } } </code></pre> <p>(The only difference is the the increment of <code>it</code> is moved from the <code>for</code> statement to the loop body after assigning <code>it</code> to <code>timeobject</code>. Advancing <code>it</code> before it can be invalidated should fix the problem.</p> <p>If your code is multithreaded, you will need a mutex.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload