Skip to content

Setting TERRAIN_SPACING Too Small Causes Instant Crash Instead of Running Out of Storage #29392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wyunc opened this issue Feb 27, 2025 · 4 comments · May be fixed by #29653
Open

Setting TERRAIN_SPACING Too Small Causes Instant Crash Instead of Running Out of Storage #29392

wyunc opened this issue Feb 27, 2025 · 4 comments · May be fixed by #29653

Comments

@wyunc
Copy link

wyunc commented Feb 27, 2025

Bug report

Issue details
Hi~
When the parameter TERRAIN_SPACING is set to a value less than 1, the system crashes, causing the GCS to lose connection.
For example, param set TERRAIN_SPACING 0 or param set TERRAIN_SPACING 0.5
(But there are no errors when TERRAIN_SPACING =1 or 1.5)

According to the parameter description:
"Grid spacings lower than 100 meters waste SD card space if the GCS cannot provide that resolution."

If the value is set below 100, it should only result in wasted storage space (eventually leading to an SD card running out of space), but it should not cause an instant crash. Therefore, I think this is a bug.

The error message from debugging is as follows:
Thread 1 "arducopter" received signal SIGFPE, Arithmetic exception.
0x00005555556979a4 in AP_Terrain::calculate_grid_info(Location const&, AP_Terrain::grid_info&) const ()

Version
SITL, copter, 4.7.0-dev

Platform
[ ] All
[ ] AntennaTracker
[*] Copter
[ ] Plane
[ ] Rover
[ ] Submarine

@peterbarker
Copy link
Contributor

This is an integer parameter. It's being truncated to zero, leading to division-by-zero.

You really want sub-metre accuracy?

@rmackay9
Copy link
Contributor

rmackay9 commented Feb 27, 2025

Maybe we should protect against unrealistically small values especially if they can cause problems on a real vehicle

@wyunc
Copy link
Author

wyunc commented Feb 28, 2025

Thank you @peterbarker and @rmackay9 ,
In my opinion, if you want to fly indoors (within a 50-square-meter area), setting the grid resolution to sub-meter might be a reasonable approach. I tend to agree with what @rmackay9 suggested — it would be best to prevent this situation from happening.

I think the simplest solution would be to add a constraint in the code, so that when the grid resolution is set to less than 1, it defaults to 1. Alternatively, we could add a note in the documentation stating: "Do not set TERRAIN_SPACING to less than 1."

Another option could be to enhance support for sub-meter resolution, though I'm not entirely sure if that's necessary.

@tiagoc-santos
Copy link

Hi. I'm interested in this issue. Is someone already working on a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants