Skip to content

grdfilter crashes in pygmt if GMT_IN is used  #4577

Closed

Description

@seisman

Currently, PyGMT opens virtual files using GMT_IN|GMT_IS_REFERENCE, and the following script works well:

import pygmt
grid = pygmt.datasets.load_earth_relief()
smooth_field = pygmt.grdfilter(grid=grid, filter="g600", distance="4")

However, if PyGMT uses GMT_IN, the above script crashes:

grdfilter [ERROR]: G->data is not NULL when memory allocation is about to happen
[Session pygmt-session (3)]: Error returned from GMT API: GMT_PTR_IS_NULL (75)
[Session pygmt-session (3)]: Error returned from GMT API: GMT_PTR_IS_NULL (75)
[Session pygmt-session (3)]: Error returned from GMT API: GMT_OBJECT_NOT_FOUND (60)

...

GMTCLibError: Failed to close virtual file '@GMTAPI@-S-I-G-M-G-N-000000'.

To reproduce the issue, please update your pygmt repository, checkout this PR (GenericMappingTools/pygmt#517), and run the above script.

It crashes with GMT 6.1.1 and GMT master, but it might work for old versions.

Activity

  1. added
    bug
    on Dec 16, 2020
  2. PaulWessel commented on Dec 19, 2020

    @PaulWessel
    Contributor

    That I do PyGMT debugging (too) infrequently is perhaps good since it clearly points out lack of clear instructions on our debug page... These are the steps I took (I already had pygmt checked out from the repo before):

    1. I pulled the latest to get all updates since last pull, then switched to the gmt-in branch.
    2. I ran conda activate pygmt
    3. I did export GMT_SHAREDIR=/Users/pwessel/GMTdev/gmt-dev/dbuild so that it points to a dir with share in it.
    4. I already had GMT_LIBRARY_PATH set to point to the xcode-built library /Users/pwessel/GMTdev/gmt-dev/xbuild/src/Debug
    5. I start python in the terminal
    6. I attach Xcode to the python process
    7. I set a stop point in GMT_Call_Module
    8. I copy/paste the three lines in the script above, one by one.

    It reproduces the crash but did not stop in Xcode. Am I missing a "build or install" type step for pyGMT above?

  3. seisman commented on Dec 19, 2020

    @seisman
    MemberAuthor

    I don't see anything wrong.

  4. PaulWessel commented on Dec 19, 2020

    @PaulWessel
    Contributor

    OK, will rebuild the xcode debug and start from the top.

  5. PaulWessel commented on Dec 19, 2020

    @PaulWessel
    Contributor

    OK, I rebuilt but also selected target libgmt in Xcode and stop point in GMT_Call_Module. That is probably better since gmt.c is not involved.
    GMT_Read_Data gets to the case GMT_IS_DUPLICATE|GMT_VIA_MATRIX and not GMT_IS_REFERENCE. So not sure where it switches since you said this branch passes GMT_IN.
    Anyway, looks like we call GMT_Create_Data for the grid to allocate memory for data and then later complain taht data is allocated. Seems like a simple fix - will apply and check.

  6. PaulWessel commented on Dec 19, 2020

    @PaulWessel
    Contributor

    Hm, after passing mode = GMT_CONTAINER_ONLY to GMT_Create_Data for the grid, the grid still has a non-zero data pointer. OK, so need to go deeper.

  7. added a commit that references this issue on Dec 19, 2020
    a22cdba
  8. added a commit that references this issue on Dec 20, 2020
    61e6aea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions