Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140465

AOT compiled (cachegen) qml crashes program when attempting to call a function on a destroyed context

XMLWordPrintable

    • All

      Given this QML code:

      pragma ComponentBehavior: Bound
      import QtQuick
      
      Window {
        id: root
        visible: true
        title: qsTr("Cachegen Crash")
      
        property Component a: Rectangle {
          color: 'red'
          TapHandler {
            function doit() { }
            onTapped: {
              root.choice = 1
              doit()
            }
          }
        }
      
        property Component b: Rectangle {
          color: 'blue'
          TapHandler {
            function doit() { }
            onTapped: {
              root.choice = 0
              doit()
            }
          }
        }
      
        property int choice: 0
      
        Loader {
          anchors.fill: parent
          sourceComponent: switch(root.choice) {
                           case 0: return root.a
                           case 1: return root.b
                           }
        }
      }
      
      

      Repeatedly clicking the rectangle causes the following assert to be hit:

      QQmlVMEMetaObject: Internal error - attempted to evaluate a function in an invalid context
      qrc:/qt/qml/bug_cachegen_loader/Main.qml:15: TypeError: Property 'doit' of object [null] is not a function
      QQmlVMEMetaObject: Internal error - attempted to evaluate a function in an invalid context
      qrc:/qt/qml/bug_cachegen_loader/Main.qml:26: TypeError: Property 'doit' of object [null] is not a function
      QQmlVMEMetaObject: Internal error - attempted to evaluate a function in an invalid context
      ASSERT: "function" in file C:\Users\qt\work\qt\qtdeclarative\src\qml\qml\qqml.cpp, line 2181
      

      In release mode this is a hard crash.
      Excerpt of the backtrace

      4  qt_assert                                                                                                                                                                          qassert.cpp                         104  0x7ffb43ff81f9 
      5  `QQmlPrivate::AOTCompiledContext::callQmlContextPropertyLookup'::`2'::<lambda_1>::operator()<bool (__cdecl *)(QV4::ExecutionEngine *,QV4::ArrowFunction *,QObject *,void * *,int)> qqml.cpp                            2182 0x7ffb459b37ee 
      6  QQmlPrivate::AOTCompiledContext::callQmlContextPropertyLookup                                                                                                                      qqml.cpp                            2186 0x7ffb459a1aea 
      7  `QmlCacheGeneratedCode::_qt_qml_bug_cachegen_loader_Main_qml::<lambda_4>::operator()'::`20'::<lambda_1>::operator()                                                                appbug_cachegen_loader_Main_qml.cpp 471  0x7ff7b1259371 
      8  QmlCacheGeneratedCode::_qt_qml_bug_cachegen_loader_Main_qml::<lambda_4>::operator()                                                                                                appbug_cachegen_loader_Main_qml.cpp 478  0x7ff7b125928d 
      9  QmlCacheGeneratedCode::_qt_qml_bug_cachegen_loader_Main_qml::<lambda_4>::<lambda_invoker_cdecl>                                                                                    appbug_cachegen_loader_Main_qml.cpp 502  0x7ff7b1259310 
      10 `QV4::Moth::VME::exec'::`2'::<lambda_1>::operator()                                                                                                                                qv4vme_moth.cpp                     447  0x7ffb4595273f 
      11 QV4::coerceAndCall<AOTCompiledMetaMethod,`QV4::Moth::VME::exec'::`2'::<lambda_1>>                                                                                                  qv4jscall_p.h                       565  0x7ffb45957202 
      12 QV4::Moth::VME::exec                                                                                                                                                               qv4vme_moth.cpp                     448  0x7ffb45945e38 
      13 QV4::Function::call                                                                                                                                                                qv4function.cpp                     37   0x7ffb457926da 
      14 QQmlJavaScriptExpression::evaluate                                                                                                                                                 qqmljavascriptexpression.cpp        270  0x7ffb45ad343d 
      15 QQmlBoundSignalExpression::evaluate                                                                                                                                                qqmlboundsignal.cpp                 197  0x7ffb459f31ff 
      16 QQmlBoundSignal_callback                                                                                                                                                           qqmlboundsignal.cpp                 316  0x7ffb459f3849 
      17 QQmlNotifier::emitNotify                                                                                                                                                           qqmlnotifier.cpp                    71   0x7ffb45b47d1a 
      18 QQmlData::signalEmitted                                                                                                                                                            qqmlengine.cpp                      347  0x7ffb45a567ba
      

      One minor thing to note is that enabling QML debugging and attempting to debug the process on startup bypasses the AOT compiled functions, resulting in a difference in behavior between Debug and Release mode.

        1. QTBUG-140465.tar.gz
          0.8 kB
          Fabian Kosmale
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtqmlteam Qt Qml Team User
            pdegoeje Pieter de Goeje
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes