[GRASS-dev] [GRASS GIS] #3429: g.gui.iclass: segfault when loading vector layer

#3429: g.gui.iclass: segfault when loading vector layer
------------------------------------------+-------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Keywords: g.gui.iclass import segfault | CPU: Unspecified
Platform: Unspecified |
------------------------------------------+-------------------------
* define group
* define classes
* digitize a few training areas
* save training areas to vector map
* close g.gui.iclass
* reopen g.gui.iclass
* import saved vector maps
=> segfault

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by mlennert):

Replying to [ticket:3429 mlennert]:
> * define group
> * define classes
> * digitize a few training areas
> * save training areas to vector map
> * close g.gui.iclass
> * reopen g.gui.iclass
> * import saved vector maps
> => segfault

I still have this problem. Can anyone reproduce ? Does anyone have a hint
on how to debug this ?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by annakrat):

Replying to [comment:1 mlennert]:
> Replying to [ticket:3429 mlennert]:
> > * define group
> > * define classes
> > * digitize a few training areas
> > * save training areas to vector map
> > * close g.gui.iclass
> > * reopen g.gui.iclass
> > * import saved vector maps
> > => segfault
>
> I still have this problem. Can anyone reproduce ? Does anyone have a
hint on how to debug this ?

Yes, I looked at it couple days ago, and I could see where the problem is,
but I didn't have time to fix it. The problem is somewhere in
iclass/frame, how it calls the C functions, but I need to explore it more.
The simplest way to debug this (for me) is using debugger integrated into
qtcreator (you need to import grass as a project there). First you run
g.gui.iclass, then in qtcreator you attach this external process and then
do the actions in gui and the debugger shows you the place where it
crashes.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by mlennert):

Replying to [comment:2 annakrat]:
> Replying to [comment:1 mlennert]:
> > Replying to [ticket:3429 mlennert]:
> > > * define group
> > > * define classes
> > > * digitize a few training areas
> > > * save training areas to vector map
> > > * close g.gui.iclass
> > > * reopen g.gui.iclass
> > > * import saved vector maps
> > > => segfault
> >
> > I still have this problem. Can anyone reproduce ? Does anyone have a
hint on how to debug this ?
>
> Yes, I looked at it couple days ago, and I could see where the problem
is, but I didn't have time to fix it. The problem is somewhere in
iclass/frame, how it calls the C functions, but I need to explore it more.
The simplest way to debug this (for me) is using debugger integrated into
qtcreator (you need to import grass as a project there). First you run
g.gui.iclass, then in qtcreator you attach this external process and then
do the actions in gui and the debugger shows you the place where it
crashes.
>

Thanks for the hint, but I have been pulling my hair out trying to make
this work. On my machine, as soon as I attach to the process, the
g.gui.iclass window blanks out completely and I cannot do anything. As
soon as I detach the debugger from the process, I can again see the GUI
window as expected and work with it. This makes it difficult to "do the
action"...

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by annakrat):

I have just been looking at this, but since I have to leave right now,
this is where I got. I don't understand how the temporary maps work, so
it's hard to say what consequences this has, but please test.

{{{
Index: Vlib/open.c

--- Vlib/open.c (revision 71523)
+++ Vlib/open.c (working copy)
@@ -960,7 +960,7 @@
      }
      G_debug(1, "Vect_open_tmp_new(): name = '%s' with_z = %d", name,
with_z);

- return open_new(Map, tmp_name, with_z, TEMPORARY_MAP); /* temporary
map */
+ return open_new(Map, tmp_name, with_z, TEMPORARY_MAP_ENV); /*
temporary map */
  }

}}}
{{{
Index: gui/wxpython/iclass/frame.py

--- gui/wxpython/iclass/frame.py (revision 71523)
+++ gui/wxpython/iclass/frame.py (working copy)
@@ -624,7 +624,8 @@
              return

          # copy features to the temporary map
- vname = self._getTempVectorName()
+ #vname = self._getTempVectorName()
+ vname = self.trainingAreaVector
          # avoid deleting temporary map
          os.environ['GRASS_VECTOR_TEMPORARY'] = '1'
          if digitClass.CopyMap(vname, tmp=True) == -1:
}}}

For the debugging, you need to (after attaching the process) press
Continue to release the gui, then do things in gui and it then jumps in
qtcreator to segfaults or breakpoints.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by mlennert):

Replying to [comment:4 annakrat]:
> I have just been looking at this, but since I have to leave right now,
this is where I got. I don't understand how the temporary maps work, so
it's hard to say what consequences this has, but please test.

Martin: as you introduced the whole notion of temporary vector maps, maybe
you can explain ?

>
> {{{
> Index: Vlib/open.c
> ===================================================================
> --- Vlib/open.c (revision 71523)
> +++ Vlib/open.c (working copy)
> @@ -960,7 +960,7 @@
> }
> G_debug(1, "Vect_open_tmp_new(): name = '%s' with_z = %d", name,
with_z);
>
> - return open_new(Map, tmp_name, with_z, TEMPORARY_MAP); /* temporary
map */
> + return open_new(Map, tmp_name, with_z, TEMPORARY_MAP_ENV); /*
temporary map */
> }
>
> }}}
> {{{
> Index: gui/wxpython/iclass/frame.py
> ===================================================================
> --- gui/wxpython/iclass/frame.py (revision 71523)
> +++ gui/wxpython/iclass/frame.py (working copy)
> @@ -624,7 +624,8 @@
> return
>
> # copy features to the temporary map
> - vname = self._getTempVectorName()
> + #vname = self._getTempVectorName()
> + vname = self.trainingAreaVector
> # avoid deleting temporary map
> os.environ['GRASS_VECTOR_TEMPORARY'] = '1'
> if digitClass.CopyMap(vname, tmp=True) == -1:
> }}}
>

This allows me to open the vector file with the stored polygons. Thanks !
In the terminal, I get messages such as:

{{{
G__open(read): Unable to open
'/home/mlennert/GRASSDATA/nc_spm_08_grass7/user1/.tmp/moritz-
ulb/vector/trAreas325320/frmt': No such file or directory
}}}

> For the debugging, you need to (after attaching the process) press
Continue to release the gui, then do things in gui and it then jumps in
qtcreator to segfaults or breakpoints.

Thanks for the hint ! Now I can get the module to crash, but the debugger
indicates some completely different place in the code. But probably I
don't understand the debugging in qtcreator enough, yet.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by annakrat):

Replying to [comment:5 mlennert]:
> This allows me to open the vector file with the stored polygons. Thanks
!
> In the terminal, I get messages such as:
>
> {{{
> G__open(read): Unable to open
'/home/mlennert/GRASSDATA/nc_spm_08_grass7/user1/.tmp/moritz-
ulb/vector/trAreas325320/frmt': No such file or directory
> }}}
>

I noticed, but they don't seem to actually cause anything so I ignored it
so far, but we should look at it too.

>
> > For the debugging, you need to (after attaching the process) press
Continue to release the gui, then do things in gui and it then jumps in
qtcreator to segfaults or breakpoints.
>
> Thanks for the hint ! Now I can get the module to crash, but the
debugger indicates some completely different place in the code. But
probably I don't understand the debugging in qtcreator enough, yet.

This is more complicated case for debugging than normally since the C
calls are made from the GUI. I think the actual crash happened elsewhere,
but that is just a consequence of a problem happening before. The specific
problem I found was that in function CopyMap in iclass/digit.py the
Vect_close function was deleting the temporary vector (which causes
segfault later on). At this point I don't understand the temporary vectors
enough to fix it properly...

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.1
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by mlennert):

Trying this with current trunk, just aopplying the first part of the
patch, i.e.

{{{

Index: Vlib/open.c

--- Vlib/open.c (revision 71523)
+++ Vlib/open.c (working copy)
@@ -960,7 +960,7 @@
      }
      G_debug(1, "Vect_open_tmp_new(): name = '%s' with_z = %d", name,
with_z);

- return open_new(Map, tmp_name, with_z, TEMPORARY_MAP); /* temporary
map */
+ return open_new(Map, tmp_name, with_z, TEMPORARY_MAP_ENV); /*
temporary map */
  }
}}}

does the trick for me.

Anna, do you remember what the second part (in frame.py) was for ?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.4.1
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------

Comment (by annakrat):

Not specifically, but I remember it was needed. The problem was I don't
know what that change in Vlib would cause or where elsewhere it is used.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

Any chance this fix (if it works) could also fix what seems to be a similar issue in the digitizer?

Michael


C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Head, Graduate Faculty in Complex Adaptive Systems Science
Arizona State University

voice: 480-965-6262 (SHESC), 480-965-8130/727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)

www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu

On Mar 21, 2018, at 7:00 AM, GRASS GIS <trac@osgeo.org> wrote:

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------±-----------------------------------------
Reporter: mlennert | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 7.4.1
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: g.gui.iclass import segfault
CPU: Unspecified | Platform: Unspecified
--------------------------±-----------------------------------------

Comment (by mlennert):

Trying this with current trunk, just aopplying the first part of the
patch, i.e.

{{{

Index: Vlib/open.c

— Vlib/open.c (revision 71523)
+++ Vlib/open.c (working copy)
@@ -960,7 +960,7 @@
}
G_debug(1, “Vect_open_tmp_new(): name = ‘%s’ with_z = %d”, name,
with_z);

  • return open_new(Map, tmp_name, with_z, TEMPORARY_MAP); /* temporary
    map */
  • return open_new(Map, tmp_name, with_z, TEMPORARY_MAP_ENV); /*
    temporary map */
    }
    }}}

does the trick for me.

Anna, do you remember what the second part (in frame.py) was for ?


Ticket URL: <https://urldefense.proofpoint.com/v2/url?u=https-3A__trac.osgeo.org_grass_ticket_3429-23comment-3A8&d=DwIGaQ&c=l45AxH-kUV29SRQusp9vYR0n1GycN4_2jInuKy6zbqQ&r=lk-7X7CEOMDN8GaGVhiDsuO6gEp1wbG6nfT1XEEEtR0&m=oZK0xrkJDs8oPFEjZ-yWn9qL0v3BUh-PkDIkacJhiOo&s=sxT_T5cyOjnZ7qj5B3DoCJt6j4Ar3V4RJoDu3slAHes&e=>
GRASS GIS <https://urldefense.proofpoint.com/v2/url?u=https-3A__grass.osgeo.org&d=DwIGaQ&c=l45AxH-kUV29SRQusp9vYR0n1GycN4_2jInuKy6zbqQ&r=lk-7X7CEOMDN8GaGVhiDsuO6gEp1wbG6nfT1XEEEtR0&m=oZK0xrkJDs8oPFEjZ-yWn9qL0v3BUh-PkDIkacJhiOo&s=_geIvQy40SIKnrzAjxnAYONOQxWTFq7rnSh0ZiLUFuo&e=>

#3429: g.gui.iclass: segfault when loading vector layer
--------------------------+------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.4.5
Component: wxGUI | Version: svn-trunk
Resolution: duplicate | Keywords: g.gui.iclass import segfault
       CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------
Changes (by mlennert):

* status: new => closed
* resolution: => duplicate

Comment:

Follow-up in https://github.com/OSGeo/grass/issues/1019, so closing this
ticket.

PR available in https://github.com/OSGeo/grass/pull/1020

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3429#comment:14&gt;
GRASS GIS <https://grass.osgeo.org>