Plugin crashing, where to safely layout components?

I am almost finished developing a plugin and I notice is flaky / crashes occasionally.

The crashes occur when laying out components after a param change, onParamChange I am calling setTargetAndDrawRects() on multiple controls.

Plugin::OnParamChange()
    for each control control->setTargetAndDrawRects(IRECT(newBounds))

The crashes happen during the next Draw() call, they are not consistent and only happen every 20 param changes or so (varies), they are also different bugs mostly related to Draw() many times on rasterize font, other times on swap draw buffers or other that causes access violation, here is an example of the call stack:

Its difficult to debug this call stack or the errors, is there a safer place/way to layout my components? Should I try to create a minimal project to reproduce this issue? Any suggestions for workarounds? Appreciate it, thanks.

Think I found it!
By marking a flag with components dirty and re-layout the components during OnIdle() the crashes no longer happen. No idea why, maybe there should be some docs about threads and OnIdle() and where its safe to update graphics.

Cheers,

You shouldn’t touch the controls in OnParamChange(). That can be called on the real time audio thread. You can use OnParamChangeUI() which is called on the main thread. You need to test if the UI exists by calling GetUI() before touching controls. If the UI is not open it will return nullptr;

1 Like

Layout should happen in OnLayoutUI() or the mLayoutFunc set in the plugin CTOR like in the examples

1 Like