Handling broken presets

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

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.

Post

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

saveState(stateObj):
    ... whatever ...

loadState(stateObj):
    backupState = new State()
    saveState(backupState)
    try:
        actualLoadState(stateObj)
    catch:
        actualLoadState(backupState)

actualLoadState(stateObj):
    ...

Post

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.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better? :(

Post Reply

Return to “DSP and Plugin Development”