Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 83fba72e38fcd7e842953a5a2558d37ab086b2fb5bd45a551e488bdc0fb533b0
Ticket: 6cf568a21bd8fc9b1f63543efe92cbedaa5a7160
Tcl_Eval() causes new segfault
User & Date: hypnotoad on 2017-11-27 16:51:22
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    Ever since checkin e76a04e48fb1b8500f44c11120b8c8f42ed08b35, toadkits segfault on startup. An lldb trace yields the following:
    
    <BEGIN SNIPPET>
    (lldb) bt
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xe8)
      * frame #0: 0x000000010001546e toadkit`TclCreateObjCommandInNs + 56
        frame #1: 0x00000001000fdb7d toadkit`AllocObject + 410
        frame #2: 0x00000001000fdf29 toadkit`TclNRNewObjectInstance + 177
        frame #3: 0x000000010010076e toadkit`TclOO_Class_Create + 456
        frame #4: 0x00000001000fefad toadkit`TclOOObjectCmdCore + 676
        frame #5: 0x0000000100016ac9 toadkit`TclNRRunCallbacks + 80
        frame #6: 0x0000000100017d36 toadkit`TclEvalEx + 2012
        frame #7: 0x0000000100018619 toadkit`Tcl_Eval + 39
        frame #8: 0x00000001001f23a9 toadkit`Odielibc_Init + 108
        frame #9: 0x000000010000580e toadkit`Tclkit_AppInit + 101
        frame #10: 0x00000001000bec0d toadkit`Tcl_MainEx + 403
        frame #11: 0x00000001000020d0 toadkit`main + 68
        frame #12: 0x00007fff61e30145 libdyld.dylib`start + 1
        frame #13: 0x00007fff61e30145 libdyld.dylib`start + 1
    <END SNIPPET>
    
    The offending statement in C is:
    
    <BEGIN SNIPPET>
    if(interp) {
    if(Tcl_Eval(interp,
            "\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/polygon.tcl\n" \
            "namespace eval ::polygon {}\n" \
            "###\n" \
            "# Decompose a concave polygon into a set of convex polygons\n" \
            "###\n" \
            "proc ::polygon::convex_decompose POLY {\n" \
            "  if {[is_convex $POLY]} {\n" \
            "    return [list $POLY]\n" \
            "  }\n" \
            "  set SEGMENTS [::odielib::segset new]\n" \
            "  $SEGMENTS polygon_add 1 $POLY\n" \
            "  $SEGMENTS make_convex\n" \
            "  set result [$SEGMENTS polygons]\n" \
            "  $SEGMENTS destroy\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygon::set_union args {\n" \
            "  set SEGMENTS [::odielib::segset new]\n" \
            "  set polycount 0\n" \
            "  foreach poly $args {\n" \
            "    incr polycount\n" \
            "    set POLYGONS($polycount) $poly\n" \
            "    $SEGMENTS polygon_add $polycount $POLYGONS($polycount)\n" \
            "  }\n" \
            "  set cleanup [$SEGMENTS cleanup]\n" \
            "  set cleanup [$SEGMENTS cleanup]\n" \
            "  set connections {}\n" \
            "  set newseg {}\n" \
            "  for {set i 1} {$i <= $polycount} {incr i} {\n" \
            "    set COORDS [coords $POLYGONS($i)]\n" \
            "    for {set j 1} {$j <= $polycount} {incr j} {\n" \
            "      if {$i==$j} continue\n" \
            "      foreach vertex $COORDS {\n" \
            "        if {$vertex in $connections} continue\n" \
            "        set within [within $vertex $POLYGONS($j)]\n" \
            "        if {$within>0} {\n" \
            "          set connection [$SEGMENTS edge_connection $vertex $j]\n" \
            "          if {![::vector::is_null $connection]} {\n" \
            "            lappend newseg $vertex $connection\n" \
            "            lappend connections $vertex\n" \
            "          }\n" \
            "        }\n" \
            "      }\n" \
            "    }\n" \
            "  }\n" \
            "  foreach {v c} $newseg {\n" \
            "    $SEGMENTS segment_add_virtual $v $c\n" \
            "  }\n" \
            "  $SEGMENTS make_convex\n" \
            "  set result [$SEGMENTS polygons]\n" \
            "  $SEGMENTS destroy\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygon::set_intersection {UNION args} {\n" \
            "  set result {}\n" \
            "  set id 0\n" \
            "  set result {}\n" \
            "  foreach poly $UNION {\n" \
            "    set match 1\n" \
            "    set center [center $poly]\n" \
            "    foreach ipoly $args {\n" \
            "      if {[within {*}[::vectorxy::flatten $center] $ipoly]<0} {\n" \
            "        set match 0\n" \
            "        break\n" \
            "      }\n" \
            "    }\n" \
            "    if {$match} {\n" \
            "      lappend result $poly\n" \
            "    }\n" \
            "  }\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygon::set_difference {UNION args} {\n" \
            "  set result {}\n" \
            "  set id 0\n" \
            "  set result {}\n" \
            "  foreach poly $UNION {\n" \
            "    set match 1\n" \
            "    set center [center $poly]\n" \
            "    foreach ipoly $args {\n" \
            "      if {[within {*}[vectorxy::flatten $center] $ipoly]>=0} {\n" \
            "        set match 0\n" \
            "        break\n" \
            "      }\n" \
            "    }\n" \
            "    if {$match} {\n" \
            "      lappend result $poly\n" \
            "    }\n" \
            "  }\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygon::within_concave {A POLY} {\n" \
            "  if {[is_convex $POLY]} {\n" \
            "    return [within {*}[vectorxy::flatten $A] $POLY]\n" \
            "  }\n" \
            "  set polylist [convex_decompose $POLY]\n" \
            "  return [within {*}[vectorxy::flatten $A] {*}$polylist]\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/polygon.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/polygonxyz.tcl\n" \
            "namespace eval ::polygonxyz {}\n" \
            "###\n" \
            "# Decompose a concave polygon into a set of convex polygons\n" \
            "###\n" \
            "proc ::polygonxyz::convex_decompose POLY {\n" \
            "  if {[is_convex $POLY]} {\n" \
            "    return [list $POLY]\n" \
            "  }\n" \
            "  set SEGMENTS [::odielib::segset new]\n" \
            "  $SEGMENTS uv_transform polygon $POLY\n" \
            "  $SEGMENTS polygon_add 1 $POLY\n" \
            "  $SEGMENTS make_convex\n" \
            "  set result [$SEGMENTS polygons]\n" \
            "  $SEGMENTS destroy\n" \
            "  return $result    \n" \
            "}\n" \
            "\n" \
            "proc ::polygonxyz::set_union args {\n" \
            "  set SEGMENTS [::odielib::segset new]\n" \
            "  $SEGMENTS uv_transform polygon [lindex $args 0]\n" \
            "  set polycount 0\n" \
            "  foreach poly $args {\n" \
            "    incr polycount\n" \
            "    set POLYGONS($polycount) $poly\n" \
            "    $SEGMENTS polygon_add $polycount $POLYGONS($polycount)\n" \
            "  }\n" \
            "  set cleanup [$SEGMENTS cleanup]\n" \
            "  set cleanup [$SEGMENTS cleanup]\n" \
            "  set connections {}\n" \
            "  set newseg {}\n" \
            "  for {set i 1} {$i <= $polycount} {incr i} {\n" \
            "    set COORDS [coords $POLYGONS($i)]\n" \
            "    for {set j 1} {$j <= $polycount} {incr j} {\n" \
            "      if {$i==$j} continue\n" \
            "      foreach vertex $COORDS {\n" \
            "        if {$vertex in $connections} continue\n" \
            "        set within [within $vertex $POLYGONS($j)]\n" \
            "        if {$within>0} {\n" \
            "          set connection [$SEGMENTS edge_connection $vertex $j]\n" \
            "          if {![::vector::is_null $connection]} {\n" \
            "            lappend newseg $vertex $connection\n" \
            "            lappend connections $vertex\n" \
            "          }\n" \
            "        }\n" \
            "      }\n" \
            "    }\n" \
            "  }\n" \
            "  foreach {v c} $newseg {\n" \
            "    $SEGMENTS segment_add_virtual $v $c\n" \
            "  }\n" \
            "  $SEGMENTS make_convex\n" \
            "  set result [$SEGMENTS polygons]\n" \
            "  $SEGMENTS destroy\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygonxyz::set_intersection {UNION args} {\n" \
            "  set result {}\n" \
            "  set id 0\n" \
            "  set result {}\n" \
            "  foreach poly $UNION {\n" \
            "    set match 1\n" \
            "    set center [center $poly]\n" \
            "    foreach ipoly $args {\n" \
            "      if {[within $center $ipoly]<0} {\n" \
            "        set match 0\n" \
            "        break\n" \
            "      }\n" \
            "    }\n" \
            "    if {$match} {\n" \
            "      lappend result $poly\n" \
            "    } \n" \
            "  }\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygonxyz::set_difference {UNION args} {\n" \
            "  set result {}\n" \
            "  set id 0\n" \
            "  set result {}\n" \
            "  foreach poly $UNION {\n" \
            "    set match 1\n" \
            "    set center [center $poly]\n" \
            "    foreach ipoly $args {\n" \
            "      if {[within $center $ipoly]>=0} {\n" \
            "        set match 0\n" \
            "        break\n" \
            "      }\n" \
            "    }\n" \
            "    if {$match} {\n" \
            "      lappend result $poly\n" \
            "    } \n" \
            "  }\n" \
            "  return $result\n" \
            "}\n" \
            "\n" \
            "proc ::polygonxyz::within_concave {A POLY} {\n" \
            "  if {[is_convex $POLY]} {\n" \
            "    return [within $A $POLY]\n" \
            "  }\n" \
            "  set polylist [convex_decompose $POLY]\n" \
            "  return [within_set $A {*}$polylist]\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/polygonxyz.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/segset.tcl\n" \
            "if {[info command ::odielib::segset] eq {}} {\n" \
            "::oo::class create ::odielib::segset {\n" \
            "  constructor {} {\n" \
            "    my SegmentSet_Init\n" \
            "  }\n" \
            "\n" \
            "  method fix_coincident {} {\n" \
            "    set fixes 0\n" \
            "    for {set count 0} {$count < 1000} {incr count} {\n" \
            "      my modified 0\n" \
            "      foreach problem [my check_coincident] {\n" \
            "        my vertex_add [dict get $problem intercept1:] [dict get $problem intercept2:]\n" \
            "      }\n" \
            "      if {![my modified]} break\n" \
            "      incr fixes\n" \
            "    }\n" \
            "    return $fixes\n" \
            "  }\n" \
            "\n" \
            "  # Break up oblique angles\n" \
            "  method make_convex {} {\n" \
            "    set newseg 0\n" \
            "    my fix_coincident\n" \
            "    for {set count 0} {$count < 128} {incr count} {\n" \
            "      my modified 0\n" \
            "      foreach {vertex connection} [my check_oblique] {\n" \
            "        set c [my segment_add_virtual $vertex $connection]\n" \
            "        incr newseg $c\n" \
            "      }\n" \
            "      if {![my modified]} break\n" \
            "    }\n" \
            "    return $newseg\n" \
            "  }\n" \
            "}\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/segset.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/plotter.tcl\n" \
            "if {[info command ::odielib::plotter] eq {}} {\n" \
            "::oo::class create ::odielib::plotter {\n" \
            "}\n" \
            "}\n" \
            "proc ::plotter name {\n" \
            "  ::odielib::plotter create $name\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/plotter.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/slicer.tcl\n" \
            "if {[info command ::odielib::slicer] eq {}} {\n" \
            "::oo::class create ::odielib::slicer {\n" \
            "  superclass ::odielib::plotter\n" \
            "  \n" \
            "  constructor {} {\n" \
            "    my Slicer_Init\n" \
            "  }\n" \
            "}\n" \
            "}\n" \
            "\n" \
            "proc ::slicer name {\n" \
            "  ::odielib::slicer create $name\n" \
            "  return $name\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/slicer.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/wallset.tcl\n" \
            "if {[info command ::odielib::wallset] eq {}} {\n" \
            "::oo::class create ::odielib::wallset {\n" \
            "}\n" \
            "}\n" \
            "\n" \
            "proc ::wallset name {\n" \
            "  return [::odielib::wallset create $name]\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/wallset.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/faceset.tcl\n" \
            "if {[info command ::odielib::polygonhull] eq {}} {\n" \
            "::oo::class create ::odielib::polygonhull {\n" \
            "  constructor {} {\n" \
            "    my PolygonHull_Init\n" \
            "  }\n" \
            "\n" \
            "  method SimplifyStep {} {\n" \
            "    puts [list SimplifyStep]\n" \
            "    set vol_list  [my volume_list]\n" \
            "    foreach vid $vol_list {\n" \
            "      if {$vid<=0} continue\n" \
            "      set volume_center($vid) [my volume_center $vid]\n" \
            "    }\n" \
            "    set changes 0\n" \
            "    set face_list [lsort -integer [my face_list]]\n" \
            "    set face_mod {}\n" \
            "    foreach id $face_list {\n" \
            "      set facepolygon($id) [my face_polygon $id]\n" \
            "      set facesides($id)   [my face_volume $id]\n" \
            "    }\n" \
            "    ###\n" \
            "    # WHY IS THIS AN INFINITE LOOP?!?!?\n" \
            "    ###\n" \
            "    foreach i $face_list {\n" \
            "      foreach j $face_list {\n" \
            "        #if {$j>=$i} continue\n" \
            "        if {![::polygon::coplaner $facepolygon($i) $facepolygon($j)]} continue\n" \
            "\n" \
            "        set union [::polygon::union $facepolygon($i) $facepolygon($j)]\n" \
            "        set intersect [::polygon::intersection $union $facepolygon($i) $facepolygon($j)]\n" \
            "        if {![llength $intersect]} continue\n" \
            "        incr changes\n" \
            "        lappend face_mod $i $j\n" \
            "        my face_delete $i\n" \
            "        my face_delete $j\n" \
            "        set vola [lindex $facesides($i) 1]\n" \
            "        set volb [lindex $facesides($j) 1]\n" \
            "        foreach poly $intersect {\n" \
            "          set id [my face_create $i {*}[::polygon::coords $poly]]\n" \
            "          if {$vola>0} {\n" \
            "            set sidea [my face_side $id $volume_center($vola)]\n" \
            "            my face_volume $id $sidea $vola\n" \
            "          }\n" \
            "          if {$volb>0} {\n" \
            "            set sideb [my face_side $id $volume_center($volb)]\n" \
            "            my face_volume $id $sideb $volb\n" \
            "          }\n" \
            "        }\n" \
            "        foreach poly [::polygon::clip $union $facepolygon($i) $facepolygon($j)] {\n" \
            "          set id [my face_create -1 {*}[::polygon::coords $poly]]\n" \
            "          if {$vola>0} {\n" \
            "            set side [my face_side $id $volume_center($vola)]\n" \
            "            my face_volume $id $side $vola\n" \
            "          }\n" \
            "        }\n" \
            "        foreach poly [::polygon::clip $union $facepolygon($j) $facepolygon($i)] {\n" \
            "          set id [my face_create -1 {*}[::polygon::coords $poly]]\n" \
            "          if {$volb>0} {\n" \
            "            set side [my face_side $id $volume_center($volb)]\n" \
            "            my face_volume $id $side $volb\n" \
            "          }\n" \
            "        }\n" \
            "        return 1\n" \
            "      }\n" \
            "    }\n" \
            "    return $changes\n" \
            "  }\n" \
            "\n" \
            "  method simplify {} {\n" \
            "    puts [list [self] simplify]\n" \
            "    set changes 1\n" \
            "    set count 0\n" \
            "    while {$changes>0} {\n" \
            "      if {[incr count]>1000} {\n" \
            "        error \"Infinite loop\"\n" \
            "      }\n" \
            "      set changes [my SimplifyStep]\n" \
            "      puts [list [self] simplify $count $changes]\n" \
            "    }\n" \
            "  }\n" \
            "}\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/geometry/faceset.tcl\n" \
            "# BEGIN /Users/seandeelywoods/dev/dirt/odielib/cmodules/typespec/simulator.tcl\n" \
            "if {[info command ::odielib::simulator] eq {}} {\n" \
            "::oo::class create ::odielib::simulator {\n" \
            "  constructor {} {\n" \
            "    my C_Init\n" \
            "  }\n" \
            "}\n" \
            "}\n" \
            "if {[info command ::odielib::entity] eq {}} {\n" \
            "::oo::class create ::odielib::entity {\n" \
            "  constructor {simulatorObj} {\n" \
            "    my C_Init $simulatorObj\n" \
            "  }\n" \
            "}\n" \
            "}\n" \
            "if {[info command ::odielib::simtype] eq {}} {\n" \
            "::oo::class create ::odielib::simtype {\n" \
            "  constructor {simulatorObj} {\n" \
            "    my C_Init $simulatorObj\n" \
            "  }\n" \
            "}\n" \
            "}\n" \
            "# END /Users/seandeelywoods/dev/dirt/odielib/cmodules/typespec/simulator.tcl\n" \
            "\n" )) return TCL_ERROR;
      }
    </END SNIPPET>
    
  5. foundin changed to: "core-8-branch"
  6. is_private changed to: "0"
  7. login: "hypnotoad"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "5846a328c39e4967aaeb56d4e03d3e783e2dd1b8"
  10. resolution changed to: "None"
  11. severity changed to: "Critical"
  12. status changed to: "Open"
  13. submitter changed to: "hypnotoad"
  14. subsystem changed to: "45. Parsing and Eval"
  15. title changed to: "Tcl_Eval() causes new segfault"
  16. type changed to: "Bug"