rtabmap icon indicating copy to clipboard operation
rtabmap copied to clipboard

iOS: Crash when `Maximum Output Textures` > 1 during textured mesh creation

Open zeitlerv opened this issue 6 months ago • 1 comments

Description
When Settings → Assembling → Maximum Output Textures is increased above the default value of 1, the application immediately crashes as soon as a textured mesh is generated. This occurs regardless of the chosen texture size, and happens more quickly with smaller sizes (since fewer images fit into a single atlas). It appears to be triggered when RTAB-Map cannot pack all source images into one file without resizing.

To Reproduce

  1. Launch RTAB-Map.
  2. Go to Settings → Assembling.
  3. Change Maximum Output Textures from 1 to 2 (or any value > 1).
  4. Close the settings dialog and start a new mapping/mesh session.
  5. Perform a scan and proceed to mesh creation with texturing enabled.
  6. Observe that the application terminates immediately.

Stack Trace / Error Log

State: STATE_VISUALIZING
[FATAL] {8309376320} (2025-06-16 16:07:34.586) DBDriverSqlite3.cpp:5546::loadOptimizedMeshQuery() Condition (int(serializedTexCoords.at<float>(t)) > 0) not met!
libc++abi: terminating due to uncaught exception of type UException: [FATAL] {8309376320} (2025-06-16 16:07:34.586) DBDriverSqlite3.cpp:5546::loadOptimizedMeshQuery() Condition (int(serializedTexCoords.at<float>(t)) > 0) not met!
terminating due to uncaught exception of type UException: [FATAL] {8309376320} (2025-06-16 16:07:34.586) DBDriverSqlite3.cpp:5546::loadOptimizedMeshQuery() Condition (int(serializedTexCoords.at<float>(t)) > 0) not met!

zeitlerv avatar Jun 16 '25 14:06 zeitlerv

I fixed the fatal error above in https://github.com/introlab/rtabmap/commit/0536ddf0c9699c985ae6747c0fb70759be797d2a. However, when testing with 8092x8092, max 8 textures, I got this error:

[ERROR] {6096908288} (2025-06-17 20:27:55.105) RTABMapApp.cpp:4174::exportMesh() Out of memory! OpenCV(4.11.0) ~/workspace/rtabmap/app/ios/RTABMapApp/Libraries/opencv/modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 805306368 bytes in function 'OutOfMemoryError'

The problem is that it is still allocating the whole memory of all textures before saving them on drive, 805MB (roughly 4x 8092x8092 BGR images), which busted the RAM remaining on the device. Exporting 4x 4096x4096 textures worked though.

Current workaround would be to export from the Desktop version instead (assuming a computer with more RAM), which also gives no limitation to number of texture images we can export.

The actual fix would be to optimize the RAM usage of the app:

  1. Add option to clear clouds/meshes not shown in visualization mode. The idea is to give as much RAM as possible to Assemble.
  2. When creating multiple textures, save them incrementally to database instead of all at the same time, so we don't need to keep them all in RAM till we save to drive.

matlabbe avatar Jun 18 '25 03:06 matlabbe