Bug 43415 - SWT window crashes LOo
Summary: SWT window crashes LOo
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
3.4.0 release
Hardware: x86 (IA32) Linux (All)
: medium major
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-01 04:06 UTC by othman
Modified: 2013-02-28 15:57 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
SWTBrowserAddon.oxt (1.37 MB, application/vnd.openofficeorg.extension)
2011-12-01 04:06 UTC, othman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description othman 2011-12-01 04:06:03 UTC
Created attachment 54003 [details]
SWTBrowserAddon.oxt

In my linux box, I created an extension that uses SWT browser to launch an swt browser window.
when i close this window the whole Openoffice application freezes and becomes unresponsive for some cases the whole libreoffice crashes after closing the SWt window.
i suspect this to be related to some issue with GTK. if i remove a SWT call "display.dispose()' LOo dose'nt crash but my SWT window becomes unusable . if i try re-launch the SWT window again it doesn’t shows up. removing the display.dispose() solves the crash but makes my SWT window nu-usable. It seems the bug is related to this 'display.dispose()' SWT statement which causes the Loo to crash for some reason .
I'm providing the SWT code below. i also include a oxt demo to replicate this issue on Linux.

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.OpenWindowListener;
import org.eclipse.swt.browser.VisibilityWindowListener;
import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
*
* @author othman
*/
public class SWTBrowser {
   
    private Shell shell;
    // private Browser browser;
    private static final int WINDOW_WIDTH = 780;
    private static final int WINDOW_HEIGHT = 570;

    /**
     * SWTBrowser application entry point
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new SWTBrowser(args.length == 0 ? null : args[0]);
    }

    /**
     * Constructor
     *
     * @param location the initial location to display
     */
    public SWTBrowser(String location) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Main Window");
        shell.setLayout(new FillLayout());
        final Browser browser;
        try {
            browser = new Browser(shell, SWT.NONE);
        } catch (SWTError e) {
            System.out.println("Could not instantiate Browser: "
                    + e.getMessage());
            display.dispose();
            return;
        }
        initialize(display, browser);
        shell.open();
        browser.setUrl(location);
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
         display.dispose();

    }
   
    /* register WindowEvent listeners */
    static void initialize(final Display display, Browser browser) {
        browser.addOpenWindowListener(new OpenWindowListener() {

            @Override
            public void open(WindowEvent event) {
                if (!event.required) {
                    return; /* only do it if necessary */
                }
                Shell shell = new Shell(display);
                shell.setText("New Window");
                shell.setLayout(new FillLayout());
                Browser browser = new Browser(shell, SWT.NONE);
                initialize(display, browser);
                event.browser = browser;
            }
        });
        browser.addVisibilityWindowListener(new VisibilityWindowListener() {

            @Override
            public void hide(WindowEvent event) {
                Browser browser = (Browser) event.widget;
                Shell shell = browser.getShell();
                shell.setVisible(false);
            }

            @Override
            public void show(WindowEvent event) {
                Browser browser = (Browser) event.widget;
                final Shell shell = browser.getShell();
                if (event.location != null) {
                    shell.setLocation(event.location);
                }
                if (event.size != null) {
                    org.eclipse.swt.graphics.Point size = event.size;
                    shell.setSize(shell.computeSize(size.x, size.y));
                }
                shell.open();
            }
        });
        browser.addCloseWindowListener(new CloseWindowListener() {

            @Override
            public void close(WindowEvent event) {
                Browser browser = (Browser) event.widget;
                Shell shell = browser.getShell();
                shell.close();
            }
        });
    }


   
    /**
     * This class implements a CloseWindowListener for SWTBrowser
     */
    class BrowserCloseWindowListener implements CloseWindowListener {

        /**
         * Called when the parent window should be closed
         */
        @Override
        public void close(WindowEvent event) {
           
            // Close the parent window
            ((Browser) event.widget).getShell().close();
           

        }
    }

    /**
     * This class implements a LocationListener for SWTBrowser
     */
    class BrowserLocationListener implements LocationListener {
        // The address text box to update

        //private Text location;
        /**
         * Constructs an BrowserLocationListener
         *
         * @param text the address text box to update
         */
        public BrowserLocationListener() {
            // Store the address box for updates
        }

        /**
         * Called before the location changes
         *
         * @param event the event
         */
        @Override
        public void changing(LocationEvent event) {
            // Show the location that's loading
            // System.out.println("Loading " + event.location + "...");
        }

        /**
         * Called after the location changes
         *
         * @param event the event
         */
        @Override
        public void changed(LocationEvent event) {
            // Show the loaded location
            //  System.out.println("loaded location : " + event.location);
           /* if (event.location.contains("/callback?type=google")) {
            display.timerExec(2000, new Runnable() {

            public void run() {
            if (!shell.isDisposed()) {
            shell.dispose();
            }
            display.dispose();
            }
            });

            }*/
        }
    }
}

I'm using the following software:
Libreoffice 3.4
openJDK 6
Linux 3.1.2-1-desktop i686
System: openSUSE 11.4 (i586)
KDE: 4.6.00 (4.6.0) "release 6"
Comment 1 Petr Mladek 2011-12-08 05:40:22 UTC
There was a long discussion on the devel mailing list about his bug,
see http://lists.freedesktop.org/archives/libreoffice/2011-November/thread.html#21510

The result is that it is too specific and too complicated that nobody is interested into debugging it right now. There are many more important bugs that affect more people and they get higher priority and attention.

I am sorry, I lower the priority and severity. This bug can't block the release.

You might either debug it yourself with the hints from the mailing list or you need to pay someone who would fix it for you, or you might wait if anyone gets interested into it from some reasons.
Comment 2 othman 2011-12-09 11:06:49 UTC
yes i know there is little hope that this bug could be fixed.
it will probably be never fixed...
Comment 3 Julien Nabet 2012-07-10 20:43:10 UTC
othman: on pc Debian x86-64, with master sources (future 3.7) or 3.5 branch updated today, I made these tests with a brand new profile each time :
- install extension for All users
- restart LO
- I see a windows where there's a button "SWT Browser" but when I click on it, nothing at all.
- I can close the whole LO without problem
(noticed no specific logs whereas I use --enable-symbols option)

Here's Java version I use :
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-2)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
Comment 4 othman 2012-07-11 11:49:51 UTC
- I see a windows where there's a button "SWT Browser" but when I click on it,
nothing at all.

"nothing at all" means there is no  SWT window shows? 
the addon shows a simple SWT Browser window when the button clicked. if "nothing at all" means this window doesn't show then i have no Idea.

thanks.
Comment 5 Julien Nabet 2012-07-11 11:55:00 UTC
Yes, there's no "new window" when I click on this button.

Could you do this test on newer version (like 3.5.4) ? Perhaps there has been changing  on the api or config parameters.
Comment 6 othman 2012-07-11 17:38:03 UTC
what is the latest LO version?
i'll try later with latest LO version..but i can only install it from opensuse Yast2 and i don't know which LO yast does propose..i tried installing LO from source in linux but failed..so i only install it from yast opensuse 12.1
Comment 7 Julien Nabet 2012-07-11 19:40:24 UTC
Last LO version is 3.5.5, you can find .deb or .rpm (it seems Yast uses rpm packages) here :
http://www.libreoffice.org/download/?nodetect

You can also find daily builds here :
http://dev-builds.libreoffice.org/daily/
Comment 8 othman 2012-07-17 18:10:58 UTC
Sorry i still didn't tried with newer versions of LO sdk.
I'll let you know when i manage to try them.
I'm not sure why the swt browser code i use in addon test doesn’t work.
meanwhile you can try using any simple SWT browser code that you can find in the web to test with. just write a very simple java LO addon that calls a SWT Browser window upon a button push. just google for some java class of SWT Browser and use it for testing . We only need to know if newer versions of LO SDK can handle correctly a SWT Browser window. I don't have some swt code under my hand now beside the one i attached to this bug entry.
Comment 9 Julien Nabet 2012-07-17 18:16:58 UTC
About an addon for a browser, I don't know how to create one. If you have some time to create one, I could test it.

BTW when I remove the LO profile (~/.config/libreoffice) to use a brand new one, your addon is still there. Any idea ?
Comment 10 othman 2012-07-17 18:28:00 UTC
I have no Idea about the /config/libreoffice issue.

I'll try find sometime to search some other SWT Browser code to test with newer versions..Sorry if this will take time as i'm currently busy.

thanks for your interest in this bug.
Comment 11 othman 2012-07-19 14:35:41 UTC
I tried it in version 3.4  and can confirm that it still has the same problem that i described in this bug issue.

i'll need to upgrade to 3.5 and test. opensuse yast repos don't yet have the LO 3.5 version so i'll need to install it manually and there is probablity installation could fails : i experienced this last time i tried installing a newer version of LO. But i'll try and let you know.
Thank you again for your interest in investigating this bug.
Comment 12 Julien Nabet 2012-07-19 14:49:40 UTC
(In reply to comment #11)
> I tried it in version 3.4  and can confirm that it still has the same problem
> that i described in this bug issue.
> 
> i'll need to upgrade to 3.5 and test. opensuse yast repos don't yet have the LO
> 3.5 version so i'll need to install it manually and there is probablity
> installation could fails : i experienced this last time i tried installing a
> newer version of LO. But i'll try and let you know.
> Thank you again for your interest in investigating this bug.
Thank you for your feedback. To have a "clean"* base, you can use a brand new LO profile.

*I still don't know why your addon is still there whereas I recreated from scratch the LO profile. So I don't know if and which extra cleansing action it would need.
Comment 13 othman 2012-07-19 16:28:42 UTC
Hello,
I tried installing manually the 3.5 version but the rmp installation fails and says there are conflicts with other LO packages. I also had no luck installing Apache Oppenoffice 3.4.

It is probably better to wait until the 3.5 version is available for OpenSuse 12.1 repos. If you can direct me on how i can install 3.5 that would be nice.
Comment 14 Julien Nabet 2012-07-19 16:56:44 UTC
(In reply to comment #13)
> Hello,
> I tried installing manually the 3.5 version but the rmp installation fails and
> says there are conflicts with other LO packages. I also had no luck installing
> Apache Oppenoffice 3.4.
> 
You must uninstall LO OpenSuse packages. If 3.5 doesn't work, you can reinstall OpenSuse packages.
> It is probably better to wait until the 3.5 version is available for OpenSuse
> 12.1 repos. If you can direct me on how i can install 3.5 that would be nice.
Up to you :-)
Comment 15 othman 2012-07-21 02:01:10 UTC
BTW, I know why the oxt doesn't work for you : it is because you haven't the swt.jar for linux in the oxt jars libraries.
I'll need to create an oxt that includes the swt jar . have you browser this oxt to see if it includes the mentioned jar.
anyway i think if you want to debug this issue correctly you should have knowledge of SWT and how to create a java SWT LO extension and debug it. otherwise i don't think it will be easy to spot the issue.

try creating a simple LO java extension using SWT Browser code i provided. and add the swt jar for linux to class path. this is the only way to do a correct debugging of this issue.

thanks
Comment 16 Julien Nabet 2012-07-21 06:21:51 UTC
(In reply to comment #15)
> BTW, I know why the oxt doesn't work for you : it is because you haven't the
> swt.jar for linux in the oxt jars libraries.
You put swt.jar in lib part of your oxt

> I'll need to create an oxt that includes the swt jar . have you browser this
> oxt to see if it includes the mentioned jar.
> anyway i think if you want to debug this issue correctly you should have
> knowledge of SWT and how to create a java SWT LO extension and debug it.
> otherwise i don't think it will be easy to spot the issue.
I have no knowledge for both of these. I know some Java, that's all.

> 
> try creating a simple LO java extension using SWT Browser code i provided. and
> add the swt jar for linux to class path. this is the only way to do a correct
> debugging of this issue.
I thought I could retrieve a bt or interesting console logs since I compile with symbols.

Anyway, I'll be away from my computer for 2 weeks.
Comment 17 robinson 2013-02-28 03:10:38 UTC
What is happening, is that in SWT, display.dispose() calls OS.gdk_event_handler_set (0, 0, 0), and since GTK can only have one event handler at a time, SWT is effectively removing the event handler for [b]ALL[/b] of GTK. 

From the perspective of SWT, it's doing the correct thing, as it is cleaning up after itself, as it is removing the SWT specific event handler that it had added earlier.

call:  gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);  and GTK will work again.
-robinson


NOTE: the "SWT" way of doing this, is as follows.

eventCallback = new Callback (this, "eventProc", 2);
eventProc = eventCallback.getAddress ();
if (eventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
OS.gdk_event_handler_set (eventProc, 0, 0);
Comment 18 robinson 2013-02-28 03:12:59 UTC
(In reply to comment #17)
> NOTE: the "SWT" way of doing this, is as follows.
> 
> eventCallback = new Callback (this, "eventProc", 2);
> eventProc = eventCallback.getAddress ();
> if (eventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
> OS.gdk_event_handler_set (eventProc, 0, 0);

I should also mention, make sure that "eventProc" is the name of a Java method...
Comment 19 othman 2013-02-28 15:57:07 UTC
thank you robinson for solving this mystery that lasted almost 2 or 3 years!
for the eventProc you mentioned it should be a java method name. what method should this be ? i have attached my SWTBrowser.java class so i wonder what the eventProc should be in my case?