.Net KM_Controller.Compile() error

Moderators: TomKerekes, dynomotion

Post Reply
akorchak
Posts: 2
Joined: Fri Nov 16, 2018 7:04 pm

.Net KM_Controller.Compile() error

Post by akorchak » Fri Nov 16, 2018 7:22 pm

I'm trying to compile c code file using .Net KM_Controller.Compile() method. I'm getting the following error:

Code: Select all

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.String..ctor(SByte* value)
   at System.StubHelpers.CSTRMarshaler.ConvertToManaged(IntPtr cstr)
   at KMotion_dotNet.KM_Controller.KM_dotnet_Interop_Compile(IntPtr handle, Int32 boardtype, Int32 threadID, String name, String& outfile, String& error, Int32 _ErrorLength)
The issue doesn't seem to be caused by a particular .c file (tried few of them - same result). The same files are being compiled/executed from KMotionCNC without any issues.

Tried with KMotion versions 4.3.3 and 4.3.4 - same result.

Would appreciate any help. Thanks.

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

Re: .Net KM_Controller.Compile() error

Post by TomKerekes » Fri Nov 16, 2018 7:37 pm

Hi akorchak,

Did you allocate memory for the return strings?

Can we see your code?
Regards,

Tom Kerekes
Dynomotion, Inc.

akorchak
Posts: 2
Joined: Fri Nov 16, 2018 7:04 pm

Re: .Net KM_Controller.Compile() error

Post by akorchak » Fri Nov 16, 2018 10:02 pm

Hi TomKerekes,

Thanks for the response.

No, I did not explicitly allocate memory for the return string (should I?). Here is my code (used "PC VCS Examples\KMotion_dotNet Console" as a template):

Code: Select all

_Controller = new KMotion_dotNet.KM_Controller();
string thefile = @"C:\KMotion434\C Programs\ToolChange.c";
String result = _Controller.Compile(4, thefile);

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

Re: .Net KM_Controller.Compile() error

Post by TomKerekes » Sat Nov 17, 2018 2:08 am

Hi akorchak,

Oops you are correct. That routine is rarely used and has several bugs. This will be fixed in the next release.

In the meantime please use CompileAndLoadCoff() instead:

String result = _Controller.CompileAndLoadCoff(4, thefile, false);
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply