[NXC] Insane offset?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

[NXC] Insane offset?

Post by spillerrec »

When trying to run a program like this:

Code: Select all

struct point{
	int X;
	int Y;
	byte Z;
};
point temp[1][1];

task main(){
	NumOut( 0, LCD_LINE1, temp[0][0] );
}
I get a "File error! -9".

Looking it up in "NBCCommon.h" I find this:

Code: Select all

#define ERR_INSANE_OFFSET   -9 
Insane offset? Does anyone have an idea of what this means?
After a bit of experimenting, it seems this error happens when the struct in the 2D array is larger than 4 bytes. If one of the ints are changed to byte or one of the variables are removed, it stops complaining...
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: [NXC] Insane offset?

Post by h-g-t »

Looked interesting so I did a search and found this from the national Instruments website :-

"This message means that an object in LabVIEW such as a wire or a loop tunnel does not pass an internal test known as a sanity check. If the errors are serious enough, LabVIEW exits because something has become very corrupted. Sanity checks occur before each save, to ensure that corrupted VIs are not written over good VIs."

Absolutely no idea why the error occurred though!
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: [NXC] Insane offset?

Post by m-goldberg »

I don't think you should be passing a struct as the third argument to NumOut. Doesn't NumOut only accept a scalar for its third argument? If so, since no scalar can be bigger than four bytes, that might explain the error message.
Regards, Morton
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: [NXC] Insane offset?

Post by spillerrec »

I did notice it and fixed it in my test copy, but I left it there as a treat for your guys. It does no change whatsoever, it seems to happen at the ArrayInit() call. But if the type is wrong, it usually just returns 0, I have never experienced it to crash the program.
It is a bit unexpected that it accepts the value though, but I didn't test if it could actually display it properly. Who knows... But there was also a similar case with pow(), I could pass an array of float into it, while it clearly didn't support it... (Again, no crash, it just returned 0.)
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: [NXC] Insane offset?

Post by afanofosc »

I spent way too long trying to figure this out today and ended up not making any real progress. The compiler is definitely generating a bad RXE file if you have a struct longer than 4 bytes in a 2d array. It is setting the offset to the first Dope Vector to 4 bytes greater than it should be and that causes one of the file header offsets to be 4 bytes too large which is causing the parsing of the RXE by the firmware to abort with the insane offset error.

If anyone would like to help me figure out what I am doing wrong I would be grateful.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: [NXC] Insane offset?

Post by muntoo »

Just in case this will save anyone some trouble, here's the code I used:

Code: Select all

struct point{
   int X;
   int Y;
   byte Z;
};
point temp[1][1];

task main(){
   NumOut( 0, LCD_LINE1, temp[0][0].X );
}
And here's the NBC:

Code: Select all

dseg	segment
;------- definitions -------
__ArrHelper__mainpoint_219_0_def	struct
X	sword
Y	sword
Z	byte
__ArrHelper__mainpoint_219_0_def	ends
____temp_2_0_def	struct
X	sword
Y	sword
Z	byte
____temp_2_0_def	ends
Location_def	struct
X	sword
Y	sword
Location_def	ends
__TextOutArgs_def	struct
Result	sbyte
Location	Location_def	
Text	byte[]
Options	dword
__TextOutArgs_def	ends
__temp_2_type_def	struct
X	sword
Y	sword
Z	byte
__temp_2_type_def	ends
__ArrHelper__mainpoint_228_0_type_def	struct
X	sword
Y	sword
Z	byte
__ArrHelper__mainpoint_228_0_type_def	ends
temp_type_type_def	struct
X	sword
Y	sword
Z	byte
temp_type_type_def	ends
;------- declarations -------
__signed_stack_002main	sdword	
__signed_stack_001main	sdword	
__signed_stack_004main	sdword	
__signed_stack_003main	sdword	
__D0main	sdword	
__constVal1	sbyte	1
____initialize_global_data_return	byte	
__ArrHelper__mainpoint_219_0	__ArrHelper__mainpoint_219_0_def	
____temp_2_0	____temp_2_0_def	
__TextOutArgs	__TextOutArgs_def	
__temp_2	__temp_2_type_def[]	
__ArrHelper__mainpoint_228_0	__ArrHelper__mainpoint_228_0_type_def[]	
temp	temp_type_type_def[][]	
dseg	ends
;------- code -------
thread main
	subcall __initialize_global_data, ____initialize_global_data_return
	set __signed_stack_001main, 0
	set __signed_stack_002main, 56
	set __signed_stack_003main, 0
	index __ArrHelper__mainpoint_228_0, temp, __signed_stack_003main
	set __signed_stack_004main, 0
	index __ArrHelper__mainpoint_219_0, __ArrHelper__mainpoint_228_0, __signed_stack_004main
	mov __D0main, __ArrHelper__mainpoint_219_0.X
	mov __TextOutArgs.Location.X, __signed_stack_001main
	mov __TextOutArgs.Location.Y, __signed_stack_002main
	set __TextOutArgs.Options, 0
	numtostr __TextOutArgs.Text, __D0main
	syscall 13, __TextOutArgs
	mov __D0main, __TextOutArgs.Result
	exit -1, -1
endt
;------------------------
subroutine __initialize_global_data
	arrinit __temp_2, ____temp_2_0, __constVal1
	arrinit temp, __temp_2, __constVal1
	subret ____initialize_global_data_return
ends
;------------------------
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
rghansen
Posts: 67
Joined: 12 Oct 2010, 17:44

Re: [NXC] Insane offset?

Post by rghansen »

afanofosc wrote:
If anyone would like to help me figure out what I am doing wrong I would be grateful.

John Hansen
Hi John,

After all you've done for us (and me) I'd love to help you with this but as I recall your compiler is written in Pascal and I'm not sure I can get it running on my Mac. But I'm a pretty good code reader.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests