Handling broken presets

DSP, Plug-in and Host development discussion.
471 posts since 6 Aug, 2005 from England

Post Mon Aug 13, 2018 12:29 pm

Vokbuz wrote:
BertKoor wrote:Errors can always occur. So what's wrong with reporting "Sorry, an error occurred: premature EOF" to the user?
The problem is not in showing error report. Problem is that when error discovered plugin state is only partially updated and its state is likely producing garbage sound. That is not what user expects.
That’s where the “cyclic redundancy check“ comes in handy. Or the hashing mentioned above.

7 posts since 5 Jul, 2018

Re: Handling broken presets

Post Wed Aug 15, 2018 7:04 am

TL;DR: could you save your current state first, and restore from that if something goes wrong?

I think the common thread to a lot of the suggestions in this thread is they're two-step solutions, where it's possible to cleanly bail out after the first step, before you make any actual changes.

Perhaps your first pass is verifying a CRC/hash. Or maybe your first pass is parsing into a richer data structure (XML/CBOR/custom objects), and you can bail out if your data is truncated or malformed. Mystran talked about this earlier, as separating parsing and application.

However, it's still possible that your data is fundamentally the right shape (CRC/hash checks out, valid XML) but has more subtle problems, like out-of-range values or arrays with the wrong length. It's definitely a bit of an edge-case (maybe the presets are actually from a different plugin or a later version?), but you'll basically never catch these unless your first-pass logic is as complex as the actual second-pass application.

Another approach (which could be used on its own, or in addition) might be to save your own state (re-using the same code as when saving to the host) before you apply the incoming preset. If applying the incoming preset fails, you can restore the previous state, or else release it. It's a little weird, but it should be possible to implement without any duplication.

Code: Select all

    ... whatever ...

    backupState = new State()


User avatar
443 posts since 25 Sep, 2014 from Specific Northwest

Re: Handling broken presets

Post Sun Aug 19, 2018 5:15 pm

You don't need full xml, which literally nobody uses correctly anyway. :roll:

Just use a tag and a value in any format you prefer. Unrecognized tags can be ignored. Initialize a preset object with default values prior to loading so missing/newly added tags not present in an older preset still have sane values. Once loaded, you can safely clone the object into the current working preset object of nothing has gone horribly wrong.

Return to “DSP and Plug-in Development”