CallbackOnCollectedDelegate exception

Moderators: TomKerekes, dynomotion

Post Reply
Juanjo-Lasing
Posts: 25
Joined: Wed Sep 04, 2019 11:56 am

CallbackOnCollectedDelegate exception

Post by Juanjo-Lasing » Thu Jun 11, 2020 12:46 pm

Hello,

I am getting this exception by using KMotion's interpreter on my application. This happens sometimes and I have not found any pattern to predict it. The same G-Code file may or may not trigger this exception. The problem is that when that happens, the whole program stops and Visual Studio does not mark any code of mine as the problem.

callbackoncollecteddelegate.PNG

This is the message I get when this happens:
CallbackOnCollectedDelegate occurred
Message: Managed Debugging Assistant 'CallbackOnCollectedDelegate' has detected a problem in 'C:\Users\epatec\Desktop\LS-PROCESS-NV\MAIN\LSPROCESS\LSPROCESS\bin\Debug\LSPROCESS.vshost.exe'.
Additional information: Message: A callback was made on a garbage collected delegate of type 'KMotion_dotNet!KMotion_dotNet.KM_CoordMotionStraightTraverseSixAxisHandler::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.".
I found some information about this exception here https://docs.microsoft.com/en-us/dotnet ... legate-mda and it seems that this happens random.

I don't know how to solve this. Has anyone have this problem before?

Thank you.

User avatar
TomKerekes
Posts: 2527
Joined: Mon Dec 04, 2017 1:49 am

Re: CallbackOnCollectedDelegate exception

Post by TomKerekes » Sat Jun 13, 2020 2:29 am

Hi Juanjo-Lasing,

Sorry you are having problems.

Your link is very informative. But its not clear why you should receive the error.

Basically the .NET library registers a 6 axes call back to the unmanaged C++ code. The callback is called to inform the higher level code whenever a rapid G0 motion it processed. The .NET library makes a global public variable for the callback to prevent the garbage collector from deleting the callback function. As described in the link.

One confusing factor is that our legacy code expected Rapid callbacks to inform the Application of the 3 axes (xyz) position for the rapid. Later rapids could callback with 6 axes (xyzabc) positions. The .NET code supports registering either a 3 axes or 6 axes callback.

When the .NET Interface receives a callback (always 6 axes) from the Interpreter that a Traverse (G0) occurred, it checks if a 3 axes or 6 axes callback has been registered with it and makes the appropriate callback

Does your Application register a callback? Is it for 3 axes (xyz) or six axes (xyzabc)?

Regards
Regards,

Tom Kerekes
Dynomotion, Inc.

Juanjo-Lasing
Posts: 25
Joined: Wed Sep 04, 2019 11:56 am

Re: CallbackOnCollectedDelegate exception

Post by Juanjo-Lasing » Thu Jun 18, 2020 7:14 am

Hi Tom,

Sorry I couldn't reply sooner.

I initialize the axes from a C program, based in the file InitStepDir3Axis.c from the C Progarms folders in the KMotion434 folder. I use a total of 5 axes (0, 1, 3, 4, 5). In this C file I also make a home routine for all the axis. I don't do anything with axis 2 because I never use it. Should I also initialize axis 2 even if I don't use it?

On the other hand, when I execute a G-Code I only use 3 of those axes (0=y, 4=x, 5=z). I know that the nomenclature may seem unusual but it is necessary for my application. These axes are supposed to be ready for use after they have been initialized.In addition, any other movement routine performed with Move or Jog instructions works perfectly.

The most unusual thing for me is the seemingly random nature of this behavior. When the interpreter works, it does it perfectly but when I get the exception, it does it right before starting the G-Code execution. If I knew when it was going to happen, I could try to fix it in code.

Thank you.

User avatar
TomKerekes
Posts: 2527
Joined: Mon Dec 04, 2017 1:49 am

Re: CallbackOnCollectedDelegate exception

Post by TomKerekes » Thu Jun 18, 2020 4:30 pm

Hi Juanjo-Lasing,

No rush from our end.

Thanks for the info and background, but I was more asking about your Application rather than how KFLOP is configured. The Interpreter has a callback that your Application can register to be informed on what type of motion has been created by the Interpreter. .NET refers to these as events. Applications normally use this to plot the motion. Also there are two different types of callbacks that your Application can request. One returns only the XYZ data. The other returns XYZABC data. Does your application have a function that it is registering? See the event to receive 3 axis callback and 6 axis callbacks..
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply