Note: I don’t know PyTorch at all, so these comments all address common C++ issues:
First of all: You can find the exact location where your crash happens yourself using your debugger. If you are not familiar with such a common tool, I’d strongly advise you to get familiar with it to become able to help yourself fixing simple problems. You should specify the AudioPluginHost as the application to execute and then start a debugging session from your IDE whith your plugin project loaded. Then perform the same steps and the debugger will stop at the line of code where your crash happens.
That being said, the line
*module = torch::jit::load ("first_ascending_model.pt");
looks suspicious. You are dereferencing this
module pointer and assigning a new object to it. How and where is
module declared and where do you actually allocate the memory it points to? If you didn’t allocate any memory (and this is what I guess as this line is the very first line of your constructor) you try to assign the object returned by
torch::jit::load to a non-existing memory location, which will obviously lead to a crash. In case your debugger tells you that this is your fault, I strongly recommend you to make yourself familiar with the concept of pointers and memory allocation in C++, if you did not understand this completely, you will likely write a lot of crashing code.
Beneath this, I see that you are creating
std::vector instances inside your
renderNextBlock function. While this should not be a reason for a crash, this is an operation that allocates under the hood and therefore is not suited for usage in a realtime capable rendering callback. You should move all your
std::vector creation and
push_back operations out of this function and make your inputs vector a class member instead, so that you can prepare it beforehand in your constructor instead of creating new instances over and over. While we are at this, have you investigated if the functions of the PyTorch library that you use in your processing are realtime safe under the hood (e.g. non-blocking, non-allocating)? Otherwise you’ll hardly achieve realtime performance with this approach at all…
One last thing looking at your screenshot: Please do yourself a favour and change the font in your code editor to a monospaced font – code will immediately look so much more structured