Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Found interesting way to crash QML app.
Qt 6.11 is out! See what's new in the release blog

Found interesting way to crash QML app.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    I wanted to provide a function to a function as a parameter. I also wanted the default value to be an empty function. This however will crash if I use parameter=function(){} in the function definition:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Crash QML Default Function Parameter")
    
        // this crashes
        function crashFunction(functionptr=function(){}){ functionptr(); }
    
        // this does not
        function emptyfunc(){}
        function nocrashFunction(functionptr=emptyfunc){ functionptr(); }
    
        // this is how I fixed it
        function nocrashFunction(functionptr=null){
            if(functionptr){
                functionptr();
            }
        }
    }
    

    I solved this, but I find it interesting that it just kills the application. I would have expected some runtime error of some sort. I suppose this is in a top level function in the app so that exceptions are not caught by the JS engine?

    I don't need a fix, I just find this fascinating.

    C++ is a perfectly valid school of magic.

    JKSHJ 1 Reply Last reply
    2
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      Indeed, curious. The crash is in an indirect recursive call to QV4::Compiler::Codegen::defineFunction().

      Presumably this means that it is dying in the definition of the default value for functionptr. A simplified case triggers the same behavior:

      import QtQuick 2.15
      Item {
          function crashFunction(functionptr=function(){}){ }
      }
      

      Storing the function in a property is another workaround.

      property var crashFunction: function(functionptr=function(){}){ }
      

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      3
      • fcarneyF fcarney

        I wanted to provide a function to a function as a parameter. I also wanted the default value to be an empty function. This however will crash if I use parameter=function(){} in the function definition:

        import QtQuick 2.15
        import QtQuick.Window 2.15
        
        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Crash QML Default Function Parameter")
        
            // this crashes
            function crashFunction(functionptr=function(){}){ functionptr(); }
        
            // this does not
            function emptyfunc(){}
            function nocrashFunction(functionptr=emptyfunc){ functionptr(); }
        
            // this is how I fixed it
            function nocrashFunction(functionptr=null){
                if(functionptr){
                    functionptr();
                }
            }
        }
        

        I solved this, but I find it interesting that it just kills the application. I would have expected some runtime error of some sort. I suppose this is in a top level function in the app so that exceptions are not caught by the JS engine?

        I don't need a fix, I just find this fascinating.

        JKSHJ Online
        JKSHJ Online
        JKSH
        Moderators
        wrote on last edited by
        #3

        @fcarney said in Found interesting way to crash QML app.:

        I would have expected some runtime error of some sort.

        Indeed; crashing is never OK.

        Would you be willing to submit a bug report to https://bugreports.qt.io/ ?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by fcarney
          #4

          @JKSH said in Found interesting way to crash QML app.:

          Would you be willing to submit a bug report to https://bugreports.qt.io/ ?

          Yeah, I can do that.

          Edit:
          https://bugreports.qt.io/browse/QTBUG-98032

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved