<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Light Switch Client stop due to ++m_scheduler.event_count &amp;lt; 0?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39301/light-switch-client-stop-due-to-m_scheduler-event_count-0</link><description>I am working on nrf5_SDK_for_Mesh_v2.2.0 with nRF5_SDK_15.0.0 and softdevice 6.0.0. I run code on PCA10040 dev boards. I am trying use a timer to send onoff message from a client to two servers. but the client stopped after 2 hrs, it returns an error</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Nov 2018 20:35:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39301/light-switch-client-stop-due-to-m_scheduler-event_count-0" /><item><title>RE: Light Switch Client stop due to ++m_scheduler.event_count &lt; 0?</title><link>https://devzone.nordicsemi.com/thread/159632?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 20:35:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79ea2483-3e04-4a37-af2b-aca58815d603</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;I just discovered this issue myself, and out of curiosity, I searched to see if anyone else has reported it.&lt;/p&gt;
&lt;p&gt;I can add a clarification to the provided solution: since the count is incremented when an event is added to the queue, so too must the count be decremented when an event is removed from the queue. There are 2 places that events can be removed from the scheduler queue: in &lt;strong&gt;fire_timers&lt;/strong&gt; and in&amp;nbsp;&lt;strong&gt;remove_evt&lt;/strong&gt;. I copied the decrement instruction from&amp;nbsp;&lt;strong&gt;fire_timers&lt;/strong&gt; and inserted it in&amp;nbsp;&lt;strong&gt;remove_evt&lt;/strong&gt; before line 108:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (p_it-&amp;gt;p_next == p_evt)
{
    NRF_MESH_ASSERT(m_scheduler.event_count-- &amp;gt; 0); //ATTENTION: unofficial modification
    p_it-&amp;gt;p_next = p_evt-&amp;gt;p_next;
    break;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Light Switch Client stop due to ++m_scheduler.event_count &lt; 0?</title><link>https://devzone.nordicsemi.com/thread/158656?ContentTypeID=1</link><pubDate>Thu, 22 Nov 2018 13:42:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f82ff28-72b0-4f41-a7bb-bd783c4d0b52</guid><dc:creator>karinca</dc:creator><description>&lt;p&gt;this is not working, it causing mesh assert. Could you please explain how to implement this? (Also checked if the event_count &amp;gt; 0 condition before --)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Light Switch Client stop due to ++m_scheduler.event_count &lt; 0?</title><link>https://devzone.nordicsemi.com/thread/152397?ContentTypeID=1</link><pubDate>Wed, 10 Oct 2018 16:02:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42532d32-424a-44cb-ae2c-45719c2bec1f</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;The assert&amp;nbsp;NRF_MESH_ASSERT(++m_scheduler.event_count &amp;gt; 0) failed, due to an overflow (since event_count is of type uint16_t&amp;nbsp;and can&amp;#39;t contain a negative value).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The only place event_count is decremented is inside the function&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;fire_timers(..)&lt;/em&gt;. However, if the functions timer_sch_reschedule(..) or timer_sch_abort is called, the function remove_evt(..) will be called, and inside remove_evt(..), event_count is not decremented.&amp;nbsp;After 2 hours of running your application, these functions have been called enough times to make event_count overflow&lt;/p&gt;
&lt;p&gt;Thus, the error you encountered is due to a bug in the code, and is reported.&lt;/p&gt;
&lt;p&gt;The problem can be solved by adding&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;m_scheduler.event_count--;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;inside the function remove_evt(..).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards, Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>