You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for your reply. However, when I adjust the z-range in the -R option, for example:
gmt basemap -R1e+17/1e+21/1e+17/1e+21/1e5/1e19 -Jz1cl -BwSEnZ -JX10cl -p130/50 -Bxa1f3p -Bya1f3p -Bza1f3p -png lixo
If I want to plot the z-axis for a different range, such as -R1e+17/1e+21/1e+17/1e+21/1e10/1e19, what should I do?
● There's the bug! Line 740:
return (PSL->internal.y0 + (int)lrint (y * PSL->internal.y2iy));
psl_iy converts to PS dots using int. When y = -1789569 (the y0 passed to PSL_setorigin for the Z-axis), and y2iy is the conversion from inches to PS
dots (typically 1200 dots/inch):
y * y2iy = -1789569 * 1200 = -2,147,482,800
And INT_MAX = 2,147,483,647 (2^31 - 1). So -1789569 * 1200 = -2,147,482,800 — this is just barely within the 32-bit int range.
But for -1789570 * 1200 = -2,147,484,000 — this overflows a 32-bit int! INT_MIN = -2,147,483,648, so -2,147,484,000 < INT_MIN → integer overflow!
The threshold is exactly INT_MAX / 1200 ≈ 1,789,569.7, which matches the reported boundary between working (1789569) and broken (1789570).
Issue #8812: Root Cause
The bug is a 32-bit integer overflow in postscriptlight.c line 740, in the psl_iy() function:
static int psl_iy (struct PSL_CTRL *PSL, double y) {
return (PSL->internal.y0 + (int)lrint (y * PSL->internal.y2iy));
}
When drawing the Z-axis, gmt_xy_axis is called with y0 = -wesn[ZLO] = -1789569 (raw data units). This gets passed to PSL_setorigin(), which calls
psl_iy(-1789569). With y2iy = 1200 dots/inch:
- lrint(-1789569 * 1200) = lrint(-2,147,482,800) — fits in int (barely)
- lrint(-1789570 * 1200) = lrint(-2,147,484,000) — overflows 32-bit int (INT_MIN = -2,147,483,648)
The overflow threshold is exactly 2^31 / 1200 ≈ 1,789,569.7, matching the reported breakpoint perfectly.
Why is a raw data value being passed as inches?
The deeper issue is in gmt_plot.c line 6844:
gmt_xy_axis (GMT, 0.0, -GMT->common.R.wesn[ZLO], ...)
The y0 = -wesn[ZLO] is passed in data units instead of projected/plot units. For the X and Y axes, gmt_xy_axis receives positions in plot inches, but
for the Z-axis (drawn in a concatenated PS matrix space), the raw data value is used. When ZLO is large, this produces a huge translation that overflows
the PostScript integer coordinate system.
The fix
The y0 for the Z-axis should be computed in projected units (inches) rather than raw data units, or the concat matrix on line 6842 should account for
the offset so that y0 doesn't need to carry a huge data value. Alternatively, psl_iy could use int64_t instead of int, though the PostScript output
format (%d) would also need updating.
Activity
joa-quim commentedon Oct 12, 2025
Please don't use issues to ask questions. Use the forum instead.
The problem is related to -R limits not the logarithmic scale. See, no z axis here either.
Xiongwei789 commentedon Oct 13, 2025
Thanks for your reply. However, when I adjust the z-range in the -R option, for example:
gmt basemap -R1e+17/1e+21/1e+17/1e+21/1e5/1e19 -Jz1cl -BwSEnZ -JX10cl -p130/50 -Bxa1f3p -Bya1f3p -Bza1f3p -png lixo
If I want to plot the z-axis for a different range, such as -R1e+17/1e+21/1e+17/1e+21/1e10/1e19, what should I do?
Esteban82 commentedon Oct 13, 2025
Hi @Xiongwei789.
Could you please post your question on the GMT forum? The community there is very active and it’s usually the best place to get detailed help.
Xiongwei789 commentedon Oct 13, 2025
OK. Thank you. I will ask on the GMT forum.
Esteban82 commentedon Oct 13, 2025
@joa-quim I think there is a bug. When the mininum z value is 1789569 is fine. But if I add 1, (so the
zminis 1789570) then I cannot plot the Z axis.I get this figure with the second command:
joa-quim commentedon Oct 13, 2025
Nice example. Even before disappearing the vertical axis starts to float away
joa-quim commentedon Mar 20, 2026
Claude's analysis
An attempt to fix the disappearing -Z-axis issue #8812