NXC: Crash with SysfileSeek

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: Crash with SysfileSeek

Post by spillerrec »

I'm trying to make a Hex viewer which only reads the portion of the file which is shown on the screen (in order to read files which are much larger than 32kB).
However after a certain point in the file it starts reading incorrectly and after a while it crashes the brick and I have to remove the batteries. SysFileSeek does not at any point return any errors.

Here is a stripped down version of my code (with TextOut() instead of FontTextOut()):

Code: Select all

void ViewBinFile(string filename){
	//Load file
	unsigned int fsize;
	byte handle;
	unsigned int result = OpenFileRead(filename, fsize, handle);
	
	FileSeekType FSTargs;
	FSTargs.FileHandle = handle;
	FSTargs.Origin = SEEK_SET;
	
	unsigned int line_amount = fsize / 8 +1;	//TODO: find actual value
	unsigned int top_line = 0;
	byte buffer[64];
	
	bool viewing_file = true;
	while(viewing_file){
		FSTargs.Length = top_line*8;
		SysFileSeek(FSTargs);
		
		unsigned int read_size = 64;
		ReadBytes(handle, read_size, buffer);
		
		//Draw everything
		ClearScreen();
		
		//Show contents of buffer
		for(int ix=0; ix<8; ix++)
			for(int iy=0; iy<8; iy++){
				TextOut(ix*12, LCD_LINE1 -iy*8, FormatNum("%02X", buffer[ix+iy*8]) );
			}
		
		
		//Do input
		while( true ){
			if(ButtonPressed(BTNLEFT, true) && top_line >0){
				top_line--;
				break;
			}
			
			if(ButtonPressed(BTNRIGHT, true) && top_line < (line_amount-8)){
				top_line++;
				break;
			}
		}
		Wait( 100 );
	}
}


task main(){
	ViewBinFile( "test.rxe" );
}
Change the filename in the main task.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: Crash with SysfileSeek

Post by muntoo »

A .rxe file cannot read itself. (Just in case you're trying to do this.)
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: Crash with SysfileSeek

Post by spillerrec »

This was indeed what I was doing but the crash also happens when viewing the other programs. (It was just because it was the only .rxe file on my NXT at the moment, not that I need to be able to do it.)
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
timpattinson
Posts: 224
Joined: 30 Oct 2010, 04:10
Location: 127.0.0.1
Contact:

Re: NXC: Crash with SysfileSeek

Post by timpattinson »

You could have used the .rtm or .sys files. I think they are actuallly RXEs
Commit to Lego Mindstorms StackExchange Q&A http://area51.stackexchange.com/proposals/4105
Minboards IRC Channel #mindboards on Freenode
My blog: http://timpattinson.wordpress.com/
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: Crash with SysfileSeek

Post by spillerrec »

There was only a single .sys file which size was 6 bytes and the program reads 64 bytes at once, thus there would be no seeking when using that file. I could have uploaded some random file, I had just forgotten that you can't read the currently running program.

It is still not the issue however...
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: Crash with SysfileSeek

Post by muntoo »

timpattinson wrote:I think they are actuallly RXEs
Clarification: I meant the .rxe cannot read itself (because it already has an open handle?). It can read other .rxe files, though.

It runs OK on my NXT until it reaches the end of the file.

Try opening a large 1KB file. Scroll down for a while (to the bottom?). It freezes.

EDIT: In addition, when viewing a small >16 bytes file, it shows a bunch of "ADDBEDAB..." over and over, filling the screen. When you press the left button, it freezes. The right button doesn't seem to do anything other than refresh the drawing.
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: Crash with SysfileSeek

Post by spillerrec »

Yes, it crashes and shows random values when it is at the end of the file. However when opening a large file (KB size) it freezes long before it is near the end. (Until I'm sure I can fix this issue I'm not going to fix the other easier one.)
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: Crash with SysfileSeek

Post by afanofosc »

With the latest enhanced NBC/NXC firmware on my brick and the latest version of the compiler I do not experience any crashes/freezes with your program even when it reaches the end of a nearly 6kb file.

FYI, seeking only works with files opened for reading at this point. It may be that you have a slightly older and buggy version of the firmware on your NXT?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXC: Crash with SysfileSeek

Post by spillerrec »

I did try to update the firmware to the latest version. However while I thought I already had downloaded the latest BCC release, I had not...
It indeed works fine now. Updating your software (correctly) really does magic : )
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests