PDA

View Full Version : QScriptEngine::popContext crash



tonka3000
19th September 2014, 15:57
Hy@everybody,

i have some troubles with the QScriptEngine and the context. I have a simple script (originally written in coffeescript). I call these script with the engine (with a new pushed context) and i get an crash after popContext().
The script is a simple recursive function which call itself 1000 times. I have created much more complex apps with QtScript and never had problems like these!


// Generated by CoffeeScript 1.7.1
(function() {
var param1, recursive;

param1 = 0;

recursive = function() {
param1 = param1 + 1;
if (param1 < 1000) {
return recursive();
}
};

recursive();

}).call(this);

My cpp code is very simple:



QScriptEngine engine;
QScriptContext* newContext = engine.pushContext();
engine.evaluate(jscode);
engine.popContext(); // after this point it crashes!


It crashes after engine.popContext(). I need the context to avoid variables in the global-object by default (and this snippet worked the last 2 months).

If i change the recursive counter in the script from 1000 to 10, it works well.

Working script:



// Generated by CoffeeScript 1.7.1
(function() {
var param1, recursive;

param1 = 0;

recursive = function() {
param1 = param1 + 1;
if (param1 < 10) {
return recursive();
}
};

recursive();

}).call(this);


I can reproduce this problems with 4.7.3 and 4.8.5 (i have not tested 5.x yet). I'm on a Windows 7 x64 SP1 machine with Visual Studio 2010 SP1 compiler.

Does anybody has this problem?
Can anybody reproduce this error on your windows/linux/mac machine?

BTW: This code works perfectly in node.js

Thanks in advance
Tonka

anda_skoa
20th September 2014, 10:35
It would be easier to try reproducing it if there was something to compile and run.

Cheers,
_

tonka3000
20th September 2014, 14:09
Hy anda_skoa,

i've write a simple console-program with an example script. At the moment (weekend) i've only have a mac and Qt 5.2, and here it is working.

I've add the QtCreator project to this thread.
The first argument of the app has to be the script-file.

Thanks for your help

Greetings
Tonka

anda_skoa
20th September 2014, 15:03
Works for me on Linux, 64bit, with both Qt 4.8.6 and 5.3.1

Cheers,
_

tonka3000
20th September 2014, 18:59
Thanks for testing. I think thats a windows only problem.
I hope somebody could test my example on a windows x64 system.

Greetings
Tonka

ars
20th September 2014, 20:54
Fails on windows 7, 64 bit with TDM GCC 4.8, 64 bit and Qt 4.7.3. Reducing the recursion to 814 in the js file gives success (recursion >= 815 gives failure).

Works without problems on linux 64 bit (gcc 4.8 and Qt 4.8.5).

Regards
ars

wysota
20th September 2014, 21:01
What is the backtrace upon the crash?

tonka3000
20th September 2014, 21:50
Ars, thanks for testing. It seems that this bug is only in windows (and I think only in x64).

The strangest thing about this error is that the script runs to the end, and then it breaks. At Friday I have debug this bug a little bit and seems that the callframe of the JavaScript Core is broken, but I can't find a reason why.

If I remove the context push (and pop), nothing breaks (but without the context I get garbage in my global object).

Does anybody know if it works in ein x86?

Greetings
Tonka

Added after 31 minutes:

There is an bugfix in qt 4.8.6 which solve some memory problems with recursiv function. Maybe this will fix the crash (could not test it myself before monday)

Greetings
Tonka

wysota
20th September 2014, 21:51
Have you tried simply replacing the global object and setting the original one as its prototype instead of using contexts?

tonka3000
21st September 2014, 07:08
wysota, thats an interresting idea, i will try that on monday.
Thanks

tonka3000
24th September 2014, 15:28
I've created a github-repo for the testapp https://github.com/tonka3000/QtScriptRecursiveFunctionBug

I've rebuild this bug on the following versions on windows

* 4.7.3 x64 (MSVC 2010 SP1 x64)
* 4.8.5 x86 (from Qt-Project.org MSVC2010)
* 4.8.6 x86 (from Qt-Project.org MSVC2010)
* 5.3.2 x86 (from Qt-Project.org MSVC2010)

In the next view days i try to implement my own context-system (with the global-object change tip from wysota).
I also will open a bug-report on the offical qt-bugtracker.

Greetings
Tonka

Added after 24 minutes:

here is the link to the bug-report on qt-project.org
https://bugreports.qt-project.org/browse/QTBUG-41558