Go Down

Topic: BIG PROGRAM: Bath Overflow Error With /*...*/ When Preprocessing !! (Read 1 time) previous topic - next topic

pizzayolo

Hi all!

WHAT I HAVE:
I am using the Arduino IDE 1.04, on a winXp machine (XP-2002 family sp3 RAM 1 Gb, java jre7 installed, in addition to jre1.5.0_06), and a Mega2560.

WHAT I DO:
After having experienced quite a bit with the Arduino Uno and getting used to it,
I am developing now a larger program for the Arduino Mega, with the goal to make a data acquisition instrument (with a specific hardware and user interface).

MY PROBLEM:
I am experiencing "stack overflow errors" (arduino Exception in thread java.lang.StackOverflowError) at the stage of pre-processing a large Arduino Mega program (itself made of a series of .ino files, see later);

At the present stage (very large program already, but not yet full-blown), I noticed that I start to get unexpected problems at the stage of preprocessing, and those problem appear as *not linked* to simply silly write-up errors (for example given in file:///C:/Documents%20and%20Settings/Francois/Mes%20documents/arduino-1.0.4/reference/Guide_Troubleshooting.html: (section Why do I get a java.lang.StackOverflowError when I try to compile my program?)
Now, at the present stage of the program that compiles, loads and runs fine on an ArduinoMega 2560: then when adding simply two "separation lines" in an ino file of the project, as separator for the eye, such as:
/*  *********************************************************************** */
... I get Exception in thread java.lang.StackOverflowError (!), such as:

Exception in thread "Thread-6" java.lang.StackOverflowError
   at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
   at java.util.regex.Pattern$Neg.match(Pattern.java:4598)
   at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3366)
   at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
   at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
   at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
(....)

This is one simple example that I could track, but it seems now to occur after a series of some simple (and sound to me)  modifications of the program: I got trapped several times, with the only escape being to trash the version, and recover a previous "compiling" version of the program, and start adding modifications, while hitting "check compilation" every 2-3 lines addition.
Furthermore, a given program may now compile at a given time of the day, and will not compile at another time...

It seems that I am hitting the wall ! And yet, there is still about 4Kb of available SRAM (between heap and stack) that I want to use for more growth of my program !!

SUSPECTED REASON:
I suspect that the stack depth is getting insufficient for the preprocessing.
I need yet my program to grow still quite larger, and I foresee that the problems with "stack overflow errors" will become insurmountable without major overhaul of the program (suppressing all comments ??!!!, shortening all variable names ???), a prospect that I am very reluctant to embark into, especially because the stack overflow error seems to occur now erratically.

HELP NEEDED:
Is there a way to force a larger max stack size ?
Is there a way to circumvent the above problem (without changing my present program), and allowing further growth of the program ?


HANDLING OF MY LARGE GROWING PROGRAM:
I have started from small sub-units that I had tested each, and then have started to assemble progressively a quite a big program, taking care to verify compilation (and saving the successive versions at intermediate steps of the growing program). I have followed  the practice to split the whole program into several .ino files (see later). I have also the practice to heavily annotate the program with comments, either with //, or enclosed within /* ... */. I have also the practice to use VERY long variable names, so that their use is more explicit (for the sake of future maintenance of the program)

I have followed advices on the forum and on http://arduinodilettante.wordpress.com/2011/03/10/multiple-file-sketches/, on the practice to split the whole program into several .ino files, and taking critical attention to the alphabetic orders of the names of the different files : (in aphabetical order of the files, 1st: file with the name of the folder, but only comments in it, followed by an .ino file containing #includes, followed by an .ino file containing only #defines, followed by an .ino file containing only global variables, followed by a number of .ino files containing various function, and last (name starting with Z), the .ino file containing the SETUP  {} , and the LOOP {}.

THANKS FOR YOUR HELP !

UKHeliBob

Does anything in this thread http://forum.arduino.cc/index.php?topic=104245.0 help ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

pizzayolo

No,
It does not help.
I  have already taken care of avoiding the use of 3 "!" in a row anywhere in the files

Riva

Quote
Is there a way to circumvent the above problem (without changing my present program), and allowing further growth of the program ?

Maybe you could try CodeBlocks. Not used it properly yet myself but putting the '#include <Arduino.h>' should be the only code change needed to compile it unless your using libraries. You will have to find out how to add libraries as I have not got that far yet.
http://forum.arduino.cc/index.php?action=unread;boards=5,67,10,11,66,12,15,17,21,22,23,24,25,29;ALL

pizzayolo

Hi,
thanks for this interesting suggestion!
I have actually libraries (a bunch of them), so that I need to find the way to use them.
I will try.


In the mean time, and as a remark on the arduino Ide,
I am not at all used to java; I am at the level of simply using the Arduino Ide, that itself uses java.

>>> What is the way (under winxp), to set the java parameters -Xms <size> (initial mem size), -Xmx <size> (max mem size), -Xss <size> (stack size), so that the Arduino Ide will have more resource ?

When bluntly trying in the command window to type: java -Xss number, (and number between 1000 and 100M), I get
"Invalid thread stack size: -Xss"
"Error: could not create the Java Virtual Machine."
"Error: A fatal exception has occurred. Program will exit"

wildbill

Quote
It seems that I am hitting the wall ! And yet, there is still about 4Kb of available SRAM (between heap and stack) that I want to use for more growth of my program !!


Since you have a compile time error, the issue does not to appear to be with RAM available on the arduino. Can you reduce what's running on your XP machine? Preferably add some RAM to your windows box too - it would be much happier with a bit more.

Nick Gammon

Quote
I have followed  the practice to split the whole program into several .ino files (see later).


I disagree with the idea of splitting programs into multiple .ino files. They get concatenated into one huge file which probably doesn't totally help.

I strongly suggest breaking your project into .cpp and .h files as appropriate. Each one becomes a separate compilation unit and that should help with such issues.

Quote
Bath Overflow Error


Certainly that's unusual. ;)
http://www.gammon.com.au/electronics

holmes4

The first few lines of the Java stack dump are never useful any clue to your problem lies in the last 20 or so lines. It's very unlikely that the problem has any thing to do with the size of the stack. Its most likely a double you have a bad construct in your code and the IDE can't cope with it.

Mark

PaulS

One way to narrow down the issue is to NOT use /* */ comments.

Use // comments, instead.

Yes, commenting every line can be a pain, but comments are not supposed to be novels. If you really need a large block of comments, simplifying the code is in order. Or, reference a section in a text file that documents what the /* */ no longer document.

An embedded quote or double slash comment in a block comment can confuse the parser.

AWOL

...and sometimes, a misplaced backslash causes untold grief
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

aarondc


One way to narrow down the issue is to NOT use /* */ comments.

Use // comments, instead.

Yes, commenting every line can be a pain, but comments are not supposed to be novels. If you really need a large block of comments, simplifying the code is in order. Or, reference a section in a text file that documents what the /* */ no longer document.

An embedded quote or double slash comment in a block comment can confuse the parser.


Good grief. If that's true in any way, shape or form then it's a very sad state of affairs.
Windows serial port monitor: Tellurium | Arduino serial port debugging library: DBG | Cusom LCD char generator | Technical questions will only be answered in forum threads

PeterH

#11
Jul 14, 2013, 06:01 pm Last Edit: Jul 14, 2013, 06:03 pm by PeterH Reason: 1
The problem is happening in the bit of the Arduino IDE that mucks about with your code before the compiler is called. You should eventually be able to resolve the problem by trial and error / guesswork to figure out which part of your code is confusing the IDE, and changing it to something the IDE can cope with. However, if you want, you can avoid all of that by moving all of your code out of the Arduino .ino sketch file and putting it into a .cpp file. Then the Arduino won't muck about with it and it will simply be passed to the compiler as-is. (Any remaining compiler issues are now your own problem!)

In order to convert your code from 'Arduino' to 'C++' you would need to add a #include for Arduino.h, and add function prototypes for any of your functions that get called before they are defined - in other words, you'd have to follow the conventional approach for coding C++ applications.


Good grief. If that's true in any way, shape or form then it's a very sad state of affairs.


The Arduino pre-processor is pretty crude and it would not be at all surprising that there are valid C++ code constructs that it can't handle.
I only provide help via the forum - please do not contact me for private consultancy.

tarquinio


...and sometimes, a misplaced backslash causes untold grief

Bingo! I was having the same issue for a couple days now, ended up reading this topic, and after changing all of my /* */ to //, in the end I discovered my untold grief did in fact come from a misplaced \. Tkx AWOL :)

Nick Gammon

If you use /* type comments you are always tempted to do this:

Code: [Select]

/***** test ********\


That backslash on the end of the first line is hard to spot.
http://www.gammon.com.au/electronics

pizzayolo

Hi

One way to narrow down the issue is to NOT use /* */ comments.

Use // comments, instead.

Yes, commenting every line can be a pain, but comments are not supposed to be novels. If you really need a large block of comments, simplifying the code is in order. Or, reference a section in a text file that documents what the /* */ no longer document.

An embedded quote or double slash comment in a block comment can confuse the parser.
,

I did the painfull work of converting by numerous /* ... */ blocks, to long series of single lines of comments starting with //.
It seems to have done the trick: preprocessing is now going to completion!


Go Up