Hello Guest it is June 17, 2025, 06:44:58 PM

Author Topic: bug crash  (Read 4413 times)

0 Members and 1 Guest are viewing this topic.

bug crash
« on: January 06, 2025, 06:52:23 PM »
While attempting to figure out a problem with a m6 script I placed a line is the mcs file. This IMMEDIATLY crashed mach4 and consistantly crashed it on startup until I removed the offending line. I was attempting a C/C++ type statement with a boolean variable like the following.

   --log = msg..string.format((val == 1) ? "Not ": "" .. "Ignore all tool changes, selected tool was #%0.0f", selectedtool)

On the other hand, this completely fails in a function m6(). yes I know it's mostly commented out. I've been attempting to figure out why this fails.

local hreg, rc = mc.mcRegGetHandle(inst, "iRegs0/2010/IgnoreM6")
   --if (rc ~= mc.MERROR_NOERROR) then
   --   mc.mcCntlLog(inst, msg.."failure to acquire register handle. rc="..rc, "", -1)
   --   ignore = 0
   --else
   --   ignore = mc.mcRegGetValue(hreg)
   --   mc.mcCntlSetLastError(inst," IgnoreM6 set to " .. ignore)
   --end
    ignore = mc.mcRegGetValue(hreg)
   --log = msg..string.format((val == 1) ? "Not ": "" .. "Ignore all tool changes, selected tool was #%0.0f", selectedtool)
   -- Skip remaining tool change steps if ignoring tool changes
   if (ignore == 1) then
      log = msg..string.format("Ignoring all tool changes, selected tool was #%0.0f", selectedtool)
      mc.mcCntlLog(inst, log, "", -1)
      mc.mcCntlSetLastError(inst, log)
      return
   end



Some part of this crashes mach4 with NO error msg at all. I haven't dug into this enough to know where though. I suspect it might be the extra ) on the end of the string.format. This should NOT ever happen to a well developed program though. Error msg, yes. Crash NO.

   local hreg, rc = mc.mcRegGetHandle(inst, "iRegs0/2010/IgnoreM6")
   if (rc ~= mc.MERROR_NOERROR) then
       mc.mcCntlLog(inst, msg.."failure to acquire register handle. rc="..rc, "", -1)
   else
      ignore = mc.mcRegGetValueLong(hreg)
   end

   -- Skip remaining tool change steps if ignoring tool changes
   if (ignore == 1) then
      log = msg..string.format("Ignoring all tool changes, selected tool was #%0.0f", selectedtool))
      mc.mcCntlSetLastError(inst, log)
      return
   end

I've also discovered that the random NULL pointer is being written into the screen.xml file which causes mach4 to crash of course. sometimes it will tell you where the error is so you can use a text editor to fix the xml, other times I've had to use XMLnotepad to find and correct the extra character. This has been going on for years now. I remember working on a screenset 5-6 years ago and found the same thing. Randomly inserted null pointer into the screen xml file. Can I reliably  replicate the problem? nope. do I know it happens, yes it does. Just wish it'd be fixed. From the lack of activity on the forums though, it's like Mach4 is going by the wayside. No idea what it's being replaced with though.

Offline smurph

*
  • *
  •  1,574 1,574
  • "That there... that's an RV."
Re: bug crash
« Reply #1 on: January 08, 2025, 05:56:47 PM »
Quote from: cd_edwards
While attempting to figure out a problem with a m6 script I placed a line is the mcs file. This IMMEDIATLY crashed mach4 and consistantly crashed it on startup until I removed the offending line. I was attempting a C/C++ type statement with a boolean variable like the following.

   --log = msg..string.format((val == 1) ? "Not ": "" .. "Ignore all tool changes, selected tool was #%0.0f", selectedtool)

If you are editing the code in the Zerobrane editor, then hit F7 to try and compile the code.  Or just try running the code in the editor.  Either way, you will be given an error similar to the following "')' expected near '?'"  This should be a clue that the C/C++ style statement is not supported in LUA.  Always try proving out code in the editor instead of just trying to run it in Mach. 
local hreg, rc = mc.mcRegGetHandle(inst, "iRegs0/2010/IgnoreM6")

Quote from: cd_edwards
On the other hand, this completely fails in a function m6(). yes I know it's mostly commented out. I've been attempting to figure out why this fails.

   --if (rc ~= mc.MERROR_NOERROR) then
   --   mc.mcCntlLog(inst, msg.."failure to acquire register handle. rc="..rc, "", -1)
   --   ignore = 0
   --else
   --   ignore = mc.mcRegGetValue(hreg)
   --   mc.mcCntlSetLastError(inst," IgnoreM6 set to " .. ignore)
   --end
    ignore = mc.mcRegGetValue(hreg)
   --log = msg..string.format((val == 1) ? "Not ": "" .. "Ignore all tool changes, selected tool was #%0.0f", selectedtool)
   -- Skip remaining tool change steps if ignoring tool changes
   if (ignore == 1) then
      log = msg..string.format("Ignoring all tool changes, selected tool was #%0.0f", selectedtool)
      mc.mcCntlLog(inst, log, "", -1)
      mc.mcCntlSetLastError(inst, log)
      return
   end

It is VERY difficult for anyone to just read a code snippet and say what is wrong.  It would be FAR better to post the whole script so that we can tell if you are even retrieving the instance or correctly retrieving hReg.  If hReg is zero, then expect it to not work.  I can't even paste that snippet of code into Zerobran and try to run it to check it because I have no idea what might have come before the script snippet. 

Quote from: cd_edwards
Some part of this crashes mach4 with NO error msg at all. I haven't dug into this enough to know where though. I suspect it might be the extra ) on the end of the string.format. This should NOT ever happen to a well developed program though. Error msg, yes. Crash NO.

   local hreg, rc = mc.mcRegGetHandle(inst, "iRegs0/2010/IgnoreM6")
   if (rc ~= mc.MERROR_NOERROR) then
       mc.mcCntlLog(inst, msg.."failure to acquire register handle. rc="..rc, "", -1)
   else
      ignore = mc.mcRegGetValueLong(hreg)
   end

   -- Skip remaining tool change steps if ignoring tool changes
   if (ignore == 1) then
      log = msg..string.format("Ignoring all tool changes, selected tool was #%0.0f", selectedtool))
      mc.mcCntlSetLastError(inst, log)
      return
   end

Again, you can use the editor to compile or try to run the code and it would tell you that what you suspected was the error was indeed the error. 

Quote from: cd_edwards
I've also discovered that the random NULL pointer is being written into the screen.xml file which causes mach4 to crash of course. sometimes it will tell you where the error is so you can use a text editor to fix the xml, other times I've had to use XMLnotepad to find and correct the extra character. This has been going on for years now. I remember working on a screenset 5-6 years ago and found the same thing. Randomly inserted null pointer into the screen xml file. Can I reliably  replicate the problem? nope. do I know it happens, yes it does. Just wish it'd be fixed. From the lack of activity on the forums though, it's like Mach4 is going by the wayside. No idea what it's being replaced with though.

What character set and locale are you using in Windows?  What screen set are you using?  I'm not saying it doesn't happen, but I have never had this happen in my 14 years of editing Mach 4 screens.  If you copy and paste things from a web browser, it MAY be copying a character that just doesn't convert to the character set that the LUA editor is using.  This kind of sounds like something got pasted into the screen stuff.  There is nothing inside of Mach that will just insert a NULL character into the scripts out of the blue so I don't think this is a Mach GUI issue at all.  That and the fact that our support people are not getting tons of calls on this.  Like I said, I don't doubt it isn't happening to you.  I just mean that it is probably not happening for the reasons you suspect.  If you have to copy and paste stuff from a web browser, paste the text into Notepad first.  Not Notepad++ or any other advanced editor.  Just plain Notepad.  We are counting on its simplicity to remove non printable characters.  Then copy and past the text from Notepad into the Zerobrane script editor.

Steve
Re: bug crash
« Reply #2 on: January 09, 2025, 08:12:27 AM »
I'm using windows 10 with US keyboard and US char coding. So nothing you haven't seen before. I've attached my "modified screenset" to this.. I'll include my currently working m6 script as well. I still have NO idea on howto access a register from a screen button though. Registers are supposed to be the cat's meow and we are to use them, but if they don't work as advertised.

Anyways the attached screenset has a null in the middle of a line which defines the screen itself. this isn't a macro or something I've "cut and pasted in" from somewhere. This is directly in the screen definitions part of the xml. This time it tells you where. On another screenset, it appeared in the "mcvision" portion of the screen and I'm still working on what the hell I need to change so that portion of the screenset works. I've also attached my currently "working" copy of the screenset which does have the issue with vision. I get a random render error out of mach4 occasionally now as well. No clue where that's coming from though or howto trigger it yet.

Actually maybe I won't include the m6.mcs as it error's on me indicating I've already uploaded a file with this name.

Re: bug crash
« Reply #3 on: January 09, 2025, 08:40:45 AM »
I did figure out why register's and buttons were not working for me. "iregs0" and "iRegs0" are differant. Which should have not have been a surprise...
Re: bug crash
« Reply #4 on: January 09, 2025, 10:53:39 AM »
And Another example of extraneous characters being inserted into screen.lua

I was going back and forth editing a button and testing it. I got into a situation where G21/G20 would not switch the DRO values back and forth so I decided to exit m4 and resume m4.

Offline smurph

*
  • *
  •  1,574 1,574
  • "That there... that's an RV."
Re: bug crash
« Reply #5 on: January 14, 2025, 02:16:49 PM »
The forum won't let you upload a file with the same name.  Just attach it as m6-1.mcs and keep incrementing the dash number.  Or you can just copy paste the whole script into the reply between code tags.  There is a button on the reply that let's you do that.

<code>
paste M6 here
</code>

Just change <> to []

Steve

Offline smurph

*
  • *
  •  1,574 1,574
  • "That there... that's an RV."
Re: bug crash
« Reply #6 on: January 14, 2025, 04:20:57 PM »
And Another example of extraneous characters being inserted into screen.lua

it seems that the function that updates the surface map list is failing if there are no surface maps and the screen set is saved.  To fix it, extract the screen.xml from the .set file.  Then edit screen.xml with your favorite text editor and search for "INACTIV -" until you find as a strings property like:

            <Property name="Strings">INACTIVE - </Property>

Remove the character after the "-" character as it is the offending character.  It is hex 0x06 or Ctrl-F.  Save the screen.xml file and put it back into the screen set.  You should be able to open the screen set now.  Edit the screen and click on the surface mapping tab.  Then find the global script property and click on the ellipses to edit it.  Replace what is there with this:

Code: [Select]
function checkmaps(action)
local inst = mc.mcGetInstance("SMap list pop")
local MapNumber = {} --Might not want this to be local... but I guess I'll pass the info
local selected = scr.GetProperty("lst(Maps)", "Selected") -- Let's get the selected list entity in case we need it
local reg = mc.mcRegGetHandle(inst, "mcSurfaceMap0/smCommand")
resp, rc = mc.mcRegSendCommand(reg, "GET MAP LIST") --Grab the list of .dat files in the curr dir
local tkz = wx.wxStringTokenizer(resp, ("\n")); --Makes a token for each segment ending in \n
local i = 0 -- Counter
rc = scr.SetProperty("lst(Maps)","Strings","") --CLEAR LIST BEFORE WE WRITE TO IT
--The below function will update the maps list. I need to do it before and after an operation... so that's what we're gonna do
local function updatelist(tkz)
rc = scr.SetProperty("lst(Maps)","Strings","") --CLEAR LIST BEFORE WE WRITE TO IT
resp, rc = mc.mcRegSendCommand(reg, "GET MAP LIST") --Grab the list of .dat files in the curr dir
tkz = wx.wxStringTokenizer(resp, ("\n")); --Makes a token for each segment ending in \n
while (tkz:HasMoreTokens()) do --While we have more tokens, do this WORK
local token = tkz:GetNextToken()
local start, finish = string.find(tostring(token), ",1") --Here we're looking if the string has a ,1... if it does it's active
local start1, finish1 = string.find(tostring(token), ",0") --Here we're looking if the string has a ,0... if it does it's inactive
--"C:\\Mach4Hobby4866\\Profiles\\Mach4Mill\\zLevelMap0.dat,1\nC:\\Mach4Hobby4866\\Profiles\\Mach4Mill\\zLevelMap1.dat,1\n
if (start ~= nil) then
local new = string.gsub(tostring(token) , ",1", "") --Now I remove the ,1 or ,0 from the file name and put in table.
new = "ACTIVE -" .. tostring(new)
MapNumber[tostring(i)] = tostring(new)
local currcontent = scr.GetProperty("lst(Maps)", "Strings")
if (currcontent == "") then
newcontent = tostring(new) .. "|"
else
newcontent = tostring(currcontent) .. "|" .. tostring(new) .. "|"
end
rc = scr.SetProperty("lst(Maps)", "Strings", newcontent)
elseif (start1 ~= nil) then
local new = string.gsub(tostring(token) , ",0", "") --Now I remove the ,1 or ,0 from the file name and put in table.
if (new == "p") then
return
end
new = "INACTIVE -" .. tostring(new)
MapNumber[tostring(i)] = tostring(new)
local currcontent = scr.GetProperty("lst(Maps)", "Strings")
if (currcontent == "") then
newcontent = tostring(new) .. "|"
else
newcontent = tostring(currcontent) .. "|" .. tostring(new) .. "|"
end
rc = scr.SetProperty("lst(Maps)", "Strings", newcontent)
end
i = i + 1
end
end
updatelist(tkz) --UPDATE LIST EVERY TIME WE CALL THIS FUNCTION

if (action == "enable") and (tostring(selected) ~= "-1") then --IF ENABLE IS ACTION
--Here we're going to get the selected string from the map list and enable (or disable) it
--and we already have the map data because we ran this func
--now with the selected number I can check the map list and see if it's "ACTIVE"
str = MapNumber[tostring(selected)] --This is the map number as well...
start, finish = string.find(tostring(str), "INACTIVE") --Here we're looking if the string says active
if (start ~= nil) then
--We have to activate the map
selected = tonumber(selected) + 1
resp, rc = mc.mcRegSendCommand(reg, "SET MAP " .. tostring(selected) .. " ENABLED") --Grab the list of .dat files in the curr dir
updatelist(tkz) -- NOW UPDATE LIST AGAIN TO SHOW WE ACTIVATED IT
else
--Leave it alone
return
end
elseif (action == "disable") and (tostring(selected) ~= "-1") then --IF DISABLE IS ACTION
str = MapNumber[tostring(selected)] --This is the map number as well...
start, finish = string.find(tostring(str), "INACTIVE") --Here we're looking if the string says active
if (start == nil) then
--We have to activate the map
selected = tonumber(selected) + 1
resp, rc = mc.mcRegSendCommand(reg, "SET MAP " .. tostring(selected) .. " DISABLED") --Grab the list of .dat files in the curr dir
updatelist(tkz) -- NOW UPDATE LIST AGAIN TO SHOW WE ACTIVATED IT
else
return
end
end
rc = scr.SetProperty("lst(Maps)","Selected", tostring(selected))
return maps
end

Then click on the list box an edit the Strings property and set it blank (Get rid of "INACTIV -").
Then exist the screen editor and save the screen. 

This will fix either mcIndRouter-bad.set or mcIndRouter-bad2.set. 

Attached is a fixed mcIndRouter-bad2.set file.

Steve