Skip to content

fix(NodeDB): repair the USERPREFS_FIXED_GPS build path - #11434

Draft
h3lix1 wants to merge 1 commit into
meshtastic:developfrom
h3lix1:fix/userprefs-fixed-gps-build
Draft

fix(NodeDB): repair the USERPREFS_FIXED_GPS build path#11434
h3lix1 wants to merge 1 commit into
meshtastic:developfrom
h3lix1:fix/userprefs-fixed-gps-build

Conversation

@h3lix1

@h3lix1 h3lix1 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

The USERPREFS_FIXED_GPS block in the NodeDB constructor has two defects:

  1. It does not compile. nodePositions[info->num] references info, which is not declared in that scope — no local, no member, no global. Any vendor build setting USERPREFS_FIXED_GPS + _LAT + _LON fails with 'info' was not declared in this scope.
  2. Null pointer on variants where the first line is preprocessed out. The next statement calls nodeDB->setLocalPosition(...) via the global nodeDB, which is null until new NodeDB() returns. Another line in the same constructor already calls the member directly and correctly.

Stock builds are unaffected — no in-tree config sets the flag — but the documented fixed-GPS user-prefs feature is broken as written.

Provenance

Two separate regressions, not one:

Compile-testing this

The block is behind a flag no in-tree config sets, so a normal build does not exercise it:

PLATFORMIO_BUILD_FLAGS='-DUSERPREFS_FIXED_GPS=1 -DUSERPREFS_FIXED_GPS_LAT=48.85873920 -DUSERPREFS_FIXED_GPS_LON=2.294508368 -DUSERPREFS_FIXED_GPS_ALT=0' pio run -e native-macos

Add -DMESHTASTIC_EXCLUDE_POSITIONDB=1 to exercise the STM32WL path instead.

Related issue, not fixed here

This block only fires on reboot_count == 1, when a factory-fresh device still has region == UNSET — so keygen is suppressed and the fixed position is written under the MAC-derived node number. When the user later sets a region, createNewIdentity()removeNodeByNum()eraseNodeSatellites() deletes it, while config.position.fixed_position stays true: fixed-position mode enabled with no coordinates. Not fixable inside this block.

Validation

  • Compile-checked on heltec-v4 (ESP32-S3) against a clean baseline build of the same environment.
  • All 11 fixes from this review merge without conflict and the combined tree compiles on both heltec-v4 and seeed-xiao-s3.
  • Native unit tests were not run locally — the harness is Linux-only (bin/run-tests.sh refuses off-Linux) and bin/test-native-docker.sh needs Docker, which was unavailable on the dev host. Relying on CI for the native suite.
  • No on-hardware validation yet.

Found during an adversarial review of deriving NodeNum from the node public key. Filed as a draft for maintainer judgement.

🤖 Generated with Claude Code


Verified with the flag enabled

The block this fixes is behind USERPREFS_FIXED_GPS, which no in-tree config sets — so an ordinary build never compiles it. Built both trees with the flag to confirm the defect and the fix:

FAIL  review-base (stock)   src/mesh/NodeDB.cpp:641:27: error: 'info' was not declared in this scope
PASS  this branch

Command used (heltec-v4, ESP32-S3):

PLATFORMIO_BUILD_FLAGS='-DUSERPREFS_FIXED_GPS=1 -DUSERPREFS_FIXED_GPS_LAT=48.85873920 -DUSERPREFS_FIXED_GPS_LON=2.294508368 -DUSERPREFS_FIXED_GPS_ALT=0' pio run -e heltec-v4

The second defect (the null global nodeDB on MESHTASTIC_EXCLUDE_POSITIONDB variants) is not reachable on this target and remains verified by inspection.

The USERPREFS_FIXED_GPS block in NodeDB::NodeDB() carried two defects. No
in-tree config sets the flag (all four USERPREFS_FIXED_GPS* keys are commented
out in userPrefs.jsonc), so stock builds were unaffected and CI never saw it.
Any vendor build that uncomments USERPREFS_FIXED_GPS + _LAT + _LON -
bin/platformio-custom.py turns uncommented keys into -D flags - hit it.

1. `nodePositions[info->num]` referenced an `info` that does not exist in this
   scope. The ctor declares no such local, NodeDB has no `info` member, and
   there is no global or macro by that name: a hard "'info' was not declared in
   this scope" compile error. Replaced with `getNodeNum()`, which is what
   `info->num` resolved to when the line still compiled, and which matches how
   nodePositions is keyed everywhere else (std::map<NodeNum, ...>, NodeDB.h:270).

2. `nodeDB->setLocalPosition(fixedGPS)` dereferenced the global `nodeDB`
   pointer, which stays null until `new NodeDB` returns (main.cpp:856). On
   MESHTASTIC_EXCLUDE_POSITIONDB variants (STM32WL) defect 1 is preprocessed
   out and this became a null-this call on first boot. Replaced with the direct
   member call, matching the fixed-position restore a few lines above.

Provenance: 94bb21e ("2.8: NodeDB shrink, decoupling, and restructuring",
meshtastic#10413) mechanically rewrote `info->position = ...` into
`nodePositions[info->num] = ...`; `info` was still declared in the ctor at that
point, so it still built. 79a7dcc ("Pr1 nodedb warmstore", meshtastic#10705) then moved
`meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getNodeNum())` out of the
ctor into nodeDBSelfCare(), leaving the name dangling. Both are refactor
regressions, not intent. Defect 2 is older still - it arrived with the feature
itself in d4d8944 (meshtastic#5341).

nodeDBSelfCare() runs at NodeDB.cpp:470, well before this block, so our own
lite row already exists by the time we write nodePositions[getNodeNum()].

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 81deafb5-c2fc-4766-8ff7-12148567f5b8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Note

Building this pull request… the flash button, badges and supported-board
list will appear here automatically once CI finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant