Pcbnew hangs in infinite loop loading a board with complex Edge.Cuts layer

Bug #1766626 reported by Dick Hollenbeck
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
Undecided
Tomasz Wlostowski

Bug Description

Application: pcbnew
Version: (5.0.0-rc2-dev-569-g319908b-dirty), release build
Libraries:
    wxWidgets 3.0.2
    libcurl/7.47.0 OpenSSL/1.0.2g zlib/1.2.8 libidn/1.32 librtmp/2.3
Platform: Linux 4.4.0-62-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.58.0
    Curl: 7.47.0
    Compiler: GCC 5.4.0 with C++ ABI 1009

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=OFF
    KICAD_SCRIPTING_MODULES=OFF
    KICAD_SCRIPTING_WXPYTHON=OFF
    KICAD_SCRIPTING_ACTION_MENU=OFF
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=OFF
    KICAD_SPICE=OFF

For my testing I ran pcbnew stand alone, outside of project manager, but I don't think this matters.

During a board load, TOOL_MANAGER::ResetTools() -> LENGTH_TUNER_TOOL::Reset() ->
PNS::TOOL_BASE::Reset() ->
PNS::ROUTER::SyncWorld()
does not return.

The problem board is created empty, then by adding Edge.Cuts graphics via the DXF import using the attached *.dxf file. Save the board and then attempt to load it from disk. This fails by hanging.

Additionally, I found recently that I cannot exit pcbnew, File -> Exit hangs also, if the most recent activity is the DXF import into an empty board document tree.

I believe these two failures may involve the same code, but I did not break into the exit bug to verify.

I believe this is a relatively new bug. I was able to save and exit using a September-2017 build.

Tags: pcbnew
Revision history for this message
Dick Hollenbeck (dickelbeck) wrote :
Changed in kicad:
assignee: nobody → Tomasz Wlostowski (twlostow)
tags: added: pcbnew
Changed in kicad:
status: New → Confirmed
Revision history for this message
Tomasz Wlostowski (twlostow) wrote :

Hi Dick,

It's not an infinite loop, it's the P&S router getting stuck with far too much geometry data on the Edge.Cuts layer. Most of this comes from segment-based arc approximation (we don't have yet real arcs support in the DRC/P&S).

The DXF file you attached contains much more than the board's outline (there are texts, pads and lots of other stuff).

The only solution I see right now is an error/timeout message suggesting to simplify the drawings on the Edge.Cuts layer.

Tom

Revision history for this message
Seth Hillbrand (sethh) wrote :

Hi Tom-

Have a look at the attached patch when you have a chance.

I think that there was an error in the ConvertToPolyline calculation that forced the segment count to 32. Dick's board had many small diameter circles, so this caused a lot of extra segments.

It still isn't _fast_ but is much better.

Revision history for this message
Seth Hillbrand (sethh) wrote :

Ugh. Please disregard #3. I missed the internal angle representation (and forgot about our internal function that does this already)

Attached is the corrected version. Not as fast as #3 but better than before.

Revision history for this message
Jeff Young (jeyjey) wrote : Re: [Bug 1766626] Re: Pcbnew hangs in infinite loop loading a board with complex Edge.Cuts layer

@Seth, newer patch looks better.

A couple of thoughts: when you know the units it’s usually clearer to write: Millimeter2iu( … ) than: From_User_Unit( MILLIMETERS, … ), and the default of 0.05mm seems fairly large to me. We have a couple of constants:
constexpr int ARC_LOW_DEF = Millimeter2iu( 0.02 );
constexpr int ARC_HIGH_DEF = Millimeter2iu( 0.005 );
but even the “low definition” one is smaller. Is this code used for all edge-cut arcs?

> On 25 Apr 2018, at 00:57, Seth Hillbrand <email address hidden> wrote:
>
> Ugh. Please disregard #3. I missed the internal angle representation
> (and forgot about our internal function that does this already)
>
> Attached is the corrected version. Not as fast as #3 but better than
> before.
>
> ** Patch added: "0001-Fix-error-in-polyline-accuracy-calculation.patch"
> https://bugs.launchpad.net/kicad/+bug/1766626/+attachment/5126775/+files/0001-Fix-error-in-polyline-accuracy-calculation.patch
>
> --
> You received this bug notification because you are a member of KiCad Bug
> Squad, which is subscribed to KiCad.
> https://bugs.launchpad.net/bugs/1766626
>
> Title:
> Pcbnew hangs in infinite loop loading a board with complex Edge.Cuts
> layer
>
> Status in KiCad:
> Confirmed
>
> Bug description:
> Application: pcbnew
> Version: (5.0.0-rc2-dev-569-g319908b-dirty), release build
> Libraries:
> wxWidgets 3.0.2
> libcurl/7.47.0 OpenSSL/1.0.2g zlib/1.2.8 libidn/1.32 librtmp/2.3
> Platform: Linux 4.4.0-62-generic x86_64, 64 bit, Little endian, wxGTK
> Build Info:
> wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
> Boost: 1.58.0
> Curl: 7.47.0
> Compiler: GCC 5.4.0 with C++ ABI 1009
>
> Build settings:
> USE_WX_GRAPHICS_CONTEXT=OFF
> USE_WX_OVERLAY=OFF
> KICAD_SCRIPTING=OFF
> KICAD_SCRIPTING_MODULES=OFF
> KICAD_SCRIPTING_WXPYTHON=OFF
> KICAD_SCRIPTING_ACTION_MENU=OFF
> BUILD_GITHUB_PLUGIN=ON
> KICAD_USE_OCE=OFF
> KICAD_SPICE=OFF
>
> For my testing I ran pcbnew stand alone, outside of project manager,
> but I don't think this matters.
>
> During a board load, TOOL_MANAGER::ResetTools() -> LENGTH_TUNER_TOOL::Reset() ->
> PNS::TOOL_BASE::Reset() ->
> PNS::ROUTER::SyncWorld()
> does not return.
>
> The problem board is created empty, then by adding Edge.Cuts graphics
> via the DXF import using the attached *.dxf file. Save the board and
> then attempt to load it from disk. This fails by hanging.
>
> Additionally, I found recently that I cannot exit pcbnew, File -> Exit
> hangs also, if the most recent activity is the DXF import into an
> empty board document tree.
>
> I believe these two failures may involve the same code, but I did not
> break into the exit bug to verify.
>
> I believe this is a relatively new bug. I was able to save and exit
> using a September-2017 build.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/kicad/+bug/1766626/+subscriptions

Revision history for this message
Seth Hillbrand (sethh) wrote :

@Jeff good points all around. Unfortunately, in common, we don't know whether we are in PCBNEW with 1e6 IU/mm or Gerbview with 1e5 IU/mm (or page layout editor with 1e3 IU/mm or Eeschema with 39.37 IU/mm -- is this fun or what?). So we need to do the two-step of calling the routine through the main program.

But 0.02 makes more sense.

Also, in reviewing this, I think we should probably sync the graphical items as a layer_range rather than individual layers at a time. This speeds up the full world-sync substantially for Dick's test board.

Revised patch attached. @Tomasz, do you see any issues with the approach?

Revision history for this message
Jeff Young (jeyjey) wrote :

Ah, yes, I remember fighting with that when I created some of the constants. There are a few modules that are built with no definition of IU at all.

> On 25 Apr 2018, at 17:38, Seth Hillbrand <email address hidden> wrote:
>
> @Jeff good points all around. Unfortunately, in common, we don't know
> whether we are in PCBNEW with 1e6 IU/mm or Gerbview with 1e5 IU/mm (or
> page layout editor with 1e3 IU/mm or Eeschema with 39.37 IU/mm -- is
> this fun or what?). So we need to do the two-step of calling the
> routine through the main program.
>
> But 0.02 makes more sense.
>
> Also, in reviewing this, I think we should probably sync the graphical
> items as a layer_range rather than individual layers at a time. This
> speeds up the full world-sync substantially for Dick's test board.
>
> Revised patch attached. @Tomasz, do you see any issues with the
> approach?
>
> ** Patch added: "0001-Fix-error-in-polyline-accuracy-calculation.patch"
> https://bugs.launchpad.net/kicad/+bug/1766626/+attachment/5127128/+files/0001-Fix-error-in-polyline-accuracy-calculation.patch
>
> --
> You received this bug notification because you are a member of KiCad Bug
> Squad, which is subscribed to KiCad.
> https://bugs.launchpad.net/bugs/1766626
>
> Title:
> Pcbnew hangs in infinite loop loading a board with complex Edge.Cuts
> layer
>
> Status in KiCad:
> Confirmed
>
> Bug description:
> Application: pcbnew
> Version: (5.0.0-rc2-dev-569-g319908b-dirty), release build
> Libraries:
> wxWidgets 3.0.2
> libcurl/7.47.0 OpenSSL/1.0.2g zlib/1.2.8 libidn/1.32 librtmp/2.3
> Platform: Linux 4.4.0-62-generic x86_64, 64 bit, Little endian, wxGTK
> Build Info:
> wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
> Boost: 1.58.0
> Curl: 7.47.0
> Compiler: GCC 5.4.0 with C++ ABI 1009
>
> Build settings:
> USE_WX_GRAPHICS_CONTEXT=OFF
> USE_WX_OVERLAY=OFF
> KICAD_SCRIPTING=OFF
> KICAD_SCRIPTING_MODULES=OFF
> KICAD_SCRIPTING_WXPYTHON=OFF
> KICAD_SCRIPTING_ACTION_MENU=OFF
> BUILD_GITHUB_PLUGIN=ON
> KICAD_USE_OCE=OFF
> KICAD_SPICE=OFF
>
> For my testing I ran pcbnew stand alone, outside of project manager,
> but I don't think this matters.
>
> During a board load, TOOL_MANAGER::ResetTools() -> LENGTH_TUNER_TOOL::Reset() ->
> PNS::TOOL_BASE::Reset() ->
> PNS::ROUTER::SyncWorld()
> does not return.
>
> The problem board is created empty, then by adding Edge.Cuts graphics
> via the DXF import using the attached *.dxf file. Save the board and
> then attempt to load it from disk. This fails by hanging.
>
> Additionally, I found recently that I cannot exit pcbnew, File -> Exit
> hangs also, if the most recent activity is the DXF import into an
> empty board document tree.
>
> I believe these two failures may involve the same code, but I did not
> break into the exit bug to verify.
>
> I believe this is a relatively new bug. I was able to save and exit
> using a September-2017 build.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/kicad/+bug/1766626/+subscriptions

Revision history for this message
Dick Hollenbeck (dickelbeck) wrote :

Thank you all for your time. I have no particular preference as to a solution. Obviously this was not going to result in an actual PCB outline. I was just trying to get dimensional take offs to mate a carrier card to a daughter card. Since this came up I switched over to FreeCAD to get this dimensional information (regarding board size and pad locations only.)

Your chosen path of resolution should weigh most heavily the user experience. If something hangs the program for upwards of 30 minutes, this is perceived by any user without gdb, tantamount to a hang or lock up.

Fix that and you have made a nice improvement. I don't think it is necessary to actually process Edge.Cuts this complicated since they are bogus.

Revision history for this message
Dick Hollenbeck (dickelbeck) wrote :

For the record:
IMO Librecad is better for this 2D DXF need than FreeCAD.

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

@Seth, I tested your patch. AFAICT it does not address the hang on exit problem or maybe my computer is too slow to see the difference. I seem to be getting the same hang with or without your patch.

@Tom, I can understand this hanging during routing but the hang exiting the program doesn't make a lot of sense to me. If I merely place the dxf file in the edge cuts layer of my board, why does that trigger the p&s to begin making board outline calculations? I'm ok with implementing a time out if the board outline calculations take to long. I realize that the dxf Dick included isn't realistic but certainly if it happened once, it will happen again. The other option is to throw up a progress dialog that can dismiss the calculations. This would inform the user that something is indeed happening and taking a really long time.

I think this needs to be fixed before rc2. Users who run into this will instinctively think kicad has locked up not stuck in massive calculation loop.

Revision history for this message
Seth Hillbrand (sethh) wrote :

@Tom - It looks like we had two tools that each reset the PNS TOOL_BASE when they were reset individually. Since the tools are also reset when activated, I don't think (please correct me if I'm wrong here) that we need to reset the TOOL_BASE at other times.

The attached patch (this replaces the previous patches) takes care of this. It still takes about 2.5s to activate either the router tool or length tuner tool on Dick's DXF board. But it avoids the double-call that slowed it down on opening/closing.

Thoughts?

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

@Seth, I just finished reviewing and testing your latest patch and everything looks good. @Tom, do you have any concerns with Seth's changes?

Revision history for this message
KiCad Janitor (kicad-janitor) wrote :

Fixed in revision 2a87117edc44248e89ee15b348a8e139db9e6524
https://git.launchpad.net/kicad/patch/?id=2a87117edc44248e89ee15b348a8e139db9e6524

Changed in kicad:
status: Confirmed → Fix Committed
Revision history for this message
jean-pierre charras (jp-charras) wrote :

I committed this patch by mistake. Sorry.
Please, let me know if I must reverse this commit (or feel free to reverse it).
Thanks.

Changed in kicad:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.