Budgets, Lifetimes, and Errors#

This page describes the limits an instance enforces, how operations and objects end, and the status codes that calls return.

Budgets#

The instance holds every limit, and no limit grows on its own. The instance description sets them in these fields:

Field

Meaning

Python Default

operation_capacity

Live operations at once. An operation holds an entry until it is destroyed.

8

max_cpu_concurrency

Asynchronous CPU jobs running at once. More jobs wait in a queue. There is no hidden worker pool.

2

host_byte_budget

Host memory for versions, plans, and results.

64 MiB

device_budgets

One byte budget per CUDA device. No entry means no CUDA work.

none

Work that would exceed a limit is refused when it is submitted, with OPERATION_CAPACITY, RESULT_CAPACITY, HOST_BUDGET, or DEVICE_BUDGET, and changes nothing. An exact CPU query also charges its working memory, which depends on the geometry it reaches, while it runs. A synchronous query that does not fit returns HOST_BUDGET; an asynchronous batch ends with OPERATION_FAILED. ovspatialquery_get_instance_memory_usage() reports what is in use.

The first exact query that reaches a triangle mesh builds the mesh’s query structure. The call that adds the mesh, a registration or a publication, charges the structure’s memory in advance, along with the memory the build needs while it runs. The structure keeps about 32 bytes per triangle and 16 per vertex, and a build needs up to about 192 bytes per triangle more. Meshes not yet built share that build charge, sized for the largest of them. A 131,072-triangle mesh therefore needs about 37 MiB of host budget to register, and about 12 MiB once a query has built it. While it runs, an exact query against a mesh can need 4 bytes per triangle of the mesh, and a sweep through a mesh of more than 4,096 triangles always reserves them: 512 KiB for that mesh.

Operations#

Registrations, publications, batch launches, and pair advances are asynchronous. Each returns an operation ID, and these calls manage the operation:

  • wait_op waits up to a timeout. A timeout only means that the work is still running. Nothing is canceled, and nothing can be.

  • query_op_status reports the state, the final status, and progress without consuming anything.

  • destroy_op releases the operation and everything it kept alive: its version, its borrowed inputs, and its result slot. It returns BUSY while the work is still running, or until a wait, status call, or fetch has observed that it finished.

Each input column declares who keeps its data alive:

Destruction#

You destroy every object explicitly. A destroy call returns BUSY instead of waiting while something still uses the object, as in these cases:

  • A population, while a view, plan, reporter, or operation uses it.

  • A plan, while an operation owns one of its slots.

  • The instance, while anything it created is alive.

Destroy objects in reverse order of creation.

In Python, operations, populations, views, plans, and reporters are context managers, and the instance owns everything created through it. Leaving the instance’s block closes what is still open, operations first and the instance last. If the block raised, that exception is the one you see, with any teardown failure added to it as a note. Leaving an operation’s block waits for it and closes it.

Important

Retire a CUDA operation with close_after_cuda() before its block ends, because only the caller knows which streams read its results.

Convex Hulls#

The library builds a convex hull from the points of a convex definition that you register and of a mesh that you publish with physics:approximation = "convexHull". It builds one of two hulls:

Hull

Used For

What It Is

The points’ own hull

A registration with hull_vertex_limit zero, the default

Its vertices are points, and every point lies inside it within enclosure_tolerance of its largest half extent (2^-20 by default, at most 2^-16). It has at most 255 vertices and 254 faces; any definition of at most 129 points fits.

The hull a PhysX simulation collides with

A registration with hull_vertex_limit from 8 to 64, and every ovstage convexHull mesh, under its physxConvexHullCollision:hullVertexLimit clamped to 8 to 64, or 64

The hull PhysX cooks for a convexHull collider under that limit. It has at most that many vertices, and they need not be points. It can reach outside the points, and points can lie outside it: a beveled carton of 279 points keeps 34 of them at 64 and leaves points up to 0.9 percent of its size outside. It can differ from the simulation’s for a mesh thinner than about 1 percent of its size, which the simulation thickens first, and for a mesh under non-uniform scale, whose hull the simulation cooks before scaling. To get it for a stage’s collider, register the mesh’s local points in stage units and place the object with the prim’s world rotation, its world translation times the stage’s meters per unit, and a uniform scale of its world scale times meters per unit, composing the prim’s transform with its ancestors’: points already moved, turned or converted to meters can give another hull.

Note

When the points’ own hull has more vertices than the limit, PhysX fits an oriented box around the points and cuts it with planes of their hull until another cut would exceed the limit. Corners of the box that no cut removes stay in the hull. For points on a sphere, those corners lie up to about 65 percent of the radius outside the points at limits 8 and 16, and about 20 percent at 32. At 64 the vertices lie on the points. At every limit, points can lie up to about 12 percent of the radius outside the hull.

The points’ own hull is refused when it exceeds its limits, or when the points lie so nearly in one plane that no hull of their own encloses them. The diagnostic names the definition and, for enclosure, how far outside the farthest point lies. A mesh or definition for which PhysX cooks no hull is refused too. The two sources then answer differently:

Source

A hull that cannot be built

ovstage

The mesh is excluded as MALFORMED_GEOMETRY, and the rest of the population publishes.

Explicit

The registration returns INVALID_ARGUMENT before it admits any work. The diagnostic names the definition.

The library never replaces such a convex with its bounding box. A convex whose hull cannot be built is refused, or excluded, and a query never reports hits on a box that stands in for it. If your program needs a box as a fallback, register a box definition yourself.

Important

Known limitation: the hull builder can fail to return for very thin point clouds. A registration or a publication that reaches one never returns and keeps one CPU core busy on the calling thread. In a random sample, about 3 percent of the slabs 3e-6 to 1e-4 of their extent thick hung (77 of 2,304), and every one had 16 or more points. Thicker shapes, such as spheres, cylinders, and rotated boxes, never did, and nearly all flatter slabs are refused because their points lie too nearly in one plane. No thickness separates the clouds that hang from the clouds that register.

To avoid it, register such a shape as a triangle mesh, or as a box or another primitive, instead of a convex. You can also register it with a hull_vertex_limit, which cooks it as a PhysX simulation does. None of 336 such slabs hung that way.

Status Codes#

Every C call returns an ovspatialquery_result_t with a status. ovspatialquery_get_last_error() describes the last failure on the calling thread, and ovspatialquery_get_last_op_error() the failure of an operation that is still alive. The Python package raises ApiError with the status and that description.

A status is one of these values:

Status

Meaning

SUCCESS

The call did what it says.

ERROR

A failure with no more specific status.

TIMEOUT

A wait saw the work still running.

INVALID_ARGUMENT

Malformed input, or a value outside the input domain.

INVALID_HANDLE

A zero, unknown, or wrong-kind handle, or one from another instance. A handle from another loaded copy of the library is not detected. Refer to Several Copies in One Process.

INVALID_STATE

The object is in the wrong state for the call, such as a second first publication.

NOT_SUPPORTED

The combination is not available, such as CUDA work without CUDA.

NOT_READY

The result is not there yet, or a population has no head.

BUSY

Something still uses the object, or its work is still running.

STALE_ORDINAL

A pair advance that moves neither endpoint.

ORDINAL_MISMATCH

A publication’s base is not the head, or two endpoints in one population disagree.

ORDINAL_NOT_RETAINED

The requested ordinal is neither the head nor retained.

BACKWARD_ORDINAL

A pair advance to an older ordinal.

OPERATION_CAPACITY

No free operation entry.

RESULT_CAPACITY

No free result slot in the plan or reporter.

HOST_BUDGET, DEVICE_BUDGET

The work would exceed the memory budget.

OPERATION_FAILED

Admitted asynchronous work failed.

OUT_OF_MEMORY

An allocation failed outside the budgets.

INTERNAL

An internal check failed; no partial state was published.

DEVICE_LOST

The CUDA device was lost during admitted work.

Note

Stage content is never an error. A prim that an ovstage population cannot publish is left out and listed in the publication result, as Excluded Prims describes.