How to Fix Out of Memory Errors in AutoRemesher: Practical Solutions for High-Resolution Meshes

Reduce the target triangle count, disable adaptivity, and limit TBB threads to prevent AutoRemesher from exhausting system RAM during mesh processing.

AutoRemesher, the open-source automatic remeshing tool from the huxingyi/autoremesher repository, can trigger Out of Memory errors when processing dense meshes or using default parameters that generate excessive intermediate data structures. When the application attempts to allocate more memory than your system provides—often during voxel computation or parallel island processing—it crashes without completing the remesh operation. This guide explains the root causes of these memory spikes and provides concrete runtime fixes and source-level modifications to keep processing within safe limits.

Why AutoRemesher Consumes Excessive Memory

AutoRemesher exhausts RAM during specific pipeline stages that create large temporary data structures. According to the source code in src/AutoRemesher/autoremesher.cpp, these are the primary memory bottlenecks:

Voxel-size computation in initializeVoxelSize() calculates edge lengths based on your target triangle count. Setting this value too high creates tiny voxels, resulting in dense resampling that balloons vertex and face arrays beyond available capacity.

Island splitting via MeshSeparator::splitToIslands() creates separate data sets for each disconnected mesh component. Meshes with many islands generate hundreds of temporary vertex and face copies before parallel processing even begins.

Isotropic resampling in IsotropicRemesher::remesh() (located in src/AutoRemesher/isotropicremesher.cpp) constructs a half-edge representation (IsotropicHalfedgeMesh) that temporarily stores twice the mesh size in vertices, edges, and faces. For million-polygon meshes, this duplication alone can consume gigabytes of RAM.

Curvature-based adaptivity inside AutoRemesher::resample() allocates a std::vector<double> named vertexTargetLengths sized to the vertex count. When multiplied across multiple islands and processed concurrently by Intel TBB threads, this can allocate tens of millions of doubles simultaneously, multiplying peak memory usage by the number of active threads.

Quick Runtime Fixes to Prevent OOM Errors

Before modifying source code, apply these configuration changes to reduce AutoRemesher's memory footprint immediately.

Lower the Target Triangle Count

Reduce the Target Triangle Count in the UI from its default of 200,000, or manually set a larger Target Edge Length (m_targetEdgeLength). Fewer voxels directly translates to smaller intermediate mesh structures during the remeshing phase.

Disable Adaptivity

Uncheck the Adaptivity option or set its value to 0 in the UI. This skips the curvature-based vertexTargetLengths allocation around lines 61-89 of autoremesher.cpp, completely eliminating the per-vertex curvature vector that consumes substantial memory on high-density meshes.

Limit TBB Threads

Export the environment variable TBB_NUM_THREADS to constrain parallel processing before launching:

export TBB_NUM_THREADS=2 && ./autoremesher

This restricts the number of concurrent island copies, preventing the memory multiplication effect described in the parallelism stage. Alternatively, enforce this programmatically in src/main.cpp:

#include <oneapi/tbb/global_control.h>

int main(int argc, char *argv[])
{
    tbb::global_control gc(tbb::global_control::max_allowed_parallelism, 2);
    // Application initialization continues...
}

Build and Run Release Binaries

Compile with CONFIG+=release (Qt) or -DCMAKE_BUILD_TYPE=Release to skip debug checks and reduce runtime overhead. Ensure you use 64-bit binaries to avoid the 4 GB memory cap inherent to 32-bit builds.

Source-Level Modifications for Memory-Constrained Environments

When runtime adjustments prove insufficient, modify these specific locations in the huxingyi/autoremesher codebase to enforce hard memory limits.

Cap Vertex Target Lengths Allocation

In src/AutoRemesher/autoremesher.cpp, wrap the vertexTargetLengths allocation (around line 65) with a safety check:

// Inside AutoRemesher::resample()
if (avgCurvature > 0.0) {
    const size_t maxVertices = 5'000'000; // Safety cap
    if (vertices.size() > maxVertices) {
        qWarning() << "Vertex count exceeds safe limit; adaptivity disabled.";
    } else {
        vertexTargetLengths.resize(vertices.size());
        // Existing parallel loop remains unchanged
    }
}

This prevents the allocation of massive std::vector<double> instances when processing extremely dense meshes.

Restrict Internal Parallelism

Insert a global TBB controller before the first parallel_for call in src/AutoRemesher/autoremesher.cpp (around line 43):

tbb::global_control gc(tbb::global_control::max_allowed_parallelism, 2);

This enforces the thread limit regardless of environment variables, ensuring the program never spawns more than two concurrent island workers.

Skip Half-Edge Construction for Large Islands

In src/AutoRemesher/isotropicremesher.cpp, add an early exit to prevent the construction of memory-intensive half-edge structures:

// Inside IsotropicRemesher::remesh()
if (m_vertices.size() > 10'000'000) {
    qWarning() << "Huge island - skipping half-edge construction.";
    return false; // Fall back to simpler processing
}

The IsotropicHalfedgeMesh (lines 47-64) represents the largest temporary structure in the pipeline. This check forces the algorithm to fall back to a lower-memory path for gigantic islands.

Key Source Files Reference

Understanding these files helps you locate the functions mentioned above:

Summary

  • Reduce target complexity: Lower the triangle count or increase edge length to minimize voxel density
  • Disable adaptivity: Set adaptivity to 0 to eliminate the vertexTargetLengths allocation
  • Limit concurrency: Use TBB_NUM_THREADS=2 or tbb::global_control to cap parallel island processing
  • Build optimized: Always use Release mode and 64-bit binaries
  • Implement safety caps: Modify autoremesher.cpp and isotropicremesher.cpp to skip heavy allocations when vertex counts exceed safe thresholds

Frequently Asked Questions

What causes Out of Memory errors in AutoRemesher?

Out of Memory errors occur when AutoRemesher attempts to allocate more RAM than available while creating intermediate data structures. The primary culprits are the half-edge mesh construction in IsotropicRemesher::remesh(), the per-vertex curvature vectors allocated in resample(), and simultaneous processing of multiple islands via TBB threads that multiply memory usage by the thread count.

Can I fix memory issues without recompiling the source code?

Yes. You can reduce the Target Triangle Count in the UI, disable the Adaptivity feature, and limit TBB threads using the TBB_NUM_THREADS environment variable. Building and running a Release version of the binary also reduces overhead without requiring code modifications.

Why does the half-edge mesh use so much memory?

The IsotropicHalfedgeMesh structure temporarily stores vertices, edges, and faces simultaneously during the isotropic remeshing phase, effectively holding twice the mesh data in memory. For islands exceeding millions of vertices, this duplication can consume several gigabytes of RAM before the algorithm releases the temporary structures.

Is there a maximum mesh size AutoRemesher can handle?

The practical limit depends on your system's RAM and the specific mesh topology. By applying the source-level caps recommended in this guide—such as skipping half-edge construction for islands larger than 10 million vertices—you can process larger meshes that would otherwise trigger OOM errors, though extremely dense geometry may require manual pre-splitting into smaller components.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →