Skip to content

Figure.solar crashes on Linux when drawing nautical terminator for 2024-04-16T06:00:00 #2959

Closed

Description

@astro-jingtao

Description of the problem

When I try to draw nautical terminator for year=2024, month=4, day=16, hour=6, minute=0, second=0, I got

malloc(): invalid size (unsorted)
Aborted (core dumped)

There is no problem to draw it for other time, such as year=2024, month=4, day=16, hour=6, minute=1, second=0

Minimal Complete Verifiable Example

import datetime
import pygmt

fig = pygmt.Figure()
fig.coast(region="d", projection="W0/15c", land="darkgreen", water="lightblue")

terminator_datetime = datetime.datetime(year=2024,
                                        month=4,
                                        day=16,
                                        hour=6,
                                        minute=0,
                                        second=0)

fig.solar(
    terminator="nautical",
    terminator_datetime=terminator_datetime,
    fill="blue@90",
    pen="0.5p",
)

fig.savefig("demo.png")

Full error message

malloc(): invalid size (unsorted)
Aborted (core dumped)

System information

PyGMT information:
  version: v0.10.0
System information:
  python: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]
  executable: /home/{my_user_name}/software/anaconda3/envs/pygmt/bin/python
  machine: Linux-4.18.0-477.13.1.el8_8.x86_64-x86_64-with-glibc2.28
Dependency information:
  numpy: 1.26.3
  pandas: 2.1.4
  xarray: 2023.12.0
  netCDF4: 1.6.5
  packaging: 23.2
  contextily: None
  geopandas: None
  IPython: 8.19.0
  rioxarray: None
  ghostscript: 9.56.1
GMT library information:
  binary version: 6.4.0
  cores: 80
  grid layout: rows
  image layout: 
  library path: /work/{my_user_name}/anaconda3/envs/pygmt/lib/libgmt.so
  padding: 2
  plugin dir: /work/{my_user_name}/anaconda3/envs/pygmt/lib/gmt/plugins
  share dir: /home/{my_user_name}/software/anaconda3/envs/pygmt/share/gmt
  version: 6.4.0

Activity

  1. added
    bug
    on Jan 6, 2024
  2. welcome commented on Jan 6, 2024

    @welcome

    👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

  3. seisman commented on Jan 6, 2024

    @seisman
    Member

    It works well for me, but I'm using macOS. Could you please add verbose="d" to the Figure.solar method and post the debugging messages?

  4. yvonnefroehlich commented on Jan 6, 2024

    @yvonnefroehlich
    Member

    For me, it fails under Linux as reported, but it works under Windows.

    Output of verbose="d":

    solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
    solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
    solar [DEBUG]: Reset MAP_ANNOT_OBLIQUE to anywhere
    solar [DEBUG]: Projected values in meters: -1.80199e+07 1.80199e+07 -9.00996e+06 9.00996e+06
    solar [DEBUG]: Computed automatic parameters using dimension scaling: 0.908088
    solar [INFORMATION]: Map scale is 2402.66 km per cm or 1:2.40266e+08.
    solar [DEBUG]: Running in PS mode modern
    solar [DEBUG]: Use PS filename /home/yfroe/.gmt/sessions/gmt_session.28939/gmt_4.ps-
    solar [DEBUG]: Append to hidden PS file /home/yfroe/.gmt/sessions/gmt_session.28939/gmt_4.ps-
    solar [DEBUG]: Got session name as pygmt-session and default graphics formats as pdf
    solar [DEBUG]: Basemap order: Frame = above  Grid = above  Tick/Annot = above
    solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-90.9771
    solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-89.0292
    solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -4.54747e-13 Polygon contains south (CW) pole.
    solar [INFORMATION]: Plot small circle with pole at 89.9773/10.0419 and radius 102 degrees
    solar [DEBUG]: Polar cap: 1
    solar [DEBUG]: Try to include S pole in polar cap path
    solar [DEBUG]: West longitude = -180.  East longitude = 180
    solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -4.54747e-13 Polygon contains south (CW) pole.
    solar [DEBUG]: First longitude = 89.9773.  Last longitude = 89.9773
    solar [DEBUG]: Crossing at -180,-90
    solar [DEBUG]: k at point closest to lon -180 is = 0 [n = 363]
    solar [DEBUG]: Created path from 180/-90 to 180/-90 [0 points]
    solar [DEBUG]: Add perimeter data from k0->n [0->363], then 0->k0 [0]
    solar [DEBUG]: Add path from -180/-90 to -180/-90 [0 points]
    solar [DEBUG]: New path has 364 points, we allocated 363 points
    malloc(): invalid size (unsorted)
    
    
    Fatal Python error: Aborted
    
  5. yvonnefroehlich commented on Jan 6, 2024

    @yvonnefroehlich
    Member

    It looks like the issue is related to the fill parameter. If specifying a fill color via fill the code fails, but it works if not using fill or fill=None [Default]. The "problematic" date part seems to be hour=6, minute=0.

    import datetime
    import pygmt
    
    term_datetime = datetime.datetime(
        year=2024,
        month=4,
        day=16,
        hour=6,
        minute=0,  # fails with a fill color
        # minute=1,  # works with a fill color
        second=0,
    )
    print(term_datetime)
    
    fig = pygmt.Figure()
    fig.coast(region="d", projection="W10c", shorelines=True, frame=True)
    
    fig.solar(
        terminator="nautical",
        terminator_datetime=term_datetime,
        # fill=None,  # works
        fill="blue",  # fails
        # pen="1p,red,solid",  # works
    )
    
    fig.show()
  6. seisman commented on Jan 6, 2024

    @seisman
    Member

    The equivalent GMT CLI is:

    gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map
    

    Could you please try if it fails for you on Linux?

  7. yvonnefroehlich commented on Jan 6, 2024

    @yvonnefroehlich
    Member

    The equivalent GMT CLI is:

    gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map
    

    Could you please try if it fails for you on Linux?

    Yes, it fails with GMT 6.4 and 6.4.0_965606f_2022.03.14 on Linux.

    (gmt_env_dev) yfroe@gpiseis16:~> gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map
    malloc(): invalid size (unsorted)
    Aborted (core dumped)
    (gmt_env_dev) yfroe@gpiseis16:~> gmt --version
    6.4.0_965606f_2022.03.14
    
  8. astro-jingtao commented on Jan 6, 2024

    @astro-jingtao
    Author

    Output of verbose="d":

    solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
    solar [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
    solar [DEBUG]: Reset MAP_ANNOT_OBLIQUE to anywhere
    solar [DEBUG]: Projected values in meters: -1.80199e+07 1.80199e+07 -9.00996e+06 9.00996e+06
    solar [DEBUG]: Computed automatic parameters using dimension scaling: 0.908088
    solar [INFORMATION]: Map scale is 2402.66 km per cm or 1:2.40266e+08.
    solar [DEBUG]: Running in PS mode modern
    solar [DEBUG]: Use PS filename /home/{my_user_name}/.gmt/sessions/gmt_session.852013/gmt_1.ps-
    solar [DEBUG]: Append to hidden PS file /home/{my_user_name}/.gmt/sessions/gmt_session.852013/gmt_1.ps-
    solar [DEBUG]: Got session name as pygmt-session and default graphics formats as pdf
    solar [DEBUG]: Basemap order: Frame = above  Grid = above  Tick/Annot = above
    solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-90.9758
    solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-89.0332
    solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -1.27898e-13 Polygon contains south (CW) pole.
    solar [INFORMATION]: Plot small circle with pole at 89.9329/10.3111 and radius 102 degrees
    solar [DEBUG]: Polar cap: 1
    solar [DEBUG]: Try to include S pole in polar cap path
    solar [DEBUG]: West longitude = -180.  East longitude = 180
    solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 0  Residual: -1.27898e-13 Polygon contains south (CW) pole.
    solar [DEBUG]: First longitude = 89.9329.  Last longitude = 89.9329
    solar [DEBUG]: Crossing at -180,-90
    solar [DEBUG]: k at point closest to lon -180 is = 0 [n = 363]
    solar [DEBUG]: Created path from 180/-90 to 180/-90 [0 points]
    solar [DEBUG]: Add perimeter data from k0->n [0->363], then 0->k0 [0]
    solar [DEBUG]: Add path from -180/-90 to -180/-90 [0 points]
    solar [DEBUG]: New path has 364 points, we allocated 363 points
    malloc(): invalid size (unsorted)
    Aborted (core dumped)

    Output of

    gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map
    malloc(): invalid size (unsorted)
    Aborted (core dumped)
  9. changed the title [-]Crash when draw nautical terminator for year=2024, month=4, day=16, hour=6, minute=0, second=0[/-] [+]Figure.solar crashes on Linux when drawing nautical terminator for 2024-04-16T06:00:00[/+] on Jan 6, 2024
  10. added
    upstream
    on Jan 6, 2024
  11. seisman commented on Jan 6, 2024

    @seisman
    Member

    It's likely an upstream bug, although I can't test if it has been fixed in the upcoming GMT 6.5.0 release.

    Ping @PaulWessel.

  12. PaulWessel commented on Jan 6, 2024

    @PaulWessel

    6.5 master (i.e., release) on macOS arm64:

    gmt solar -Rd -JW10c -Baf -Tn+d2024-04-16T06:00:00 -Gblue -png map

    map

  13. yvonnefroehlich commented on Jan 6, 2024

    @yvonnefroehlich
    Member

    Thanks @PaulWessel for immediately looking at this. So far, this issue appears to be OS-dependent: it works on Windows and macOS, but it fails on Linux.

  14. PaulWessel commented on Jan 6, 2024

    @PaulWessel

    So we need someone with Linux to run that command in ddd for example and learn what the crash is and why.

  15. seisman commented on Jan 7, 2024

    @seisman
    Member

    It still crashes with GMT master branch. Trying to debug it, and this is the callstack and shows where it crashes:
    Screenshot from 2024-01-07 11-30-52

  16. PaulWessel commented on Jan 7, 2024

    @PaulWessel

    So it SEGVs in line 565? That is a calloc call but the message says malloc? What are the values of Belem and size? The message about size is invalid (unsorted) is strange was size is a scalar, no??

  17. seisman commented on Jan 7, 2024

    @seisman
    Member

    nelem=2048 and size=8.

  18. seisman commented on Jan 7, 2024

    @seisman
    Member

    Does this debug message make sense to you?

    solar [DEBUG]: New path has 364 points, we allocated 363 points
    

    As the OP says, using a slightly different time works:

    $ gmt solar -Rd -JW10c -Tn+d2024-04-16T06:01:00 -Gblue -png map
    solar [DEBUG]: gmt_get_smallcircle: Added extra point at 180/-86.5149
    solar [DEBUG]: gmt_get_smallcircle: Added extra point at 0/-89.0502
    solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 1  Residual: 2.27374e-13 Polygon contains south (CCW) pole.
    solar [INFORMATION]: Plot small circle with pole at 89.6829/10.3113 and radius 102 degrees
    solar [DEBUG]: Polar cap: 1
    solar [DEBUG]: Try to include S pole in polar cap path
    solar [DEBUG]: West longitude = -180.  East longitude = 180
    solar [DEBUG]: gmtlib_determine_pole: N = 363 Multiples of 360: 1  Residual: 2.27374e-13 Polygon contains south (CCW) pole.
    solar [DEBUG]: Make polygon to clockwise
    solar [DEBUG]: First longitude = 89.6829.  Last longitude = 89.6829
    solar [DEBUG]: Crossing at -180,-86.5149
    solar [DEBUG]: k at point closest to lon -180 is = 358 [n = 363]
    solar [DEBUG]: Created path from 180/-90 to 180/-86.5149 [48 points]
    solar [DEBUG]: Add perimeter data from k0->n [358->363], then 0->k0 [358]
    solar [DEBUG]: Add path from -180/-86.5149 to -180/-90 [48 points]
    solar [DEBUG]: New path has 459 points, we allocated 459 points
    
  19. PaulWessel commented on Jan 7, 2024

    @PaulWessel

    Could you try on Linux to change line 9707 in gmt_plot.c to be

    `n_new = 2 * MIN (1, perim_n) + n;`
    

    since perim_n is 0 this is a bit suspect. Does that help?

  20. PaulWessel commented on Jan 7, 2024

    @PaulWessel

    Sorry, MAX of course

  21. seisman commented on Jan 7, 2024

    @seisman
    Member

    Yes, n_new = 2 * MAX (1, perim_n) + n; works.

  22. added this to the 0.11.0 milestone on Jan 7, 2024
  23. seisman commented on Jan 7, 2024

    @seisman
    Member

    The upstream bug has been fixed in the GMT's master branch and the working version GMT 6.5.0 will be released soon.

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

    bugupstream

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions