Skip to content

plot crashes when plotting arrows  #406

Closed

Description

@seisman

Description of the problem

I'm trying to plot two vectors using the following script. It works well if pen is set to 1p,black (i.e. a simple line), but crashes if set to 1p,black+ve0.2c. Actually, the first plot works, but the second one crashes.

Full code that generated the error

import pygmt
import numpy as np

fig = pygmt.Figure()
fig.basemap(projection="X15c/10c", region="400/600/5/8", frame=True)
fig.plot(x=[530.0, 530.0], y=[6.0, 7.0], pen='1p,black+ve0.2c')
fig.plot(x=[570.0, 570.0], y=[6.0, 7.0], pen='1p,black+ve0.2c')
fig.savefig("map.pdf")

Full error message

python(64354,0x11ac3bdc0) malloc: *** error for object 0x7f8f28e50900: pointer being freed was not allocated
python(64354,0x11ac3bdc0) malloc: *** set a breakpoint in malloc_error_break to debug
[1]    64354 abort      python test.py

System information

  • Operating system: macOS
  • Python installation (Anaconda, system, ETS): Anaconda
  • Version of GMT: 6.1.0_e6eb3b9_2020.03.30
  • Version of Python: 3.7.4
  • Version of this package: 0.0.1a0+75.g088b0d1
  • If using conda, paste the output of conda list below:
output of conda list
PASTE OUTPUT OF CONDA LIST HERE

Activity

  1. changed the title [-]pygmt crashes when plotting vectors[/-] [+]plot crashes when plotting vectors[/+] on Mar 30, 2020
  2. added
    bug
    on Mar 31, 2020
  3. weiji14 commented on Mar 31, 2020

    @weiji14
    Member

    I can reproduce the same crash, with GMT 6.0 on Linux and using the pygmt master branch. The corresponding code in GMT works though:

    gmt begin test png
    gmt basemap -JX15c/10c -R400/600/5/8 -B
    gmt plot -W1p,black+ve0.2c << EOF
    530.0 6.0
    530.0 7.0
    EOF
    gmt plot -W1p,black+ve0.2c << EOF
    570.0 6.0
    570.0 7.0
    EOF
    gmt end show

    produces:

    two vertical lines plotted successfully using gmt

    Not much of a clue as to why it's crashing though 🤷‍♂️

  4. d-murashkin commented on May 8, 2020

    @d-murashkin

    Also crushes on the second plot, but
    does not crush if integer values are used.
    That is

    import pygmt
    import numpy as np
    
    fig = pygmt.Figure()
    fig.basemap(projection="X15c/10c", region="400/600/5/8", frame=True)
    fig.plot(x=[530, 530], y=[6.0, 7.0], pen='1p,black+ve0.2c')
    fig.plot(x=[570, 570], y=[6.0, 7.0], pen='1p,black+ve0.2c')
    fig.savefig("map.pdf")

    works fine

    fig.plot(x=[530, 530], y=[6.0, 7.0], pen='1p,black+ve0.2c')
    fig.plot(x=[570.0, 570.0], y=[6.0, 7.0], pen='1p,black+ve0.2c')

    also works fine

    fig.plot(x=[530.0, 530.0], y=[6.0, 7.0], pen='1p,black+ve0.2c')
    fig.plot(x=[570, 570], y=[6.0, 7.0], pen='1p,black+ve0.2c')

    does not work

    Seems like the issue is related to floating point numbers,
    also the data for later plots is converted to the data type of the first plot.

  5. d-murashkin commented on May 8, 2020

    @d-murashkin

    I might have found a solution:
    convert all floating point numbers to float32 (float64 is default)
    The following works with no error:

    import pygmt
    import numpy as np
    
    fig = pygmt.Figure()
    fig.basemap(projection="X15c/10c", region="400/600/5/8", frame=True)
    fig.plot(x=[np.float32(530.0), np.float32(530.0)], y=[6.0, 7.0], pen='1p,black+ve0.2c')
    fig.plot(x=[np.float32(570.0), np.float32(570.0)], y=[6.0, 7.0], pen='1p,black+ve0.2c')
    fig.savefig("map.pdf")

    Could it be that GMT does not have good support for float64 and uses float32 by default?
    Anyway, for plotting float64 values are probably not needed, so all float64 data should probably converted to float32 in the wrapper.

  6. changed the title [-]plot crashes when plotting vectors[/-] [+]plot crashes when plotting arrows [/+] on Jun 24, 2020
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