Exception in ThIAnalyze.solve

Hi everyone,
I’ve been working on a plugin that makes use of Karamba API 1.3.3. In some of the components I am running analyses inside the component using ThIAnalyze.solve. Sometimes, I get this exception:

  Message=External component has thrown an exception.

The strange thing is that it is only sometimes, and I can’t figure out in which conditions. Anyone else getting this? For now, I’ll probably just pull the analysis out of the plugin component and use the actual K3D component for it, but I’d really like to know why this happens.
Thanks in advance, Eduardo

Hi @castroecosta,
do you have a code snippet that reproduces the error and which you can send over?

Thanks for the reply, Clemens!
I’ll try to replicate it ASAP.

Hi Clemens,
Here I am back with the problem mentioned above, except now it’s happening with AnalyzeThII. I’m pasting the component code, let me know if you need more info. I’d upload a GH file, but since this is part of a custom plugin component I don’t know how to make it work here.
Thanks in advance,

    protected override void SolveInstance(IGH_DataAccess DA)
        GH_Model ghModel = new GH_Model();
        bool fast = false;

        if (!DA.GetData(0, ref ghModel)) return;
        if (!DA.GetData(1, ref fast)) return;

        // convert GH_Model to Model
        Model k3dModel = ghModel.Value;

        // errorMsgs collects error messages from analysis algorithms
        List<string> errorMsgs = new List<string>();

        //------------ ANALYSIS (displacement and buckling)
        // perform analysis: for fast calculations uses AnalyzeThI

        Model k3dModelAnalysis = new Model();
        Model k3dModelBuckling = new Model();
        double maxDisp = 0;
        List<double> bucklingFactors = new List<double>();
        if (fast)
            ThIAnalyze.solve(k3dModel, out List<double> maxDispsThI, out _, out _, out string warning, out k3dModelAnalysis);
            maxDisp = maxDispsThI[0] * 100; // assuming results in [m], even though component outputs in [cm]
            // using defaults from GH AnalyzeThII component
            AnalyzeThII.solve(k3dModel, -1, 1.0e-7, 50, false, out List<double> maxDispsThII, out _, out _, out k3dModelAnalysis, out string warning);
            maxDisp = maxDispsThII[0] * 100; // assuming results in [m], even though component outputs in [cm];

            // calculate buckling model and safety factors
            // using defaults from GH BModes component; 300 MaxIter might be reduced for performance; like GH component, returns positive load factors only
            Buckling.solve(k3dModelAnalysis, 1, 1, 300, 1.0e-7, 1, out bucklingFactors, out k3dModelBuckling, out _); 

        DA.SetDataList(0, errorMsgs);
        DA.SetData(1, new GH_Model(k3dModelAnalysis));
        DA.SetData(2, new GH_Model(k3dModelBuckling));
        DA.SetData(3, maxDisp);
        DA.SetDataList(4, bucklingFactors);

Hi Eduardo,
I could not reproduce the error. I used this definition:
ThII_Buckling_scripted.gh (26.4 KB) which uses Karamba3D 2.0.0 (see here). The only thing I changed compared to your script is the load-case identifier which needs to be a string now.
– Clemens

Thanks for trying!
As I said, the error seems to occur only sometimes, which makes it hard to debug. The only pattern I recognize is this: sometimes the component throws the exception when I open the GH file but it sorts itself out after one recompute, while some other times the exception stays there even after many recomputes…

Do you have any suggestions on how to debug that kind of exception (System.Runtime.InteropServices.SEHException)? From what I found, this is proper software development stuff: SEHException Class (System.Runtime.InteropServices) | Microsoft Docs ; c# - How should you diagnose the error SEHException - External component has thrown an exception - Stack Overflow

Anyway, I’ll keep digging, and will post it here if successful.
Best, Eduardo

Hello @castroecosta,
I tried to reproduce the problem using a Galapagos loop:
ThII_Buckling_scripted_crashing.gh (28.5 KB)
The problem is, that now Galapagos rather than Karamba3D seems to cause the crash.
A definition which replicates the problem would be very useful for eliminating the bug.
– Clemens