Basic XY Screw Mapping - Geo Table

Moderators: TomKerekes, dynomotion

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

Re: Basic XY Screw Mapping - Geo Table

Post by TomKerekes » Sun Feb 27, 2022 7:00 pm

I wouldn't have expected installing Python to remove anything.

It's common to have one thing wrong to cause hundreds of errors.

Yet another approach is within BuildAllLibs.sln in the GCodeInterpreter Project | Properties | Debugging | Command | change to C:\KMotion435g\KMotion\Debug\KMotionCNC.exe. (or whatever Version you are using) Then Debug GCodeInterpreter.
Regards,

Tom Kerekes
Dynomotion, Inc.

MadTooler
Posts: 86
Joined: Thu Nov 08, 2018 11:57 pm

Re: Basic XY Screw Mapping - Geo Table

Post by MadTooler » Mon Feb 28, 2022 5:43 pm

Well, maybe I sort of have some progress.

When I try to run/debug with the original fopen line in getParameter(), I get this error in the debug mode:
MainPathProblem.PNG
MainPathProblem.PNG (8.33 KiB) Viewed 828 times
It also opens "strlen.asm" at line 69. Process is [6240] KMotionCNC.exe. Not sure exactly what to give you with this.

When I look in GetParameter and hover over MainPath, "MainPath = 0xcdcdcdcd <Error reading characters of string.>"

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

Re: Basic XY Screw Mapping - Geo Table

Post by TomKerekes » Mon Feb 28, 2022 7:00 pm

The 0xCDCDCDCD exception indicates the code is trying to use something that has never been set to anything. Naturally the strlen.asm code fails trying to work with invalid data.

MainPath is determined and set in the CCoordMotion class. Which the CKinematics class doesn't have access to. So after CCoordMotion creates the CKinematics object it sets a pointer to it in the CKinematics object it created with this statement in CoordMotion.cpp about line 162

Kinematics->MainPath = MainPath;

do you have this line? Set a breakpoint on it to see if it is executed. If the breakpoint is hit what is the value of MainPath then. MainPath by itself refers to the member variable in the CCoordMotion object as that code is in the CCoordMotion class. Kinematics->MainPath refers to the member variable in the CKinematics object.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

MadTooler
Posts: 86
Joined: Thu Nov 08, 2018 11:57 pm

Re: Basic XY Screw Mapping - Geo Table

Post by MadTooler » Mon Feb 28, 2022 7:37 pm

TomKerekes wrote:
Mon Feb 28, 2022 7:00 pm
MainPath is determined and set in the CCoordMotion class. Which the CKinematics class doesn't have access to. So after CCoordMotion creates the CKinematics object it sets a pointer to it in the CKinematics object it created with this statement in CoordMotion.cpp about line 162

Kinematics->MainPath = MainPath;

do you have this line? Set a breakpoint on it to see if it is executed. If the breakpoint is hit what is the value of MainPath then. MainPath by itself refers to the member variable in the CCoordMotion object as that code is in the CCoordMotion class. Kinematics->MainPath refers to the member variable in the CKinematics object.
Yes. It is there. I was already looking at it and had tried a breakpoint. Execution fails with the prior noted error before the breakpoint at line 162ish is reached.

Looking above, I was wondering if the kinematics class was being initialized by the creation of the "new" class before the pointer is set. I tried moving the line before the new kinematics if loop but it caused a different error.

edit: Ah. I see why the different error popped when I moved it above the Kinematics=new if loop. Kinematics wasn't created yet.

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

Re: Basic XY Screw Mapping - Geo Table

Post by TomKerekes » Mon Feb 28, 2022 10:29 pm

It seems somehow GetParameter() is being somehow called before the MainPath is set in the CKinematics object.

Put a breakpoint in GetParameter and look at the call stack to see where it was called from.

The sequence should be:

#1 - create the Kinematics object
#2 - Set the MainPath in it
#3 - call Kinematics->Initialize(); is made which should make calls to GetParameter

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

MadTooler
Posts: 86
Joined: Thu Nov 08, 2018 11:57 pm

Re: Basic XY Screw Mapping - Geo Table

Post by MadTooler » Mon Feb 28, 2022 11:01 pm

Call stack at break in GetParameter before error...

> GCodeInterpreter.dll!CKinematics::GetParameter(const char * key, double * v) Line 784 C++
GCodeInterpreter.dll!CKinematicsBasicMapping::CKinematicsBasicMapping() Line 17 C++
GCodeInterpreter.dll!CCoordMotion::CCoordMotion(CKMotionDLL * KM) Line 152 C++
KMotionCNC.exe!CFrame::CFrame(CWnd * pParent) Line 34 C++
KMotionCNC.exe!CKMotionCNCApp::InitInstance() Line 85 C++
[External Code]
[Frames below may be incorrect and/or missing, no symbols loaded for mfc140d.dll]
KMotionCNC.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 26 C++
[External Code]

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

Re: Basic XY Screw Mapping - Geo Table

Post by TomKerekes » Mon Feb 28, 2022 11:46 pm

Looks like you are calling GetParameter from your Constructor rather than the Initialize function.

CKinematicsBasicMapping::CKinematicsBasicMapping() Line 17

Note the Initialize function is virtual. If you don't have one the one in the CKinematics base class is called which does nothing. So if you don't have an Initialize function you will need to add one in your class to override the base class.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

MadTooler
Posts: 86
Joined: Thu Nov 08, 2018 11:57 pm

Re: Basic XY Screw Mapping - Geo Table

Post by MadTooler » Tue Mar 01, 2022 12:23 am

That did it! Thanks!!!

I moved all I had in my constructor to initialize() since everything I was doing in the constructor is based upon my txt file. My constructor is now empty. Not sure if that is any problem.

I also tried cleaning up my other file reading function where I read in the screw data. That is giving me an error in debug with the way I am using "delete[]" to clear and resize my table array to match the required size by the txt file. I was really having a hard time with that before, but thought I got it right after doing a lot of reading on how all that should be done. It looks like the debug is enlightening me that what I did is not so great. However, when I run the release version, it does not give me any errors and gives the impression it is OK with my dirty code.

Exception thrown: read access violation.
it was 0xCDCDCDC4.
If there is a handler for this exception, the program may be safely continued.

I attached my kinematic. My issue starts at line 391 in .cpp. I did a bunch of reading a while back to understand this, but I apparently am still a knucklehead. Any idea why my approach is wrong?
Attachments
KinematicsBasicMapping.cpp
(13.12 KiB) Downloaded 40 times
KinematicsBasicMapping.h
(2.18 KiB) Downloaded 35 times

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

Re: Basic XY Screw Mapping - Geo Table

Post by TomKerekes » Tue Mar 01, 2022 1:32 am

I think the issue is that pointers are declared in your class but not initialized:

double* XscrewMap; // array pointers

this allocates the memory for the pointer but its value is indeterminate (garbage). In Debug mode VS initializes to CDCDCDCD (or something) to flag it is uninitialized.

Later you check if it is non-zero which it likely is random garbage or set by VS to CDCDCDCD. So it tries to release the previously allocated array that it should point to which hasn't been allocated and doesn't exist. So it reports an error.

I think a solution would be to initialize all these pointers to NULL in your constructor.
Regards,

Tom Kerekes
Dynomotion, Inc.

MadTooler
Posts: 86
Joined: Thu Nov 08, 2018 11:57 pm

Re: Basic XY Screw Mapping - Geo Table

Post by MadTooler » Tue Mar 01, 2022 1:50 am

Thanks again.

In my constructor, I set all to NULL like this:
XscrewMap = NULL;

That worked. What I don't understand is why when I did my initial test with only the X set null, Y did not have the problem. Good enough, I guess.

Finally back to my list of tasks.

edit: Figured it out. I had a check in place that was keeping it from getting there. Now it acts as expected.

Post Reply