discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

crash

J
jay@jdnd.co.uk
Thu, Dec 22, 2022 9:59 PM

so i have just crashed openscad for the first time.

i think its a circular dependency issue

in file attached "Connectors.scad" i accidentally left a number 1 where
i had copy passed some data and openscad just crashed with no
explanation.

re opening the file just instantly crashes openscad again

so i opened the file in gedit and found the problem witch i have
corrected in the attached file "Connectors (copy).scad" and im now back
in action.

but i wondered is anyone was interested in looking why it actually
crashes openscad rather than producing a warning or error

the offending line is line 168 and 177 of Connectors.scad

changing the lines from

function SocketF1_Depth(depth)  = depth
+(Socket_Thickness1()*2)+(Socket_Thickness2()*2)+(Socket_Clearance()*4);

function SocketF1_Depth()  = SocketF1_Depth(Socket_Depth1());

to

function SocketF_Depth(depth)  = depth
+(Socket_Thickness1()*2)+(Socket_Thickness2()*2)+(Socket_Clearance()*4);

function SocketF1_Depth()  = SocketF_Depth(Socket_Depth1());

fixes the problem

the rest of the attached files are dependences in case anyone tries to
re produce the crash

so i have just crashed openscad for the first time. i think its a circular dependency issue in file attached "Connectors.scad" i accidentally left a number 1 where i had copy passed some data and openscad just crashed with no explanation. re opening the file just instantly crashes openscad again so i opened the file in gedit and found the problem witch i have corrected in the attached file "Connectors (copy).scad" and im now back in action. but i wondered is anyone was interested in looking why it actually crashes openscad rather than producing a warning or error the offending line is line 168 and 177 of Connectors.scad changing the lines from function SocketF1_Depth(depth) = depth +(Socket_Thickness1()*2)+(Socket_Thickness2()*2)+(Socket_Clearance()*4); function SocketF1_Depth() = SocketF1_Depth(Socket_Depth1()); to function SocketF_Depth(depth) = depth +(Socket_Thickness1()*2)+(Socket_Thickness2()*2)+(Socket_Clearance()*4); function SocketF1_Depth() = SocketF_Depth(Socket_Depth1()); fixes the problem the rest of the attached files are dependences in case anyone tries to re produce the crash
JB
Jordan Brown
Thu, Dec 22, 2022 11:56 PM

Hint:  if you want developers - of any program - to try to diagnose
something, it's best to do whatever you can to provide a test case that
they can readily run, and reduce it to the smallest case that
demonstrates your problem.  Here you have given us programs that we
can't immediately run (because they include references to /home/jay/...,
and one of the files that appears to be required (Fuse Holder.scad) is
missing, and the total of the three files is somewhere around a thousand
lines.

Exactly what version of OpenSCAD are you running, on what platform? 
When you say "crashed", do you mean that the window disappeared, or that
it stopped responding?  If on a UNIX derivative, was there a core dump?

If I have "stop on first warning" turned off, I get

WARNING: Too many unnamed arguments supplied in file
Connectors.scad, line 173  

five times, and then OpenSCAD becomes unresponsive.

The problem is indeed with line 173:

function SocketF1_Depth()  = SocketF1_Depth(Socket_Depth1());

which is infinitely recursive - it calls itself, with no way to stop -
and has the call have one argument while the function has none.

Normally OpenSCAD detects infinite recursion, but I suspect that here
the checks may be optimized out of existence by tail recursion
optimization.[*]

[*] I've never bothered to fully understand the cases that qualify
as tail recursion, so I could easily be wrong here.

If I'm right, the result is more or less straightforwardly an infinite
loop and, since there's no way to stop  a running OpenSCAD program, it's
fatal.

Probably the most relevant open bug report is #1195
https://github.com/openscad/openscad/issues/1195, that previews should
run in a separate thread so they do not hang the UI.

Workaround:  other than fixing the infinite recursion in your program, I
suggest that you turn on "Stop on first warning" (in
Edit/Preferences/Advanced).  I suspect that you also have Design /
Automatic Reload and Preview turned on; unless you use an external
editor I would suggest turning that off.

Hint:  if you want developers - of any program - to try to diagnose something, it's best to do whatever you can to provide a test case that they can readily run, and reduce it to the smallest case that demonstrates your problem.  Here you have given us programs that we can't immediately run (because they include references to /home/jay/..., and one of the files that appears to be required (Fuse Holder.scad) is missing, and the total of the three files is somewhere around a thousand lines. Exactly what version of OpenSCAD are you running, on what platform?  When you say "crashed", do you mean that the window disappeared, or that it stopped responding?  If on a UNIX derivative, was there a core dump? If I have "stop on first warning" turned off, I get WARNING: Too many unnamed arguments supplied in file Connectors.scad, line 173  five times, and then OpenSCAD becomes unresponsive. The problem is indeed with line 173: function SocketF1_Depth() = SocketF1_Depth(Socket_Depth1()); which is infinitely recursive - it calls itself, with no way to stop - and has the call have one argument while the function has none. Normally OpenSCAD detects infinite recursion, but I suspect that here the checks may be optimized out of existence by tail recursion optimization.[*] [*] I've never bothered to fully understand the cases that qualify as tail recursion, so I could easily be wrong here. If I'm right, the result is more or less straightforwardly an infinite loop and, since there's no way to stop  a running OpenSCAD program, it's fatal. Probably the most relevant open bug report is #1195 <https://github.com/openscad/openscad/issues/1195>, that previews should run in a separate thread so they do not hang the UI. Workaround:  other than fixing the infinite recursion in your program, I suggest that you turn on "Stop on first warning" (in Edit/Preferences/Advanced).  I suspect that you also have Design / Automatic Reload and Preview turned on; unless you use an external editor I would suggest turning that off.
JB
Jordan Brown
Fri, Dec 23, 2022 1:22 AM

On 12/22/2022 3:56 PM, Jordan Brown wrote:

Workaround:  other than fixing the infinite recursion in your program,
I suggest that you turn on "Stop on first warning" (in
Edit/Preferences/Advanced).  I suspect that you also have Design /
Automatic Reload and Preview turned on; unless you use an external
editor I would suggest turning that off.

It occurs to me that "Stop on first warning" is a workaround only in
this particular case, where there's an error.  If there was undetected
infinite recursion without an error, that wouldn't help.

Turning off "Automatic Reload and Preview" would help - and you could do
it in an empty OpenSCAD, without loading the problematic file - so that
you can load a file that causes problems without triggering those problems.

Note also that OpenSCAD saves a backup copy before every run; look at
the console log for the name of the backup file.

On 12/22/2022 3:56 PM, Jordan Brown wrote: > Workaround:  other than fixing the infinite recursion in your program, > I suggest that you turn on "Stop on first warning" (in > Edit/Preferences/Advanced).  I suspect that you also have Design / > Automatic Reload and Preview turned on; unless you use an external > editor I would suggest turning that off. It occurs to me that "Stop on first warning" is a workaround only in this particular case, where there's an error.  If there was undetected infinite recursion *without* an error, that wouldn't help. Turning off "Automatic Reload and Preview" would help - and you could do it in an empty OpenSCAD, without loading the problematic file - so that you can load a file that causes problems without triggering those problems. Note also that OpenSCAD saves a backup copy before every run; look at the console log for the name of the backup file.
NH
nop head
Fri, Dec 23, 2022 9:26 AM

Can't you just open a new file, turn off Auto reload and then close
openscad and open the problem file?

On Fri, 23 Dec 2022 at 01:24, Jordan Brown openscad@jordan.maileater.net
wrote:

On 12/22/2022 3:56 PM, Jordan Brown wrote:

Workaround:  other than fixing the infinite recursion in your program, I
suggest that you turn on "Stop on first warning" (in
Edit/Preferences/Advanced).  I suspect that you also have Design /
Automatic Reload and Preview turned on; unless you use an external editor I
would suggest turning that off.

It occurs to me that "Stop on first warning" is a workaround only in this
particular case, where there's an error.  If there was undetected infinite
recursion without an error, that wouldn't help.

Turning off "Automatic Reload and Preview" would help - and you could do
it in an empty OpenSCAD, without loading the problematic file - so that you
can load a file that causes problems without triggering those problems.

Note also that OpenSCAD saves a backup copy before every run; look at the
console log for the name of the backup file.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Can't you just open a new file, turn off Auto reload and then close openscad and open the problem file? On Fri, 23 Dec 2022 at 01:24, Jordan Brown <openscad@jordan.maileater.net> wrote: > On 12/22/2022 3:56 PM, Jordan Brown wrote: > > Workaround: other than fixing the infinite recursion in your program, I > suggest that you turn on "Stop on first warning" (in > Edit/Preferences/Advanced). I suspect that you also have Design / > Automatic Reload and Preview turned on; unless you use an external editor I > would suggest turning that off. > > > > It occurs to me that "Stop on first warning" is a workaround only in this > particular case, where there's an error. If there was undetected infinite > recursion *without* an error, that wouldn't help. > > Turning off "Automatic Reload and Preview" would help - and you could do > it in an empty OpenSCAD, without loading the problematic file - so that you > can load a file that causes problems without triggering those problems. > > Note also that OpenSCAD saves a backup copy before every run; look at the > console log for the name of the backup file. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Dec 23, 2022 6:25 PM

On 12/23/2022 1:26 AM, nop head wrote:

Can't you just open a new file, turn off Auto reload and then close
openscad and open the problem file?

Yes.  You could do that once, and not have to do it again or, if you
like auto-refresh, you could do it and undo it each time that you have
such a problem.

I don't really see much of a win for auto-refresh if you use the
built-in editor, so I keep it off.

On 12/23/2022 1:26 AM, nop head wrote: > Can't you just open a new file, turn off Auto reload and then close > openscad and open the problem file? Yes.  You could do that once, and not have to do it again or, if you like auto-refresh, you could do it and undo it each time that you have such a problem. I don't really see much of a win for auto-refresh if you use the built-in editor, so I keep it off.
FH
Father Horton
Fri, Dec 23, 2022 8:20 PM

For what it's worth, OpenSCAD does catch infinite recursion even if tail
recursion is involved; it's just that the limit is much higher.

function recurse(i) =
let (dummy= (0 == i % 100) ? echo(i) : 0)
recurse(i+1);

echo(recurse(0));

This errors out after 1,000,000 recursions.

If I change the last line to:
0+recurse(i+1);
it errors out after 7,200 recursions.

The condition for tail recursion is that the recursion call has to invoke
the function while doing nothing else. The "0+" is something else, so it
disqualifies the function for tail recursion.

On Fri, Dec 23, 2022 at 12:27 PM Jordan Brown openscad@jordan.maileater.net
wrote:

On 12/23/2022 1:26 AM, nop head wrote:

Can't you just open a new file, turn off Auto reload and then close
openscad and open the problem file?

Yes.  You could do that once, and not have to do it again or, if you like
auto-refresh, you could do it and undo it each time that you have such a
problem.

I don't really see much of a win for auto-refresh if you use the built-in
editor, so I keep it off.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

For what it's worth, OpenSCAD does catch infinite recursion even if tail recursion is involved; it's just that the limit is much higher. function recurse(i) = let (dummy= (0 == i % 100) ? echo(i) : 0) recurse(i+1); echo(recurse(0)); This errors out after 1,000,000 recursions. If I change the last line to: 0+recurse(i+1); it errors out after 7,200 recursions. The condition for tail recursion is that the recursion call has to invoke the function while doing nothing else. The "0+" is something else, so it disqualifies the function for tail recursion. On Fri, Dec 23, 2022 at 12:27 PM Jordan Brown <openscad@jordan.maileater.net> wrote: > On 12/23/2022 1:26 AM, nop head wrote: > > Can't you just open a new file, turn off Auto reload and then close > openscad and open the problem file? > > > Yes. You could do that once, and not have to do it again or, if you like > auto-refresh, you could do it and undo it each time that you have such a > problem. > > I don't really see much of a win for auto-refresh if you use the built-in > editor, so I keep it off. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Dec 23, 2022 10:14 PM

On 12/23/2022 12:20 PM, Father Horton wrote:

For what it's worth, OpenSCAD does catch infinite recursion even if
tail recursion is involved; it's just that the limit is much higher.

Interesting.  I spoke too fast about this being straightforward infinite
recursion. The hang here is somehow tied up in the fact that there's
also an argument error.

This program crashes:

function foo()  = foo(0);
echo(foo());

But these two programs do not; they get a "recursion detected" error:

function foo(x)  = foo(0);
echo(foo());

function foo()  = foo();
echo(foo());

I've filed

 Infinite recursion with too many function arguments hangs #4459

On 12/23/2022 12:20 PM, Father Horton wrote: > For what it's worth, OpenSCAD does catch infinite recursion even if > tail recursion is involved; it's just that the limit is much higher. Interesting.  I spoke too fast about this being straightforward infinite recursion. The hang here is somehow tied up in the fact that there's *also* an argument error. This program crashes: function foo()  = foo(0); echo(foo()); But these two programs do not; they get a "recursion detected" error: function foo(x)  = foo(0); echo(foo()); function foo()  = foo(); echo(foo()); I've filed  Infinite recursion with too many function arguments hangs #4459
J
jay
Fri, Dec 23, 2022 10:43 PM

Well spotted. I dident realy look at why i just picked through the file untill i worked out how to make it run again. Sorry againSent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone
-------- Original message --------From: Jordan Brown openscad@jordan.maileater.net Date: 12/23/22  10:15 PM  (GMT+00:00) To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org, Father Horton fatherhorton@gmail.com Subject: [OpenSCAD] Re: crash
On 12/23/2022 12:20 PM, Father Horton
wrote:

    For what it's
      worth, OpenSCAD does catch infinite recursion even if tail
      recursion is involved; it's just that the limit is much
      higher.
  


Interesting.  I spoke too fast about this being straightforward
infinite recursion. The hang here is somehow tied up in the fact
that there's *also* an argument error.

This program crashes:

  function foo()  = foo(0);

echo(foo());

But these two programs do not; they get a "recursion detected"
  error:

  function foo(x)  = foo(0);

echo(foo());

  function foo()  = foo();

echo(foo());

I've filed
 Infinite recursion with too many function arguments hangs #4459
  
Well spotted. I dident realy look at why i just picked through the file untill i worked out how to make it run again. Sorry againSent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone -------- Original message --------From: Jordan Brown <openscad@jordan.maileater.net> Date: 12/23/22 10:15 PM (GMT+00:00) To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org>, Father Horton <fatherhorton@gmail.com> Subject: [OpenSCAD] Re: crash On 12/23/2022 12:20 PM, Father Horton wrote: For what it's worth, OpenSCAD does catch infinite recursion even if tail recursion is involved; it's just that the limit is much higher. Interesting.  I spoke too fast about this being straightforward infinite recursion. The hang here is somehow tied up in the fact that there's *also* an argument error. This program crashes: function foo()  = foo(0); echo(foo()); But these two programs do not; they get a "recursion detected" error: function foo(x)  = foo(0); echo(foo()); function foo()  = foo(); echo(foo()); I've filed  Infinite recursion with too many function arguments hangs #4459
JB
Jordan Brown
Sat, Dec 24, 2022 2:32 AM

On 12/23/2022 2:14 PM, Jordan Brown wrote:

Interesting.  I spoke too fast about this being straightforward
infinite recursion. The hang here is somehow tied up in the fact that
there's also an argument error.

Hans Loeblich writes in the Github issue:

This is entirely due to the "Error Log", which seems to take linear
time to append each error. This is why we should probably have some
configurable "Max Error Limit" in preferences (with a default of
maybe 100).
This could also potentially replace the "stop on first warning"
option (by setting the value to 1).
On 12/23/2022 2:14 PM, Jordan Brown wrote: > Interesting.  I spoke too fast about this being straightforward > infinite recursion. The hang here is somehow tied up in the fact that > there's *also* an argument error. Hans Loeblich writes in the Github issue: This is entirely due to the "Error Log", which seems to take linear time to append each error. This is why we should probably have some configurable "Max Error Limit" in preferences (with a default of maybe 100). This could also potentially replace the "stop on first warning" option (by setting the value to 1).