Hi everyone
As you might know from the forum, in some plugins, there are multi-instance crash issues in all DAWs but mostly Cubase, Reaper, Studio One.
If the user inserts one plugin instance in the DAW project, it will be ok. But if the user inserts multi plugin instances (like 5 to 10), in some machines, the DAW project can not be opened again (no problem while inserting and using in the DAW project by the way, the only problem is about re-opening the DAW project again) and this is a nightmare for a user/customer also for you too as the plugin developer :)
These multi instance crashes can be inverse proportion. For example, DAW project may crash with only 3 instances of your plugin. But it may not crash with 50 instances :) Or vice versa. It's all about moodycamels queue issue with Hise.
Of course this issue is up to your code optimization. If the communication queue between audio thread and UI is full, that means your plugin is sending too many messages. These too many messages can cause a congestion / bottleneck and then the crash happens finally. The DAW project can’t be opened again!
I’ve been investigating this issue (also acording to the users’ feedbacks of course) for a while and I just wanted to share my observations with you. These are my experiments and observations. If you find out anything else please wellcome and share.
Please note that “Multi instance DAW Crash Issue” has no only one cause. This issue is the sum of various situations. If you will be careful about these causes, the crash issue can be reduced or even fixed. The main goal is making a very light cpu / ram user plugin. So, possible causes are described below:
Wrong If Statement usage
One cause is using too much sequential if statements in a wrong way. Just a quick example for wrong usage:
if (value == 1)
{
Do something
}
if (value == 2)
{
Do something
}
if (value == 3)
{
Do something
}
if (value == 4)
{
Do something
}
In above code, since each if statement will be checked and that will cause too much message during the initialization. Instead of the sequential if statements, this implementation should be done like that:
if (value == 1)
{
Do something
}
else if (value == 2)
{
Do something
}
else if (value == 3)
{
Do something
}
else
{
Do something
}
Now it is correct. With using else if
, when the condition complies it will exit the statement and each if statement won't be checked. This will massively reduce the clog and the plugin will be much more tranquiled, relaxed :) Alternatively you can use switch / case
statements for this purpose too.
setAttribute:
Another cause is the amount of used setAttribute APIs. More setAttribute you use, it means the plugin probably will crash more likely in multi-instances. (Remember sending too many messages). Of course you will need to use it in most cases. But if there is a case that you can live without using even one line, try not to use it. Do not over use setAttribute in your code and be careful while you use it especially in an array usage.
Shared Functions:
Shared functions have been used in various places in the same plugin. If these functions have lot's of setAttribute APIs, and if you used multiple shared functions in one GUI element (for example Link Button), the plugin tends to crash in multiple instances of course because of the bottleneck on the initialization.
Image size:
Total used image size is very important too. Please note that, even if you compressed images and the size is reduced; it doesn’t matters! On the exported plugins, the image will take it’s normal place inside the memory like it’s not compressed, as big sized bitmaps. So be careful about image dimensions and formats. For example if your background image doesn’t have transpency, there is no need to use it as.png file. Instead, use as jpg. Because .png files can be 3 or 4 times bigger than jpg files. Using jpg files will end up big bitmaps too but at least you will not get "Heap is Out of Space" error while compilng.
Also avoid using big pixel sizes. For example if your GUI canvas size is 1000 x 600 pixels, there is no need to use 5000x3000 pixels :) Try to sharp the pixel sizes too, as much as you can. For knobs, calculate the optimum frame size for your GUI mesaurements and then prepare the imagestrip acording to this size. Don’t use oversized image strips. We need to make a very light cpu and ram sucker plugin :) Acording to my observations, going above the 15MB total image size, the multi instance crash possibility will be much more higher :)
Deferring Callbacks:
It’s not the ultimate cure for the crash issue but it can be a big improvement for some situations. Search forum for the usage of deferred callbacks. Also if you can reproduce the crash issue in your system, try using and not using plugin exports individually. Observe the impact, if deferring callbacks makes the improvement, use it. Also multi instance DAW testing is a good idea, save multi plugin opened DAW sessions individually (like 5 instances, 10 instances or 30 instances) and try to reopen them :)
Timer Objects:
Over used Timer objects can cause problems too. Especially very short times like 10ms, 20ms….etc.
Simple Serial Copy Protection:
If you are using thousands of long serial number batches in your plugin, since these thousands of serial numbers will be checked in every initialization, it can cause crashes. Instead of using thousands of lines for the serial copy protection, use the formula technique for serial number usage. Or make the serial check once a day.
OpenGL
If your plugin uses lot's of live analysis, vector based animations...etc, using OpenGL will be a good improvement. But if your plugin doesn't use stuff like that, it will has no impact, in some conditions also negative impact like black screen, not loading the plugin, extra crashes.... etc.