|
Forum Index : Microcontroller and PC projects : My abuse of MsgBox()
| Author | Message | ||||
| KeepIS Guru Joined: 13/10/2014 Location: AustraliaPosts: 1945 |
Platform: ARM H7 MM.VER: 5.0503 Program size: 5,400 lines Flashpages: 2 Memory from the working Program. Flash: 153K (39%) Program (5474 lines) 231K (61%) Free RAM: 43K ( 8%) 401 Variables 42K ( 8%) General 406K (84%) Free Prior to getting the above program running, I had spent a few hours chasing why I got an error of NOT ENOUGH MEMORY every time I tried to Load the program or send it via USB to the H7. I had added around 20 lines of code throughout the program and though that I had done something stupid or I was having a hardware failure of some kind. Long story short, I have this code in the running program. [code] Watchdog OFF InfoStr = "Number of Steps = " + str$(NumSteps) + "~~First Step value = " + STR$(FirstStep,0,3) + MM_In_STR InfoStr = InfoStr + "~~Other Step value = " + str$(IF_BitStepVal,0,3) + MM_In_STR + "~~Total depth = " InfoStr = InfoStr + str$(IF_MaxBitHVal,0,3) + MM_In_STR + "~~Starting at = " + STR$(InputBitPos,0,3) + MM_In_STR IF MsgBox(InfoStr,"OK","Cancel") = 2 then StopFeedStopMove() Exit sub ENDIF [/code] That code above works, the Error happened when I had the text in the InfoStr on one line as in: IF MsgBox(string data,"OK","Cancel") = 2 then MM.Basic would only load about 2/3 of the file up to Watchdog OFF, the long Msgbox() line caused MM.Basic to crash out with "Not Enough Memory" error and crazy memory values. That long line my look crazy but on Notepad++ and my 32" Display it's not. The long input had been working for weeks until I added a couple of MM_In_STR to it. FYI MM_In_STR =" mm" or " in" So in future I'll try to not get lazy and place to many strings together as an input to MSGBOX(). There is obviously a limit and I abused it. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9755 |
5474 lines.....Crikey...... Smoke makes things work. When the smoke gets out, it stops! |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3470 |
Are you sure you didn't exceed 255 as a length of the string, InfoStr? (Although, if you did, I'm not sure why the error wouldn't have occurred before MsgBox.) PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
| KeepIS Guru Joined: 13/10/2014 Location: AustraliaPosts: 1945 |
If you reread the post you will note that I'm still using exactly the same display string length in both cases. The working version takes the construction of the string out of the MsgBox() Function display parameter input line, the length of the passed string parameter is the same for both, but it may appear longer if the string construction functions are included in the MsgBox function input parameter. Total length would be around half of the normal MM.Basic string length. Keep in mind the error is not occurring on run, it's on load with only 2/3 if the program loaded into the H7 when it aborts at that Msgbox code. The incomplete loaded program can still be run but of course the typical error is "cannot find label". The main reason for the post is for others to keep this kind of error in mind when the error code thrown on load suggests something more sinister. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
| panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1116 |
Hi Mike, Tried your code on my H7 and it loads OK (and runs)- some mods to get it to work standalone - see below. I can't see any issues with the build of InfoStr$ - is it possible there something using lots of memory or string size in your MM_In_STR string? panky ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
| KeepIS Guru Joined: 13/10/2014 Location: AustraliaPosts: 1945 |
If you look under the Code Box in my first post, you will see the line: That code above works, the Error happened when I had the text in the InfoStr on one line as in: MsgBox("Number of Steps = " + str$(NumSteps) + "~~First Step value = " + STR$(FirstStep,0,3) + MM_In_STR + "~~Other Step value = " + str$(IF_BitStepVal,0,3) + MM_In_STR + "~~Total depth = " + str$(IF_MaxBitHVal,0,3) + MM_In_STR + "~~Starting at = " + STR$(InputBitPos,0,3) + MM_In_STR,"OK","Cancel") = 2 then Like I mentioned 5,470 lines of code and it was working until I added MM_IN_STR which as indicated can be either " in" or " mm". Once I found the cause it was simply a matter of constructing the string first before passing it to the MsgBox function. This is not uncommon in many case other than the MsgBox function and usually results in an incorrect value being returned, however in this case the Error and effect were completely different. The program is now getting close to 6,000 lines and is working perfectly with the code snippet I posted. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
| panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1116 |
I understand,my error, sorry. Is MM_In_STR a litteral string or is it a function that returns either "mm" or "in"? Could the issue be related to the fact that MsgBox is expecting a string as the first argument and as strings are limited to 256 characters, the inline argument which is about 270 characters long would exceed the string buffer being used to parse the command? panky ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
| KeepIS Guru Joined: 13/10/2014 Location: AustraliaPosts: 1945 |
Hi panky, no need for apology, nice to know someone tried to help. It's just a string variable and it's set depending on the status of the selected measurement unit within the controller (H7), the user can change the Global units of measure at any time. Of course a string may be short in displayable text but it's allocation size is still large and dependant on MM.Basic. You can just try it with two long string together and see if it crashes, I doubt it, I think it's not related to length as such. It's a moot point as you really should not do what I did in first place, as I said abuse by a bit of bad programming, the only poor programming I have in the complete program and came back to bite me. I don't want to try it at the moment as I'm in the middle of adding more automation code. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10572 |
That line is 308 characters long. MMBasic statements also have a limit of 255 characters which is what caused the problem. I'll put in a better error message into the next release. Not sure how MM2 or MM+ handles this (anyone?) |
||||
| KeepIS Guru Joined: 13/10/2014 Location: AustraliaPosts: 1945 |
Precisely, it was plainly not due to the string length of the text for display, as you pointed out, it was the Parameter length limit. The annoying point was that the error message had no information pointing to the cause, not unusual of course, but once I narrowed down the cause of the "insufficient memory" error on load then it was a simple matter of constructing the string outside of the passed parameter input, as I normally do. That original parameter line started small and just kept getting a bit longer and longer over the past few weeks until it finally broke. It was bad practice / programming on my part whilst rushing to get ideas in my mind into program code. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |