← Back to team overview

kicad-developers team mailing list archive

Re: About Bug 1604841: Pcbnew crash at moving via, and boost::context fixes to make it compatible with boost 1.61

 

Hey,

pinpointing the problem proved really difficult, I didn't expect it where it was... This bug existed before my 1.61-patch and did not surface because DELEGATE would not clear its content on destruction. See the attached patch.

That being said, I'm not yet 100% sure the macro'ed code for old boost versions is 100% correct. During my bug search I refactored and checked that part for [1.54, 1.66) since I suspected my stuff being the cause. I'll check with 1.56 later, need to catch some sleep first...

Michael
>From 8d0b28ead9133c3e808f06d914463449fd6f08e0 Mon Sep 17 00:00:00 2001
From: decimad <michsteinb@xxxxxxxxx>
Date: Mon, 1 Aug 2016 05:11:29 +0200
Subject: [PATCH] Fix tool crash with "reentrant" states.

---
 common/tool/tool_manager.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp
index 0ec1882..46594da 100644
--- a/common/tool/tool_manager.cpp
+++ b/common/tool/tool_manager.cpp
@@ -532,11 +532,18 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
             {
                 if( tr.first.Matches( aEvent ) )
                 {
+                    // st->Push() might clear the transitions-list, copy the transition function
+                    // early. Can move the function since the transition list will be cleared.
+                    using coroutine_type = COROUTINE< int, const TOOL_EVENT& >;
+                    std::unique_ptr< coroutine_type > next_cofunc( 
+                        new coroutine_type( std::move( tr.second ) )
+                    );
+
                     // if there is already a context, then store it
                     if( st->cofunc )
                         st->Push();
 
-                    st->cofunc = new COROUTINE<int, const TOOL_EVENT&>( tr.second );
+                    st->cofunc = next_cofunc.release();
 
                     // as the state changes, the transition table has to be set up again
                     st->transitions.clear();
-- 
2.9.0.windows.1


Follow ups

References