Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web page runJavascript always crashes jvm when you try to use the returned object #72

Closed
mchistovib opened this issue Aug 25, 2022 · 4 comments

Comments

@mchistovib
Copy link

Describe the bug
Web page runJavascript always crashes jvm when you try to use the returned object

To Reproduce
Steps to reproduce the behavior:
Just run this code:

package ngMvp;

import io.qt.QtUtilities;
import io.qt.core.QCoreApplication;
import io.qt.core.QUrl;
import io.qt.core.Qt;
import io.qt.quick.QQuickWindow;
import io.qt.quick.QSGRendererInterface;
import io.qt.webengine.core.QWebEnginePage;
import io.qt.webengine.quick.QtWebEngineQuick;
import io.qt.webengine.widgets.QWebEngineView;
import io.qt.widgets.QApplication;

import java.net.URISyntaxException;
import java.util.function.Consumer;


public class WebPage {

    // test commit
    public static void main(String[] args) throws URISyntaxException {
        QtWebEngineQuick.initialize();
        QtUtilities.initializePackage("io.qt.webengine.widgets");
        QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_ShareOpenGLContexts);
        QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.OpenGLRhi);
        QApplication.initialize(args);

        QWebEngineView view = new QWebEngineView();
        QWebEnginePage page = new QWebEnginePage(view);
        view.setPage(page);
        page.load(new QUrl("http://info.cern.ch/"));
        page.runJavaScript("window", new Consumer<Object>() {
            @Override
            public void accept(Object o) {
               System.out.println("test "  + o); // always creates a crash if you interact with this object in any way
            }
        });
        view.show();

        QApplication.exec();
        QApplication.shutdown();
    }
}

It also crashes when you stay in the breakpoint of this line for too long - I assume it happens because debugger is calling .toString() for the returned o object

Expected behavior
It shouldn't crash at all.

System (please complete the following information):

  • OS: Windows 10
  • Java version 11
  • QtJambi version 6.2.6
  • Qt version 6.2.5
@mchistovib
Copy link
Author

I assume that result object is destroyed on cpp code before being returned to this callback

@omix
Copy link
Contributor

omix commented Aug 25, 2022

There seems to be a problem when QVariant is converted to Java object. The actual value is converted to QHash but QHash.toString() crashes because there is something broken.
Can you confirm that the program does not crash when you change as follows?

System.out.println("test " + o.getClass());

@mchistovib
Copy link
Author

@omix getClass() doesn't crash because it's not using the native object link. Any method that uses QtJambi_LibraryUtilities.internal.nativeId(this) in it crashes the app, for example toString(), size(), etc

@omix
Copy link
Contributor

omix commented Aug 25, 2022

QVariant containing QMap was erroneously converted to Java QHash not QMap. Thus, accessing the QMap value from Java led to crash.
Is solved in the next release.

omix added a commit that referenced this issue Sep 2, 2022
Bugfix Issue #73
Bugfix Issue #72
Bugfix Issue #71
@omix omix closed this as completed Sep 2, 2022
omix added a commit that referenced this issue Jul 25, 2023
Bugfix Issue #73
Bugfix Issue #72
Bugfix Issue #71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants