Standard_DimensionMismatch in Open CASCADE Technology

Diagnostic signature

Standard_DimensionMismatch

An exception raised in Open CASCADE Technology (OCCT) when an operation encounters data structures, such as arrays, vectors, or matrices, with incompatible bounds, sizes, or dimensions.

What it means

In Open CASCADE Technology (OCCT), `Standard_DimensionMismatch` is a runtime exception that indicates a structural size incompatibility between operands. The kernel expects certain collections, such as coordinate arrays, weight arrays, knot vectors, or mathematical matrices, to have strictly matching or algebraically compatible lengths. When a function or operator is invoked with entities that fail these dimensional requirements, OCCT throws this exception to prevent out-of-bounds memory access or mathematically invalid operations.

Why it happens

This exception is typically caused by initializing or operating on geometric and mathematical primitives with mismatched array lengths or sizes. Common scenarios include: 1. Matrix operations (such as `math_Matrix` multiplication or addition) where the row or column dimensions do not align according to linear algebra rules. 2. Constructing curves or surfaces (such as `Geom_BSplineCurve` or `Geom_BSplineSurface`) where the number of provided poles, weights, or knots does not match the expected formula or degree. 3. Array assignments in OCCT collections (like `TColStd_Array1OfReal` or `TColgp_Array1OfPnt`) where the source and destination arrays are initialized with different index bounds.

Minimal reproduction

#include <math_Matrix.hxx>
#include <iostream>
#include <Standard_DimensionMismatch.hxx>

int main() {
    try {
        // Initialize a 2x2 matrix
        math_Matrix A(1, 2, 1, 2);
        // Initialize a 3x3 matrix
        math_Matrix B(1, 3, 1, 3);
        
        // Attempt to add a 3x3 matrix to a 2x2 matrix
        A.Add(B);
    } catch (const Standard_DimensionMismatch& e) {
        std::cerr << "Exception caught: Standard_DimensionMismatch" << std::endl;
        return 1;
    }
    return 0;
}

How to fix it

Ensure that the dimensions of arrays, matrices, or geometric vectors match the requirements of the operation being invoked.

```C++
#include <math_Matrix.hxx>
#include <iostream>
#include <Standard_DimensionMismatch.hxx>

int main() {
    try {
        // Initialize a 2x2 matrix
        math_Matrix A(1, 2, 1, 2);
        // Initialize a second 2x2 matrix to match dimensions
        math_Matrix B(1, 2, 1, 2);
        
        // Addition succeeds because dimensions match
        A.Add(B);
    } catch (const Standard_DimensionMismatch& e) {
        std::cerr << "Exception caught: Standard_DimensionMismatch" << std::endl;
        return 1;
    }
    return 0;
}

```

Step 1

Step 2

Step 3

Upstream references

Open CASCADE Technology OCCT 7.8.0 — Standard_DimensionMismatch.hxx — retrieved 2026-08-11

math_Matrix.hxx - OCCT 7.8.0 Source