Skip to content

ptz-controls: auto-save config + clamp preset_max - #323

Open
EdueskaWeiz wants to merge 2 commits into
glikely:mainfrom
EdueskaWeiz:pr/autosave
Open

ptz-controls: auto-save config + clamp preset_max#323
EdueskaWeiz wants to merge 2 commits into
glikely:mainfrom
EdueskaWeiz:pr/autosave

Conversation

@EdueskaWeiz

Copy link
Copy Markdown
Contributor

Reworked from #302 per your review.

  • ptz-controls: periodic auto-save. The dirty flag is now raised from a single central slot wired to the existing change signals, instead of scattering markDirty() through every setter. Rationale is in the commit message rather than a separate .md file.
  • ptz-device: clamp preset_max to the 1..128 slider range (your "Use clamp()?" suggestion), guarding against corrupt configs.

Both commits are clang-format clean and carry a DCO Signed-off-by line. The crash/threading change is intentionally left out since you reverted that approach, and the custom config backup is dropped as redundant with the existing obs_data_*_safe("bak") mechanism.

@glikely

glikely commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Have you run tested this PR?

@EdueskaWeiz

Copy link
Copy Markdown
Contributor Author

Have you run tested this PR?

Sorry for the slow reply. Yes — run tested with OBS Studio 32.2.1 against a VISCA-over-IP camera. The case I cared about is the one the PR is for: change presets, wait for the auto-save interval, then kill the OBS process instead of quitting cleanly. With this patch the presets are still there after restarting OBS; on main they are lost because the config is only written on shutdown.

Two things I have not covered and would like a second opinion on:

  • I have not measured the write frequency on a busy setup. The dirty flag is only raised from markConfigDirty(), and config load at startup is deliberately excluded, so an idle session should not write at all — but if you would rather see a longer interval than 30 s, that is a one-line change.
  • The preset_max clamp (1..128) is a defensive fix for a corrupt config producing a huge size_t preset count. Happy to split it into a separate PR if you would rather keep this one to the auto-save change.

One more thing: this branch has never had a CI run — the Checks tab is empty because the workflow was never approved for the fork. I am rebasing onto current main now so there is something current to run against. Heads-up that #330 moves the preset data into PTZDevice, so this will need a second rebase once that lands; if you would rather merge #330 first, I am happy to wait.

Eddy Weiz added 2 commits August 8, 2026 15:20
The plugin only writes its configuration on a clean shutdown, when the
OBS_FRONTEND_EVENT_EXIT event fires. If OBS crashes or is killed, any
changes made during the session - new presets, renamed devices, joystick
and live-move settings - are lost.

Add a 30 second auto-save timer that calls SaveConfig() whenever the
configuration has been modified. To avoid scattering dirty-tracking
calls throughout every setter, the dirty flag is raised from a single
slot, markConfigDirty(), wired up centrally in the constructor to the
existing change signals (PTZDevice::settingsChanged and the autoselect /
live-move / speed-ramp toggles). The timer only touches the disk when
something actually changed, and loading the configuration at startup is
explicitly excluded from marking it dirty.

Signed-off-by: Eddy Weiz <eddyweiz@gmail.com>
The preset limit is read straight from the configuration and cast to
size_t before being handed to PTZPresetModel. A corrupt or hand-edited
config could hold a negative or absurdly large value, which after the
cast to size_t would result in a huge preset count. Clamp the value to
the same 1..128 range that the properties slider already enforces.

Signed-off-by: Eddy Weiz <eddyweiz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants