App Volume Management
What you build
A small program that gets or creates an app volume, the named box in the room that holds your rendered content. It moves and resizes the box, moves and shrinks your content inside it, and prints the distinct updates its subscription delivers. It then reads the volume's latest values, maps a room-space point into your content, changes the gesture rules, publishes a world anchor with the volume, lists every volume in the session and clears the anchor again.
What you will learn:
- how a volume's common name makes creation idempotent,
- the two transforms: the box in the room, and your content in the box,
- why you read the latest values instead of applying an update's values,
- how a point in room space becomes a point in your content,
- how to change the gesture rules and set a world anchor,
- which handles you destroy, and in which order.
Before you start
- Windows, with QAROS installed on the Hub machine. The program runs on the Hub machine. Joining as a local app starts the Hub when it is not running.
- Joining. The program joins the Hub as a local app: click Allow in the QAROS approval prompt on the first run of the executable. Nothing is stored, and later runs join without a prompt while the executable is unchanged.
- The examples built, with the repository's CMake presets (MSVC).
- The GUI Panel Operations tutorial explains subscriptions and the rule for ending them in more detail. This tutorial uses the same pattern.
Run it
From the repository root, in a Developer PowerShell for Visual Studio:
The program loads the runtime of the installed QAROS. To load another one, such as a development build, add --qaros-library=PATH with the path of its qar-streaming-c.dll. Any other argument prints the usage and exits with 1.
Expected output after the join messages (<...> stands for values of your own run; the library's own log lines are left out):
Every run prints the same id: it derives from the common name, and the program leaves the volume open. The Latest: and Room point lines show the values the program set, unless a user or another peer changed the volume meanwhile. The program renders nothing, so in the room the box stays empty.
When no update of the volume arrives within 10 s of the changes, the line No update of the volume arrived within 10 s of the changes. replaces the Update: lines, the steps after the Received line are left out, and the program exits with 1.
The Hub delivers updates on its own schedule, reports your own changes back to you, repeats them, and can deliver them out of order: the last update can carry an app scale of 1.00 after you set 0.50, while the Latest: line reads 0.50. That is why the program prints only an update that differs from the last one it printed, and why it takes the current values from the latest getters, not from an update. When no update repeated another, the Received line ends after printed <m>.
Exit codes: 0 when every step succeeded; 1 for an unknown argument, when a call failed (the line before names it and its status), or when no update of the volume arrived within 10 s of the changes; 2 when no runtime loaded; 3 to 7 for a refused local-app join (the program prints what to do): 3 when it could not start or reach the Hub, 4 when the approval was denied, 5 when nobody answered in time, 6 when the program answering is not the installed QAROS, 7 when the executable no longer matches its approval.
Walkthrough
1. Get a session
A volume is shared session state: every peer sees the same box at the same place. The program gets its session with the helpers of common.h, as GUI Panel Operations does: it joins the Hub on this machine as a local app with its own app tag.
The Local App Onboarding tutorial explains the local-app join, its approval prompt and its app tag.
2. Get or create the volume
Like a panel, a volume is identified by a stable common name. qar_app_volumes_get_or_create() returns the volume with that name and creates it the first time, so the call is safe on every start and a restarted app finds its box again. The id derives from the name, and it is what a render sender needs.
Volumes persist: a volume stays in the session after your program ends, until someone closes it. So the call returns the existing volume of that common name, or a new one, and does not say which. Do not try to tell them apart by listing the volumes first: right after joining, the list may not hold every volume yet. Write your app so that both cases work.
- pose is the pose of the box's center in room space (a panel's pose is its top-edge midpoint).
- size is width (X), length (Z, the horizontal depth) and height (Y), in meters. The box covers half of each extent on either side of the center.
- app_pose and app_scale, left at their defaults here, place your content in the box (step 4).
The init describes a new volume only: an existing volume keeps its own values. Change what must change with the calls of step 4 and step 8.
What can go wrong: the common name must be ASCII, and the runtime rejects any other. When the call fails, the program stops: every later call needs the volume id.
3. Subscribe to volume updates
Users grab and scale volumes with gestures, and other peers change them too. A subscription tells you when. qar_app_volumes_subscribe_updates() reports changes to every volume in the session; there is no per-volume form, so the callback skips other volumes by id.
The callback runs on a library thread. Its QarAppVolume handle belongs to the library and is valid only during the call: read it with the qar_app_volume_get_* getters, copy what you need, and do not destroy it. The callback shares the update log with the main thread, so a lock guards it.
The callback prints an update only when it differs from the last one it printed. A repeat need not be equal to the bit: its floats can differ from the earlier report below any precision you print or see. So the program compares poses, size and scale with a tolerance, the precision it cares about, and the lifetime exactly:
The tolerances are in common.h, shared with GUI Panel Operations :
4. Move and resize the box, then your content
A volume has two transforms (Coordinate Systems):
- The box in the room: qar_app_volumes_change_pose() and qar_app_volumes_change_size(). Moving the box moves everything in it. Users usually do this by grabbing the volume.
- Your content in the box: qar_app_volumes_change_app_pose() and qar_app_volumes_change_app_scale(). They pan and zoom your content without your renderer changing anything.
Here the box moves half a meter further away and shrinks to a 0.8 m cube. app_pose is in volume meters and is not scaled: your content's origin sits 25 cm below the box's center. app_scale is room meters per app meter: at 0.5 your content appears at half size.
What can go wrong: QAR_STATUS_APP_VOLUME_INVALID_ID means no volume has that id, for example because it was closed. Call qar_app_volumes_get_or_create() again if your app still needs it.
5. Receive the updates, then end the subscription
The program waits up to 10 s for the first update of its volume, then until no update of it has arrived for half a second, and then ends the subscription. The Hub can take a few seconds to deliver the first update, so a quiet period alone could end before anything arrived. When no update comes within 10 s, the program says so, skips the remaining steps and exits with 1. The wait is example_wait_for_updates from common.h, which GUI Panel Operations shows.
A real application does not wait for a quiet period: it handles updates in its own loop. When qar_cancel_token_cancel() returns, no callback is running and none starts, so the update log may be read without the lock and freed. Never end a subscription while holding a lock its callback takes: ending it waits for the running callback.
6. Read the latest values
The qar_app_volume_get_latest_* getters return the latest values this peer knows, including changes by other peers and by gestures. An update tells you that the volume changed, but its values can be older than the latest ones. So on each update, read the getters again and apply what they return.
7. Map a room-space point into your content
Gesture points already arrive in app content space. A point you hold only in room space, such as a GUI panel's position or a device pose, takes two steps: room to app volume space through the volume pose, whose position is the box's center, then app volume space to app content space through the app pose and app scale. The test whether the point is inside the box happens in app volume space, against half the extents.
The program maps the point 25 cm above the box's center. With the values of step 4 it lands at (0, 1, 0) in your content: 50 cm above your content's origin in the volume, which at app scale 0.5 is one app meter.
8. Change the gesture rules
The gesture rules decide what a user's hands do to your content. Start from qar_app_volume_gesture_configuration_default(), which mirrors what a volume created without a configuration gets: two-hand distance to app scale, one-hand drag to app pose (rotation off), hover, click. Rules are in descending priority. Change a rule in place, then replace the volume's default mode with qar_app_volumes_change_gesture_configuration().
What can go wrong: QAR_STATUS_APP_VOLUME_GESTURE_CONFIGURATION_INVALID means a rule could never work, and the volume keeps its previous rules.
9. Publish a world anchor
A world anchor is geographic reference metadata the volume carries: an Earth-fixed frame in ECEF WGS84 meters with unit axes. The SDK stores and replicates it; it does not move the volume, change the app pose or scale, or transform render poses. Applications that read it apply their own mapping. Here the frame's +X points east, +Y up and +Z south of a latitude and longitude, which keeps it right-handed.
The latitude, longitude and height are an example: use the place your content belongs to. The anchor stays with the volume, for every peer, until someone clears it. The listing of step 10 shows whether a volume has an anchor, and step 11 clears it.
What can go wrong: QAR_STATUS_ARGUMENT_NOT_SUPPORTED means the frame's handedness is QAR_HANDEDNESS_UNSPECIFIED.
10. List the volumes
The listing uses the count-then-fetch pattern: ask for the count, allocate that many handles, fetch them. You own each handle the fetch returns and destroy it when done. A fetch that returns an error may still have written some handles: destroy those too.
The listing is a snapshot of every volume the session knows. It can be stale the moment it returns: use it at startup or for display, and the subscription to follow changes.
The program leaves its volume open, so the next run reuses it. qar_app_volumes_close_volume() would retire it for every peer.
11. Clear the anchor
The volume is shared and stays after the program ends, so the example anchor would stay too, for every peer. qar_app_volumes_clear_app_world_anchor() removes it. Clear an anchor of your own only when it no longer applies.
Using the volume for rendering
A render sender streams your frames into a volume: point QarRenderSenderInit::app_volume_id at the volume's id when you create the sender (CPU Rendering with a Visualizer). The volume also defines the space the sender hands you poses in, app content space, under the volume's current app_pose and app_scale. While the volume does not resolve where the stream is received, beginning a frame fails with QAR_STATUS_RENDERING_PRODUCER_APP_VOLUME_UNRESOLVED. That is normal control flow: keep the sender and try again. A volume you closed never resolves again; create it anew with qar_app_volumes_get_or_create().
Ownership and teardown in C
| Value | Who owns it | How it ends |
|---|---|---|
| QarRuntime*, QarSession* | you | qar_session_handle_destroy(), then qar_runtime_handle_destroy(), then example_unload_library (qar_library_destroy() and the unload) |
| QarCancelToken* | you | qar_cancel_token_cancel() ends the subscription; qar_cancel_token_handle_destroy() frees the token and also ends it |
| the update log (user_state) | you | free it only after the subscription has ended |
| QarAppVolume* in the callback | the library | valid during the call only; never destroy it |
| QarAppVolume* from qar_query_app_volumes() | you | qar_app_volume_handle_destroy(), then free the array |
| QarAppVolumeId | a plain value | names the volume; not a handle, nothing to free |
| the volume itself | the session, shared by every peer | qar_app_volumes_close_volume(); destroying your session does not close it |
qar_session_handle_destroy() and qar_library_destroy() also end every subscription still running. Do not destroy the session or the library from a callback.
Troubleshooting
| Symptom | Cause | What to do |
|---|---|---|
| Could not start or reach QAROS on this machine. Start QAROS from the Start menu, then start this app again., exit code 3 | The local-app join could neither start the Hub nor reach it | Start QAROS from the Start menu and run again |
| Exit code 4 or 5 after Joining the QAROS Hub on this machine as a local app | The approval prompt was denied, closed or not answered within 120 s | Run again and click Allow |
| The box already has another app's content or values on the first run of your own app | A volume with that common name already exists in the session, and get-or-create returned it | Expected: volumes persist. Pick a common name scoped to your app |
| ERROR (code=325) from a call or getter: QAR_STATUS_APP_VOLUME_INVALID_ID | The volume was closed, possibly by another peer | qar_app_volumes_get_or_create() again |
| Latest: values differ from what you set | A user or another peer moved or scaled the volume | Expected: apply the latest values, not your own copy |
| The last Update: line differs from Latest: | Updates arrive repeated and out of order | Read the latest getters after each update |
| Your content appears at the wrong size or offset | app_pose or app_scale set by a gesture or another peer | Read qar_app_volume_get_latest_app_pose() and qar_app_volume_get_latest_app_scale() again after each update |
| Volume values not available | The latest getters failed for this volume | Check the status in the line before; get or create the volume again |
| No update of the volume arrived within 10 s of the changes., exit code 1 | The Hub delivered no update of the volume within 10 s after the changes | Check that the Hub is still running and run again. In your app, read updates as they come instead of waiting for them a fixed time |
| The program hangs while ending the subscription | A callback is waiting for a lock the ending thread holds | Release the lock before qar_cancel_token_cancel() |
| No QAROS runtime loaded | The default lookup found no runtime | Install QAROS, fix or unset QAR_INSTANCE, or pass --qaros-library=PATH |
Next
- CPU Rendering with a Visualizer : render into the volume.
- App Volumes and Gestures: gesture events, the editing lock and other ways peers coordinate on a volume.
- Coordinate Systems: every space in one place.
- The same program in Rust: App Volumes.
Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.9.8.