Bug 537294 - Context menu is not shown
Summary: Context menu is not shown
Status: CLOSED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2018-07-23 10:19 EDT by Nikita Shvinagir CLA
Modified: 2018-12-14 12:48 EST (History)
3 users (show)

See Also:


Attachments
JNI cpp file (1.05 KB, text/plain)
2018-07-24 10:13 EDT, Nikita Shvinagir CLA
no flags Details
JNI header file (398 bytes, text/plain)
2018-07-24 10:13 EDT, Nikita Shvinagir CLA
no flags Details
Sample SWT application (2.58 KB, application/octet-stream)
2018-07-24 10:14 EDT, Nikita Shvinagir CLA
no flags Details
Compiled JNI library (13.04 KB, application/octet-stream)
2018-07-24 10:14 EDT, Nikita Shvinagir CLA
no flags Details
The sample application sources (52.42 MB, application/x-gzip)
2018-07-30 05:39 EDT, Nikita Shvinagir CLA
no flags Details
Behaviour of sample (314.35 KB, video/webm)
2018-08-03 12:04 EDT, Xi Yan CLA
no flags Details
Desktop video (1.18 MB, video/webm)
2018-08-05 11:30 EDT, Nikita Shvinagir CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Shvinagir CLA 2018-07-23 10:19:25 EDT
I have a native window embedded into a Composite created with an EMBEDDED flag.
This composite listens for custom events in the non-UI thread from the native window.
In one of the handlers I am trying to create a context menu and display it.

```
public void onShowContextMenu() {
.......................
widget.getDisplay().syncExec(new Runnable() {
                        public void run() {

                            menu = new Menu(widget.getShell());
                            MenuItem item1 = new MenuItem(popupMenu, SWT.NONE);
                            item1.setText("Item 1");
                            MenuItem item2 = new MenuItem(popupMenu, SWT.NONE);
                            item2.setText("Item 2");
                            menu.setLocation(250, 150);
                            menu.setVisible(true);
                        }
                    });
................
}

```
The context menu is never displayed in this case.
Nevertheless, if I invoke the ```menu.setVisible(true);``` code in one of a selection listener bound to a button on a shell and press this button after the onShowContextMenu() is invoked, the context menu is displayed.
Comment 1 Xi Yan CLA 2018-07-23 10:24:15 EDT
Do you have a standalone snippet that reproduces the issue?
Comment 2 Nikita Shvinagir CLA 2018-07-23 10:52:58 EDT
Unfortunately, it's very hard to provide you with a workable standalone snippet as it would contain a private source code.
Our SWT widget is a simple composite I am trying to embed into SWT application.
A composite contains nothing. All it does is invoking a JNI function and passing its handle to a native application. The native application accepts the handle and embeds a native window into the window with the handle passed.
On specific circumstances, the native application invokes a Java callback code through an IPC approach.
I expect, that it is possible to create an SWT  popup menu from this code via the syncExec or asyncExec method.

Hope this additional info sheds a light on the case.
Comment 3 Nikita Shvinagir CLA 2018-07-23 10:56:42 EDT
Please note, that this behavior is reproducible in both SWT 3.8.2 and 4.8.

When I am trying the SWT 4.8, I can see the following error message in the console:
(SWT:18464): GLib-GObject-CRITICAL **: g_object_set_data: assertion 'G_IS_OBJECT (object)' failed
Comment 4 Xi Yan CLA 2018-07-23 11:16:55 EDT
Is this still an issue on SWT master as of today?
Comment 5 Nikita Shvinagir CLA 2018-07-23 11:24:07 EDT
It is reproducible with SWT 4.8. Let me check with the latest available SWT release.
Comment 6 Nikita Shvinagir CLA 2018-07-23 11:31:25 EDT
The same result with the swt-I20180722-2000-gtk-linux-x86_64 build.
The context menu is not displayed and the following error message in the console.

(SWT:19336): GLib-GObject-CRITICAL **: g_object_set_data: assertion 'G_IS_OBJECT (object)' failed.

This issue is reproducible on Linux only and after I click the embedded into a Composite native window and natively handle this click.
Comment 7 Xi Yan CLA 2018-07-23 11:53:26 EDT
Does the issue occur in both GTK2 and GTK3? Is it possible to provide the steps to reproduce the problem?
Comment 8 Nikita Shvinagir CLA 2018-07-24 07:39:40 EDT
The issue is reproducible both with GTK2 and 3. (I suppose I checked it correctly setting the SWT_GTK3 environment variable to "0" in my Idea project).
At the moment I do not have specific steps and code sample that can be used to reproduce this issue. I am trying to implement such a sample but it can take some time if it is possible at all.
Comment 9 Nikita Shvinagir CLA 2018-07-24 10:13:34 EDT
Created attachment 275103 [details]
JNI cpp file
Comment 10 Nikita Shvinagir CLA 2018-07-24 10:13:58 EDT
Created attachment 275104 [details]
JNI header file
Comment 11 Nikita Shvinagir CLA 2018-07-24 10:14:22 EDT
Created attachment 275105 [details]
Sample SWT application
Comment 12 Nikita Shvinagir CLA 2018-07-24 10:14:42 EDT
Created attachment 275106 [details]
Compiled JNI library
Comment 13 Nikita Shvinagir CLA 2018-07-24 10:16:20 EDT
Please take a look at the sample application.
To reproduce the issue, you need to run the HelloWorld.java file and, before the callback method will be invoked by JNI library, resize the application window.
Comment 14 Xi Yan CLA 2018-07-27 15:02:27 EDT
Hi Nikita, 

Sorry, if I ask, but I am having some trouble running the snippet. I am able to see shell and the "Show popup manually" button, but I seem to get an UnsatisfiedLinkError exception whenever it invokes the callback method. 

Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: org.eclipse.swt.tests.gtk.snippets.HelloWorld.sayHello(JJ)V
	at org.eclipse.swt.tests.gtk.snippets.HelloWorld.sayHello(Native Method)
	at org.eclipse.swt.tests.gtk.snippets.HelloWorld.lambda$0(HelloWorld.java:68)
	at java.lang.Thread.run(Thread.java:748)


I tried recompiling the library using

g++ -O -Wall -fPIC -DSWT_VERSION=4913    -DLINUX -DGTK -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-9.b11.fc28.x86_64//include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-9.b11.fc28.x86_64//include/linux -DJNI64 `pkg-config --cflags gtk+-3.0 gtk+-unix-print-3.0` -c HelloWorld.cpp

g++ -shared -fPIC  -s -o libhelloworld.so HelloWorld.o
Comment 15 Nikita Shvinagir CLA 2018-07-30 05:37:54 EDT
(In reply to Xi Yan from comment #14)
> Hi Nikita, 
> 
> Sorry, if I ask, but I am having some trouble running the snippet. I am able
> to see shell and the "Show popup manually" button, but I seem to get an
> UnsatisfiedLinkError exception whenever it invokes the callback method. 
> 
> Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError:
> org.eclipse.swt.tests.gtk.snippets.HelloWorld.sayHello(JJ)V
> 	at org.eclipse.swt.tests.gtk.snippets.HelloWorld.sayHello(Native Method)
> 	at
> org.eclipse.swt.tests.gtk.snippets.HelloWorld.lambda$0(HelloWorld.java:68)
> 	at java.lang.Thread.run(Thread.java:748)
> 
> 
> I tried recompiling the library using
> 
> g++ -O -Wall -fPIC -DSWT_VERSION=4913    -DLINUX -DGTK
> -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-9.b11.fc28.x86_64//include
> -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.172-9.b11.fc28.x86_64//include/linux
> -DJNI64 `pkg-config --cflags gtk+-3.0 gtk+-unix-print-3.0` -c HelloWorld.cpp
> 
> g++ -shared -fPIC  -s -o libhelloworld.so HelloWorld.o

Hi Xi,

I use the CMake 3.2.2 tool to compile the JNI library.
Please find the whole set of source files in the GZ attachment.
To build the lib, please run the ./compileLib command from the root folder.
Also, please do not forget to add the dependency on the libhelloworld.so file in the Java project.
Comment 16 Nikita Shvinagir CLA 2018-07-30 05:39:41 EDT
Created attachment 275187 [details]
The sample application sources
Comment 17 Nikita Shvinagir CLA 2018-07-30 06:00:50 EDT
Also, please note that I am compiling and running the snippet using the Oracle JDK 1.8.
Perhaps, it matters which JDK to use with the already built JNI SO-file.
Comment 18 Nikita Shvinagir CLA 2018-08-02 12:35:46 EDT
Hi,

Do you have any updates regarding this issue?
Perhaps, I can provide you with some additional information?
Comment 19 Xi Yan CLA 2018-08-03 11:57:25 EDT
(In reply to Nikita Shvinagir from comment #18)
> Hi,
> 
> Do you have any updates regarding this issue?
> Perhaps, I can provide you with some additional information?

Thanks for the sources, I have been able to run the snippet. However, I can't seem to reproduce the issue. The context menu pops up by the mouse pointer when the callback is invoked, and the following gets printed to the console. 

Hello World from C++!
handle = 44040218
windowHandle = 62914692
result = 1
In C++, about to enter Java
HelloWorld.callback
Thread.currentThread().getName() = Thread-0
Comment 20 Xi Yan CLA 2018-08-03 12:04:53 EDT
Created attachment 275256 [details]
Behaviour of sample

This is the behaviour that I am getting when the callback gets invoked.
Comment 21 Nikita Shvinagir CLA 2018-08-05 11:30:15 EDT
Created attachment 275275 [details]
Desktop video
Comment 22 Nikita Shvinagir CLA 2018-08-05 11:31:06 EDT
(In reply to Xi Yan from comment #20)
> Created attachment 275256 [details]
> Behaviour of sample
> 
> This is the behavior that I am getting when the callback gets invoked.

Yes, sometimes I observe the same behavior as in your video.

Could you please try resizing it dragging the bottom-left or top-left window corner?
Please do that several times as well.
I also attach the desktop video displaying the issue in my local environment.

P.S. Please note, that my local Ubuntu environment runs under the Virtual Box virtual machine. Perhaps, this matters.
Comment 23 Xi Yan CLA 2018-08-09 11:30:45 EDT
(In reply to Nikita Shvinagir from comment #22)

> Could you please try resizing it dragging the bottom-left or top-left window
> corner?
> Please do that several times as well.
> I also attach the desktop video displaying the issue in my local environment.

Hi, I cannot reproduce it on Fedora 28, it seems to work every time.
Comment 24 Nikita Shvinagir CLA 2018-08-09 12:10:19 EDT
Which architecture are you running the Fedora on? Linux (x86/GTK+), Linux (x86_64/GTK+), Linux (PPC64/GTK+) or Linux (PPC64LE/GTK+)
Comment 25 Nikita Shvinagir CLA 2018-08-09 12:11:29 EDT
(In reply to Xi Yan from comment #23)
> (In reply to Nikita Shvinagir from comment #22)
> 
> > Could you please try resizing it dragging the bottom-left or top-left window
> > corner?
> > Please do that several times as well.
> > I also attach the desktop video displaying the issue in my local environment.
> 
> Hi, I cannot reproduce it on Fedora 28, it seems to work every time.

Which architecture are you running the Fedora on? Linux (x86/GTK+), Linux (x86_64/GTK+), Linux (PPC64/GTK+) or Linux (PPC64LE/GTK+)

Also, please let me know the SWT version you are testing this sample on.
Comment 26 Xi Yan CLA 2018-08-09 15:36:53 EDT
(In reply to Nikita Shvinagir from comment #25)
> (In reply to Xi Yan from comment #23)
> > (In reply to Nikita Shvinagir from comment #22)
> > 
> > > Could you please try resizing it dragging the bottom-left or top-left window
> > > corner?
> > > Please do that several times as well.
> > > I also attach the desktop video displaying the issue in my local environment.
> > 
> > Hi, I cannot reproduce it on Fedora 28, it seems to work every time.
> 
> Which architecture are you running the Fedora on? Linux (x86/GTK+), Linux
> (x86_64/GTK+), Linux (PPC64/GTK+) or Linux (PPC64LE/GTK+)
> 
> Also, please let me know the SWT version you are testing this sample on.

I am running under x86_64 GNU/Linux, GTK3.22, and using SWT master as of today.
Comment 27 Nikita Shvinagir CLA 2018-08-10 04:19:10 EDT
(In reply to Xi Yan from comment #26)
> (In reply to Nikita Shvinagir from comment #25)
> > (In reply to Xi Yan from comment #23)
> > > (In reply to Nikita Shvinagir from comment #22)
> > > 
> > > > Could you please try resizing it dragging the bottom-left or top-left window
> > > > corner?
> > > > Please do that several times as well.
> > > > I also attach the desktop video displaying the issue in my local environment.
> > > 
> > > Hi, I cannot reproduce it on Fedora 28, it seems to work every time.
> > 
> > Which architecture are you running the Fedora on? Linux (x86/GTK+), Linux
> > (x86_64/GTK+), Linux (PPC64/GTK+) or Linux (PPC64LE/GTK+)
> > 
> > Also, please let me know the SWT version you are testing this sample on.
> 
> I am running under x86_64 GNU/Linux, GTK3.22, and using SWT master as of
> today.

Could you please check this behavior un an Ubuntu 16.04 environment?
I am setting up at the moment a Fedora environment to check whether it is not reproducible in my local Fedora environment as well.
Comment 28 Alexander Kurtakov CLA 2018-10-18 06:36:00 EDT
(In reply to Nikita Shvinagir from comment #27)
> (In reply to Xi Yan from comment #26)
> > (In reply to Nikita Shvinagir from comment #25)
> > > (In reply to Xi Yan from comment #23)
> > > > (In reply to Nikita Shvinagir from comment #22)
> > > > 
> > > > > Could you please try resizing it dragging the bottom-left or top-left window
> > > > > corner?
> > > > > Please do that several times as well.
> > > > > I also attach the desktop video displaying the issue in my local environment.
> > > > 
> > > > Hi, I cannot reproduce it on Fedora 28, it seems to work every time.
> > > 
> > > Which architecture are you running the Fedora on? Linux (x86/GTK+), Linux
> > > (x86_64/GTK+), Linux (PPC64/GTK+) or Linux (PPC64LE/GTK+)
> > > 
> > > Also, please let me know the SWT version you are testing this sample on.
> > 
> > I am running under x86_64 GNU/Linux, GTK3.22, and using SWT master as of
> > today.
> 
> Could you please check this behavior un an Ubuntu 16.04 environment?
> I am setting up at the moment a Fedora environment to check whether it is
> not reproducible in my local Fedora environment as well.

Actually can you rerproduce on Ubuntu 18.04? If not it's probably some issue with older GTK versions. Also what happened with your Fedora test?
Comment 29 Alexander Kurtakov CLA 2018-11-15 07:44:28 EST
Any progress with testing here?
Comment 30 Xi Yan CLA 2018-12-14 12:48:03 EST
Closing this ticket now as there has been no response in awhile. Please reopen it if you can reproduce the issue on GTK3.22/24 using SWT 4.10.