Results 1 to 11 of 11

Thread: QScriptEngine::popContext crash

  1. #1
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Exclamation QScriptEngine::popContext crash

    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!

    Qt Code:
    1. // Generated by CoffeeScript 1.7.1
    2. (function() {
    3. var param1, recursive;
    4.  
    5. param1 = 0;
    6.  
    7. recursive = function() {
    8. param1 = param1 + 1;
    9. if (param1 < 1000) {
    10. return recursive();
    11. }
    12. };
    13.  
    14. recursive();
    15.  
    16. }).call(this);
    To copy to clipboard, switch view to plain text mode 

    My cpp code is very simple:

    Qt Code:
    1. QScriptEngine engine;
    2. QScriptContext* newContext = engine.pushContext();
    3. engine.evaluate(jscode);
    4. engine.popContext(); // after this point it crashes!
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. [CODE]// Generated by CoffeeScript 1.7.1
    2. (function() {
    3. var param1, recursive;
    4.  
    5. param1 = 0;
    6.  
    7. recursive = function() {
    8. param1 = param1 + 1;
    9. if (param1 < 10) {
    10. return recursive();
    11. }
    12. };
    13.  
    14. recursive();
    15.  
    16. }).call(this);
    To copy to clipboard, switch view to plain text mode 
    [/CODE]

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScriptEngine::popContext crash

    It would be easier to try reproducing it if there was something to compile and run.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScriptEngine::popContext crash

    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
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScriptEngine::popContext crash

    Works for me on Linux, 64bit, with both Qt 4.8.6 and 5.3.1

    Cheers,
    _

  5. #5
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScriptEngine::popContext crash

    Thanks for testing. I think thats a windows only problem.
    I hope somebody could test my example on a windows x64 system.

    Greetings
    Tonka

  6. #6
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScriptEngine::popContext crash

    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

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScriptEngine::popContext crash

    What is the backtrace upon the crash?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScriptEngine::popContext crash

    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
    Last edited by tonka3000; 20th September 2014 at 21:50.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScriptEngine::popContext crash

    Have you tried simply replacing the global object and setting the original one as its prototype instead of using contexts?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScriptEngine::popContext crash

    wysota, thats an interresting idea, i will try that on monday.
    Thanks

  11. #11
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QScriptEngine::popContext crash

    I've created a github-repo for the testapp https://github.com/tonka3000/QtScrip...iveFunctionBug

    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
    Last edited by tonka3000; 24th September 2014 at 15:28.

Similar Threads

  1. Crash on deletion of QScriptEngine object
    By rajeshclt3 in forum Qt Programming
    Replies: 4
    Last Post: 11th August 2011, 07:48
  2. QScriptEngine::importExtension()
    By wookoon in forum Qt Programming
    Replies: 8
    Last Post: 18th July 2011, 16:33
  3. Crash on deletion of QScriptEngine object
    By The_Fallen in forum Qt Programming
    Replies: 4
    Last Post: 11th March 2010, 09:27
  4. QScriptEngine
    By coderbob in forum Qt Programming
    Replies: 10
    Last Post: 25th January 2010, 16:12
  5. QScriptEngine in Qt 4.6.0
    By Fastman in forum Qt Programming
    Replies: 0
    Last Post: 25th December 2009, 21:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.