@@ -16471,6 +16471,23 @@ dry_run: if (opt_R == NULL) { /* In this context we imply -Rd unless grdcut -S
1647116471 API->GMT->hidden.func_level++; /* Must do this here in case gmt_parse_R_option calls mapproject */
1647216472 if (!parsed_R) gmt_parse_R_option (GMT, opt_R->arg);
1647316473 API->GMT->hidden.func_level = level; /* Reset to what it should be */
16474+ /* Issue #6463: If -R<x>/<x>/<y>/<y>+u<unit> was given, rewrite opt_R->arg to the equivalent
16475+ * geographic LL/UR form -R<LL_lon>/<LL_lat>/<UR_lon>/<UR_lat>+r. The +u parsing path invokes
16476+ * mapproject as a sub-module to invert projected coords; a second invocation (during the
16477+ * module's own GMT_Parse_Common) inherits the parent's now-populated current.proj and yields
16478+ * a wrong inverse. The +r path needs no sub-mapproject call so it is immune. R.wesn already
16479+ * holds the correct LL/UR corners at this point. */
16480+ if (!parsed_R && GMT->common.R.oblique) {
16481+ char *u_pos = strstr(opt_R->arg, "+u");
16482+ if (u_pos && strchr(GMT_LEN_UNITS2, u_pos[2])) {
16483+ char new_arg[GMT_LEN256] = {""}, *rest = u_pos + 3; /* Skip past "+u<unit>" */
16484+ snprintf(new_arg, GMT_LEN256, "%.16g/%.16g/%.16g/%.16g+r%s", GMT->common.R.wesn[XLO], GMT->common.R.wesn[YLO],
16485+ GMT->common.R.wesn[XHI], GMT->common.R.wesn[YHI], rest);
16486+ GMT_Report(API, GMT_MSG_DEBUG, "Replace -R%s with -R%s to avoid projection-dependent re-parse [#6463]\n", opt_R->arg, new_arg);
16487+ gmt_M_str_free(opt_R->arg);
16488+ opt_R->arg = strdup(new_arg);
16489+ }
16490+ }
1647416491 if (GMT->common.R.oblique || GMT->current.proj.projection == GMT_OBLIQUE_MERC || GMT->current.proj.projection == GMT_GENPER) {
1647516492 int s_error = GMT_NOERROR; /* Error code for various calls */
1647616493 const char *prev_name = GMT->init.module_name; /* Remember calling module */
0 commit comments