IDE12 Auto Format on Ubuntu 8.04 crashes

whenever I call "Auto Format"
I got an Index out of BoundsExecption: String Index out of range:1022

What's the code that it happens on? Can you post a minimal example with the same problem?

The comment part at begin seems to be the problem,
without it Auto Format works


//
// panorobot program for Olympus E510 DZ Kit
// - with serial LCD
// - with Nunchuk
// - EasyDriver 3
// - opto coupled remote focus and shutter trigger
// - Arduino Nano
//
// - 4 Eckbrennweiten des Kits und drei BWs für 70-300mm
// - mehrreihig
// - BKT
// - optional Delay
// - Timelaps with FL 0
// - Nullpunkt setzen, Anzeige der Bildzahl ab Nullpunkt zur gewählten BW
//

// Timelaps funktion ohne Bewegung evtl. einfach ohne Motorstrom?

//
// TODO: evtl. opt. kurze Erinnerung an AEL, AFL, RemoteSet, WB, no Liveview, Delay
//

#define VERSION "?fabso.lutum V16"

// set params for 7 certain focallengths FL / and 0 for timelapse without moving
#define MAX_INDEX 7
unsigned int FL_MM[] = {
0, 14, 40, 42, 150, 70, 200, 300};
unsigned int MAX_ROW[] = {
1, 4, 10, 10, 36, 17, 48, 72}; // max number of rows
long STEPS_FL_H[] = {
0, 39996, 15383, 14813, 4166, 8888, 3100, 2072};
long STEPS_FL_V[] = {
0, 49995, 19998, 19998, 5555, 11764, 4166, 2778};
unsigned int NPP[] ={
0,350,155,350,250,0,0,0};

// Pins for shuttercontrol
#define FOCUS_PIN 6
#define SHUTTER_PIN 7

//LCD Pins (only D3)
#include <SoftwareSerial.h>
#define rxPin 4 // rxPin is immaterial - not used - just make this an unused Arduino pin number
#define txPin 3

#include <Wire.h>

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

// NUNCHUK (Pins: A4 green, A5 yellow
static uint8_t nunchuck_buf[6]; // array to store nunchuck data
// nunchuck X Y
int NUN_X;
int NUN_Y;
// nunchuk buttons
int NUN_C;
int NUN_Z;

// Globals
byte LU_ZERO_SET = 0;
byte LU_FL_Index = 0;
byte LU_DONE;
byte LU_BKT = LOW;
unsigned int LU_Pics_to_do = 1; // change here init no of pics !!!
unsigned int LU_Pic_Delay = 1; // delay between two pics = wait before move
unsigned int LU_Rows_to_do = 1; // number of rows

// STEPPER (Pins: D9,D10,D11,D12)
// horizontal
int hsteppin = 9;
int hdirpin = 10;
long LU_STEPS_H = 0;
// vertikal
int vsteppin = 11;
int vdirpin = 12;
long LU_STEPS_V = 0;

// Cam data
int no_of_pics;
int row;
int CAM_position; // 0 at start, 1 if position is set
int CAM_hori_pics;// 0 at start, n if no of horizontal pics is set
int CAM_row_pics;// 1 at start, n if no of vertical pics is set
int CAM_MM = 0; // initial focal lenght
long CAM_STEPS = 0; // initial horizontal steps for 1 pic
long CAM_STEPS_ROW = 0; // initial vertical steps per row
int CAM_NPP; // cam NPP in tenth of mm

//-------------------------
void setup() {

// init LCD
delay(5000); // give LCD Time to warm up
pinMode(txPin, OUTPUT);
mySerial.begin(9600); // 9600 baud is LCD chip comm speed
mySerial.print("?G420");
delay(100); // pause to allow LCD EEPROM to program
mySerial.print("?c0"); // turn cursor off
delay(200);

// init nunchuck
Serial.begin(19200);
nunchuck_init(); // send the initilization handshake
delay(200);
nunchuck_zero();
nunchuck_get_data();
delay(200);

// cam pins
pinMode(FOCUS_PIN, OUTPUT);
pinMode(SHUTTER_PIN, OUTPUT);
digitalWrite(FOCUS_PIN, LOW);
digitalWrite(SHUTTER_PIN, LOW);

// vertikal motor pins
pinMode(vdirpin, OUTPUT);
pinMode(vsteppin, OUTPUT);

// horizontal motor pins
pinMode(hdirpin, OUTPUT);
pinMode(hsteppin, OUTPUT);

// initial values
LU_BKT = 0; // no bracketing
LU_Rows_to_do = 1; // 1 row

}

Does the same thing happen if you delete most of the sketch? Can you post a short example with the same problem?

I deleted some more lines, the bug happens as long as the arrays are initialized.


//
// panorobot program for Olympus E510 DZ Kit
// - with serial LCD
// - with Nunchuk
// - EasyDriver 3
// - opto coupled remote focus and shutter trigger
// - Arduino Nano
//
// - 4 Eckbrennweiten des Kits und drei BWs für 70-300mm
// - mehrreihig
// - BKT
// - optional Delay
// - Timelaps with FL 0
// - Nullpunkt setzen, Anzeige der Bildzahl ab Nullpunkt zur gewählten BW
//
//
// Timelaps funktion ohne Bewegung evtl. einfach ohne Motorstrom?
//
//
// TODO: evtl. opt. kurze Erinnerung an AEL, AFL, RemoteSet, WB, no Liveview, Delay
//

// set params for 7 certain focallengths FL / and 0 for timelapse without moving

unsigned int FL_MM[] = {
0, 14, 40, 42, 150, 70, 200, 300};
unsigned int MAX_ROW[] = {
1, 4, 10, 10, 36, 17, 48, 72}; // max number of rows
long STEPS_FL_H[] = {
0, 39996, 15383, 14813, 4166, 8888, 3100, 2072};
long STEPS_FL_V[] = {
0, 49995, 19998, 19998, 5555, 11764, 4166, 2778};
unsigned int NPP[] ={
0,350,155,350,250,0,0,0};

void setup() {
// init LCD
delay(5000); // give LCD Time to warm up
}

I had a problem with the space after the last closing curly brace. Does deleting it fix things for you?

no, I deleted all trailing blanks, but Auto Format still crashes

java.lang.StringIndexOutOfBoundsException: String index out of range: 1022
at java.lang.String.charAt(String.java:687)
at processing.app.tools.AutoFormat.getchr(AutoFormat.java:313)
at processing.app.tools.AutoFormat.cpp_comment(AutoFormat.java:243)
at processing.app.tools.AutoFormat.getnl(AutoFormat.java:370)
at processing.app.tools.AutoFormat.show(AutoFormat.java:675)
at processing.app.Editor$15.actionPerformed(Editor.java:728)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1220)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1261)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

same bug with windows xp:


java.lang.ArrayIndexOutOfBoundsException: 1024

at processing.app.tools.AutoFormat.getnl(AutoFormat.java:343)

at processing.app.tools.AutoFormat.show(AutoFormat.java:621)

at processing.app.Editor$15.actionPerformed(Editor.java:728)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.AbstractButton.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

It looks like the array in AutoFormat.java is overflowing

Seems interesting that it is occurring on multiple operating systems

:slight_smile:

Can you guys post an (even) shorter example with the problem?

Short example WinXP:

//
// Auto Format bug
unsigned int FL_MM[] = {
0, 14, 40, 42, 150, 70, 200, 300};

void setup() {
delay(5000); // give LCD Time to warm up
}

java.lang.ArrayIndexOutOfBoundsException: 1024

at processing.app.tools.AutoFormat.getnl(AutoFormat.java:343)

at processing.app.tools.AutoFormat.show(AutoFormat.java:621)

at processing.app.Editor$15.actionPerformed(Editor.java:728)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.AbstractButton.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)