Page 1 of 1

NXC code compiles but rxe causes file error and aborts.

Posted: 30 Jan 2011, 01:28
by dsjove
The following code compiles but causes file error on execution.

Code: Select all

struct Movement
{
	int min;
	int max;
	int inc;
	int period;
	int valid;
};

Movement g_movements[4][4];
I am running the extended firmware and NCB 1.2.1.r3.

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 30 Jan 2011, 02:07
by mattallen37
Can you post the entire code?

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 30 Jan 2011, 13:34
by dsjove
It really is as simple as this. With the mentioned NXC compiler and extended firmware, the code below immediately aborts with File Error -9.
If I reduce the two dimensional array down to one, it runs.

Code: Select all

struct Movement
{
	int min;
	int max;
	int inc;
	int period;
	int valid;
};

Movement g_movements[4][4];

task main()
{
	while (true)
	{
	}
}

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 30 Jan 2011, 19:09
by muntoo
What does this do:

Code: Select all

struct Movement
{
	int min;
	int max;
	int inc;
	int period;
	int valid;
};

Movement g_movements[][];

task main()
{
	Movement pmTemp[];
	ArrayInit(pmTemp, NULL, 4);
	ArrayInit(g_movements, pmTemp, 4);

	while(1)
	{
		TextOut(0, 0, "It works!", 0);
	}
}

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 31 Jan 2011, 03:50
by dsjove
First usage now causes crash. A step in the right direction :)

g_movements[0][0].valid = true;

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 31 Jan 2011, 20:38
by afanofosc
Do you get the -9 error in all of the crashes you are experiencing?

ERR_INSANE_OFFSET -9 // 0xF7 CurrOffset != (DataSize - VarsCmd.CodespaceCount * 2)

That would indicate a low level compiler error of some kind. I must not be generating a valid RXE in this situation. What version/timestamp do you have on your compiler? Perhaps I have fixed a problem since your build? (I can always hope). If you are running with something other than the latest 1.2.1.r4 test release for Windows then there is a small hope that it is a bug that I have fixed. There definitely are bugs with structures in multi-dimensional arrays that I have seen in the past but I was thinking that basic structs (ones with no arrays in them) were possibly all better now.

Here's some code with comments in it that I have in my "tests\lingering" folder (as in lingering problems):

Code: Select all

// working as of 2009-01-29 JCH (with exceptions as noted below)
struct foobar {
  int a;
  int b;
};

struct location {
  int x;
  int y;
  string foo; // nested strings cause file error! if stored in 2-d array
  foobar test; // nested structs cause file error! if stored in 2-d array
  int buf[]; // nested arrays cause file error! if stored in 2-d array
};

task main() {
// initializing a 2-d+ array of structs causes File Error! abort
// if the struct contains nested arrays or structs
// !!! THIS IS EITHER A COMPILER BUG OR A FIRMWARE BUG !!!
  location array2[5][2];
  location array[5];
  location tmp;
//  ArrayInit(array, tmp, 2);
//  ArrayInit(array2, tmparray, 5);
  foobar flakey;
  int values[] = {1, 2, 3, 4};
  flakey.a = 12;
  flakey.b = 14;

  // scalar members
  array2[0][1].x = 2;    // valid code
  array2[0][1].x++;      // valid code
  array2[0][1].x += 14;  // valid code

  // string members
  array2[0][1].foo = "test";  // valid code
  array2[0][1].foo += "_123"; // valid code

  // nested structs
  array2[0][1].test.a = 2;    // valid code
  array2[0][1].test += 2;     // valid code
  array2[0][1].test = flakey; // valid code

  // array members
  array2[0][1].buf = values;  // valid code
  array2[0][1].buf[0] = 123;  // valid code

  tmp = array2[0][1];
  NumOut(0, LCD_LINE1, tmp.buf[0]);   // 123       (OKAY)
  NumOut(0, LCD_LINE2, tmp.test.a);   // 12        (OKAY)
  NumOut(0, LCD_LINE3, tmp.x);        // 17        (OKAY)
  TextOut(0, LCD_LINE4, tmp.foo);     // test_123  (OKAY)

  NumOut(0, LCD_LINE5, array2[0][1].buf[0]);  // 123       (OKAY)
  NumOut(0, LCD_LINE6, array2[0][1].test.a);  // 12        (OKAY)
  NumOut(0, LCD_LINE7, array2[0][1].x);       // 17        (OKAY)
//  TextOut(0, LCD_LINE8, array[0].foo);    // test_123  (OKAY)

  array2[0][1].test += 30;  // valid code
  NumOut(50, LCD_LINE6, array2[0][1].test.a);    // 42 (OKAY)
  array2[0][1].test.a += array2[0][1].test.b * array2[0][1].test.b; // valid code
  NumOut(50, LCD_LINE7, array2[0][1].test.a);    // 1978  (OKAY)
  array2[0][1].foo += "testing";  // valid code
  TextOut(0, LCD_LINE8, array2[0][1].foo);    // test_123testing  (OKAY)

  Wait(SEC_5);

  // scalar members
  array[0].x = 2;    // valid code
  array[0].x++;      // valid code
  array[0].x += 14;  // valid code

  // string members
  array[0].foo = "test";  // valid code
  array[0].foo += "_123"; // valid code

  // nested structs
  array[0].test.a = 2;    // valid code
  array[0].test.b = 2;    // valid code
  array[0].test += 2;     // valid code
  array[0].test = flakey; // valid code

  // array members
  array[0].buf = values;  // valid code
  array[0].buf[0] = 123;  // valid code

  tmp = array[0];
  NumOut(0, LCD_LINE1, tmp.buf[0]);   // 123       (OKAY)
  NumOut(0, LCD_LINE2, tmp.test.a);   // 12        (OKAY)
  NumOut(0, LCD_LINE3, tmp.x);        // 17        (OKAY)
  TextOut(0, LCD_LINE4, tmp.foo);     // test_123  (OKAY)

  NumOut(0, LCD_LINE5, array[0].buf[0]);  // 123       (OKAY)
  NumOut(0, LCD_LINE6, array[0].test.a);  // 12        (OKAY)
  NumOut(0, LCD_LINE7, array[0].x);       // 17        (OKAY)
//  TextOut(0, LCD_LINE8, array[0].foo);    // test_123  (OKAY)

  array[0].test += 30;  // valid code
  NumOut(50, LCD_LINE6, array[0].test.a);    // 42 (OKAY)
  array[0].test.a += array[0].test.b * array[0].test.b; // valid code
  NumOut(50, LCD_LINE7, array[0].test.a);    // 1978  (OKAY)
  array[0].foo += "testing";  // valid code
  TextOut(0, LCD_LINE8, array[0].foo);    // test_123testing  (OKAY)

/*
  array[0].y = array[0].x;
  tmp = array[0];
  tmp.x = 2;
  array[0] = tmp;
  NumOut(0, LCD_LINE1, array[0].x);
*/
  Wait(10000);
}
Can you try a few tests with a simple 4 byte struct (i.e., one long field in it) or 1 byte or 2 byte structs. Or multiples of 4 bytes? I will run some myself tonight.

John Hansen

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 31 Jan 2011, 21:16
by dsjove
Before I do the tests (and I still have some light sensor tests I promised you :) ), I am running the Mac NBC binary...
Next Byte Codes Compiler version 1.2 (1.2.1.r3, built Thu Jul 1 08:05:50 CDT 2010)

Re: NXC code compiles but rxe causes file error and aborts.

Posted: 31 Jan 2011, 23:05
by dsjove
error -9...

Fails...
struct Movement
{
// int min;
// int max;
int inc;
int period;
int valid;
};

// Succeeds
struct Movement
{
// int min;
// int max;
// int inc;
int period;
int valid;
};