Pages: [1] 2   Go Down
Author Topic: BIG PROGRAM: Bath Overflow Error With /*...*/ When Preprocessing !!  (Read 1207 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 109
Posts: 4074
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anything in this thread http://forum.arduino.cc/index.php?topic=104245.0 help ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Norfolk UK
Offline Offline
Edison Member
*
Karma: 66
Posts: 2475
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley-wink
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 50
Posts: 2203
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25794
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Melbourne, Australia
Offline Offline
God Member
*****
Karma: 8
Posts: 567
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Windows serial port monitor: Tellurium | Arduino serial port debugging library: DBG | Cusom LCD char generator | Technical questions will only be answered in forum threads

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12551
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 14, 2013, 11:03:23 am by PeterH » Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 1
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...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 smiley
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
/***** test ********\

That backslash on the end of the first line is hard to spot.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

Logged

Pages: [1] 2   Go Up
Jump to: