Page 1 of 3

Open/Close program crash

Posted: Thu May 10, 2018 2:19 pm
by dinox
I’ve found a bug in my program that I’m hoping someone can help me resolve, or at least point me in the right direction.

I’ve written a Superbasic program to access a few megabytes of data using the Open and Close command to read in data from a few hundred files on a hard drive. The files contain map coordinates that are used in the program to draw palaeomaps.

The program works well for half an hour or so but then crashes with a typical error like:

At line 220 channel not open

The line 220 could be something like:

220 If EOF (#5) then exit loop

Where the #5 is the pipe to a file previously opened. The program can not be restarted at that point and just returns the same "channel not open" error.

After trying to solve this problem for some time I’ve come to the conclusion that there is a limit to the number of times the Open/Close command can access a file – 32764 times.

I don’t understand why there is this limit. Is there a counter for some reason? Is there anything I can do to increase that limit?

Re: Open/Close program crash

Posted: Thu May 10, 2018 2:34 pm
by Dave
As a side question.... How many megabytes of data are we talking about exactly?

Re: Open/Close program crash

Posted: Thu May 10, 2018 2:55 pm
by tofro
It would be interesting to know
  • What system are you using?
  • What ROM version?
  • Are you using OPEN or FOPEN?
  • Are you sure you close #5 before re-opening it?
This looks very much like a file descriptor leak. (System runs out of descriptors because you forgot to close something you opened.)

Tobias

Re: Open/Close program crash

Posted: Thu May 10, 2018 3:38 pm
by duncan
Another possibility is memory corruption if an SBASIC program won't restart. Have you tried the CLEAR command to reset the variables or checked with QPAC2 jobs menu to see it it reports SBASIC corrupted?

Re: Open/Close program crash

Posted: Thu May 10, 2018 4:33 pm
by dinox
Dave wrote:As a side question.... How many megabytes of data are we talking about exactly?
23.9 MByte (at the moment) for the most detailed palaeomaps.

Re: Open/Close program crash

Posted: Thu May 10, 2018 4:48 pm
by dinox
tofro wrote:It would be interesting to know
  • What system are you using?
  • What ROM version?
  • Are you using OPEN or FOPEN?
  • Are you sure you close #5 before re-opening it?
This looks very much like a file descriptor leak. (System runs out of descriptors because you forgot to close something you opened.)

Tobias
I'm using Q-emulator for windows 3.2.
QDOS version 1.10
CARE / TOOLKIT V2.12

I've used OPEN and OPEN_IN. FOPEN doesn't work. Do I need to install something for that to work?

Here's a simple program I wrote to try to test what's happening. It works up to the 32764 limit.

100 LET count_open=0: LET count_read=0
110 CLS
120 AT 0,25: PRINT "Read"
130 AT 5,0: PRINT "Data"
140 AT 0,0: PRINT "Open/Close"
150 REPeat first_loop
160 AT 1,1: PRINT count_open
170 OPEN_IN #5, flp1_african_160
180 REPeat loop
190 REMark Do something with data
200 AT 1,26: PRINT count_read
210 LET count_read=count_read+1
220 IF EOF (#5) THEN
230 CLOSE #5
240 EXIT loop
250 END IF
260 INPUT #5,strip$
270 AT 6,0: PRINT strip$
280 END REPeat loop
290 LET count_open=count_open+1
300 END REPeat first_loop
310 :
320 DEFine PROCedure resave
330 SAVE flp1_crash
340 END DEFine

Re: Open/Close program crash

Posted: Thu May 10, 2018 4:51 pm
by dinox
duncan wrote:Another possibility is memory corruption if an SBASIC program won't restart. Have you tried the CLEAR command to reset the variables or checked with QPAC2 jobs menu to see it it reports SBASIC corrupted?
Yes, I've tried the CLEAR command. It doesn't make any difference.

Re: Open/Close program crash

Posted: Thu May 10, 2018 5:40 pm
by tofro
QDOS 1.10 is actually a "JS" ROM, which should be relatively bug-free. You've most probably been running into the famous "second but last" one.

I have run your test program on QPC2/SMSQ/E 332 with no problems. It also runs fine on my MGG QL. The effect does, however show up in my JS QL.

The "32768 OPENs per session" is apparently a bug that was only fixed in MG and newer (according to an old article in QL World here: http://www.cowo.ch/downloads/198x_Sincl ... s-SQPP.pdf , see page 21 of August '87, middle column bottom)

You could try a Minerva ROM or an MGUK ROM which were even later versions of QDOS with (many, in the Minerva case and some in the MG case bugs fixed - Apparently the one you are hitting is fixed in both) and see if that changes anything. If you want to work around the bug, just leave the file open and re-position the file pointer to the beginning using TK2 commands instead of closing and re-opening it.

Tobias

Re: Open/Close program crash

Posted: Thu May 10, 2018 5:53 pm
by pjw
Instead of OPEN/CLOSE you may be able to alter your program slightly:
Dont close the channel, but use GET#5\ 0 and start afresh. Perhaps something along these lines..

Code: Select all

..
150 REPeat first_loop
155 OPEN_IN #5, flp1_african_160
160 AT 1,1: PRINT count_open
170 GET#5\0
180 REPeat loop
190 REMark Do something with data
200 AT 1,26: PRINT count_read
210 LET count_read=count_read+1
220 IF EOF (#5): EXIT loop
260 INPUT #5,strip$
270 AT 6,0: PRINT strip$
280 END REPeat loop
290 LET count_open=count_open+1
300 END REPeat first_loop
305 CLOSE #5: REMark When all is done..
..

Re: Open/Close program crash

Posted: Thu May 10, 2018 5:55 pm
by pjw
Oh well. Got my lines a bit crossed there, but you get the idea