← All bug reports

FS#317Debugger with -always-load-scripts

Type
Bug
Status
Closed
Resolution
Deferred
Category
QCAD (main)
Severity
Low
Priority
Low
Reported version
3 Beta 3
Target version
3.0.0
Operating system
Linux (All / Other)
Reported
2011-10-15 by hungerburg
Closed
2011-10-17 by andrew

Starting qcad Beta 3 with command line argument -always-load-scripts will bring up debugger:

Uncaught exception at /opt/qcad-3.0.0-beta3-prof-linux/scripts/library.js:2: RangeError: Maximum call stack size exceeded.
2 include("sprintf.js");

Comments (7)

andrew 2011-10-15

Not reproducible under Mac OS X. Will test under Linux.

hungerburg 2011-10-15

Does not look like a loop, rather some arbitrary limit of 25?

qsdb> .bt
#0  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/library.js:2
#1  <native>('library.js') at -1
#2  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/WidgetFactory.js:1
#3  <native>('WidgetFactory.js') at -1
#4  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/Plugin.js:1
#5  <native>('Plugin.js') at -1
#6  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/EAction.js:2
#7  <native>('scripts/EAction.js') at -1
#8  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/File/DrawingPreferences/PageSettings/PageSettings.js:1
#9  <native>('scripts/File/DrawingPreferences/PageSettings/PageSettings.js') at -1
#10  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/File/PrintPreview/Print.js:2
#11  <native>('scripts/File/PrintPreview/Print.js') at -1
#12  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/ImportExport/SvgExporter/SvgExporter.js:3
#13  <native>('SvgExporter.js') at -1
#14  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/ImportExport/SvgExporter/SvgExporterPG.js:1
#15  <native>('scripts/ImportExport/SvgExporter/SvgExporterPG.js') at -1
#16  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/BST/Schrank/SchrankVorlage.js:34
#17  <native>('SchrankVorlage.js') at -1
#18  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/BST/Schrank/SchrankDesign.js:39
#19  <native>('SchrankDesign.js') at -1
#20  <eval>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/BST/Schrank/Schrank.js:21
#21  <native>('scripts/BST/Schrank/Schrank.js') at -1
#22  <anonymous>() at /opt/qcad-3.0.0-beta3-prof-linux/scripts/Plugin.js:127
#23  loadPlugins(plugins = Plugin(  [ ... snip ... ]  ), splash = QSplashScreen) at scripts/autostart.js:305
#24  main() at scripts/autostart.js:477
#25  <global>() at scripts/autostart.js:557
hungerburg 2011-10-15

Ooops, reading it, there are some scripts of mine in there... How come, I don't understand.

hungerburg 2011-10-15

When I remove my scripts from QCAD the error the application starts without debugger. What may I do wrong?

andrew 2011-10-15

Nothing obvious, but it must have to do with one or more includes. You can try to wrap one include after another in your script plugin with a condition (only include if the class is not defined yet).
This is essentially what QCAD is doing without -always-load-scripts.

For example, for SvgExporterPG:

if (isNull(SvgExporterPG)) {
  include("scripts/ImportExport/SvgExporter/SvgExporterPG.js");
}

Of course that will make the -always-load-scripts option useless but it might help to pinpoint the problem to one particular include.

hungerburg 2011-10-16

It actually helps to only conditionally include SvgExporterPG.js. Funny thing is: including NewFile.js in the same frame will not exceed call stack size. And also including SvgExporterPG.js from the parent frame will not do so.

A simple recursion on the other hand can run 47618 times.

var counter = 0;
(function bomb() {
	qDebug("Bomb: " + counter++);
	bomb();
})();

How is the limit calculated? http://doc.qt.nokia.com/latest/qthread.html#setStackSize says, its up to the operating system, unless set explicitly.

hungerburg 2011-10-18

I am fine with deferral. The workaround is simple and does not impose much of an inconvenience and "always-load-scripts" is a developper extension anyways. Please note though, that its not about recursion, at least not infinite one: The stack trace does not show that. Instead its about loading, what otherwise would already have been loaded and thereby increasing stack size beyond some limit. The message of the error thrown is remarkably clear on that.

With the recursion sample I only wanted to address, that the limit is not the number of frames. The documented QThread structure is not exposed to scripting, or only in an obscure place. I Hope I dont steal your time with such a fringe problem.

Closure comment

Somewhat out of the scope for now. Not sure how recursions could be avoided with -always-load-scripts