Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Execute swt program success inside Eclipse, but failure execute it as a standalone jar file

The difference could be that the standalone SWT app uses GTK3, but the one launched from Eclipse uses GTK2 (because Eclipse was launched with the environment variable SWT_GTK3=0, or maybe because the Eclipse launcher set this variable due to issues with latest GTK3 versions).

To see what's going on, you can use
                System.out.println(System.getenv("SWT_GTK3"));

Or, in recent I-builds from the 4.5 stream, do this after a Display has been created:
                System.out.println(System.getProperty("org.eclipse.swt.internal.gtk.version"));

See also https://www.eclipse.org/swt/faq.php#gtkstartup

Markus



From:        Gulfstrean Wang <gulfstream.wang@xxxxxxxxx>
To:        "Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
Date:        2014-09-29 11:34
Subject:        Re: [platform-swt-dev] Execute swt program success inside Eclipse, but failure execute it as a standalone jar file
Sent by:        platform-swt-dev-bounces@xxxxxxxxxxx




There are two error. For the first error, the code is the most simple, it is:

package testswt;

import org.eclipse.jface.window.*;
import org.eclipse.swt.widgets.*;


public class CTestSWT extends ApplicationWindow
{
    public static void main(String[] args)
    {
        Display.setAppName("Test SWT");

        CTestSWT frObj = new CTestSWT();
        frObj.setBlockOnOpen(true);
        frObj.open();
        Display.getCurrent().dispose();
    }

    public CTestSWT()
    {
        super(null);
    }

    @Override
    protected Control createContents(Composite parent)
    {
        getShell().setText("Test SWT");
        getShell().setSize(300, 300);
        getShell().setLocation(200, 200);

        return parent;
    }
}


For the second error. I use the Font object in the while loop, the object's life cycle is in one loop. Because I try to change different font size, and the size must be set at the moment of creating a Font object. After call the function "computeSize" of Label and get the perfect size of the Label, I will try another size of font. So I need another Font object, and dispose the old one because it is no useful. That is why dispose the font object in the code.

Further more, these code execute success inside the Eclipse, and execute success as a standalone jar file with old SWT version, so I do not think the reason is dispose of the font object.

Thank you!



在 2014年09月29日 16:45, Alex Blewitt 写道:
> Your ‘most simple SWT program’ is still calling your many-line CTestSWT code which disposes fonts before they are used. Simplify further so that there is no separate CTestSWT and remove all instances of dispose-before-use before testing further, and report back when you have fixed it.
>
> Alex
>
> On 29 Sep 2014, at 08:57, Gulfstrean Wang <gulfstream.wang@xxxxxxxxx> wrote:
>
>> We will get more information about this question. In fact, there are two errors displayed.
>>
>> The first error is that some error message are print in the console while execute the SWT program as a jar file in the console. The messages are showed as blew:
>>
>> (Test SWT:5234): Gtk-CRITICAL **: gtk_hsv_to_rgb: assertion 's >= 0.0 && s <= 1.0' failed
>>
>> But the error messages are not printed if I execute the SWT program inside the Eclipse. The error occurs even if the program is a the most simple SWT program, such as:
>>
>>
>> package testswt;
>>
>> import org.eclipse.jface.window.*;
>> import org.eclipse.swt.widgets.*;
>>
>>
>> public class CTestSWT extends ApplicationWindow
>> {
>>                  public static void main(String[] args)
>>                  {
>>                                   Display.setAppName("Test SWT");
>>                                  
>>                                   CTestSWT frObj = new CTestSWT();
>>                                   frObj.setBlockOnOpen(true);
>>                                   frObj.open();
>>                                   Display.getCurrent().dispose();
>>                  }
>>                  
>>                  public CTestSWT()
>>                  {
>>                                   super(null);
>>                  }
>>                  
>>                  @Override
>>                  protected Control createContents(Composite parent)
>>                  {
>>                                   getShell().setText("Test SWT");
>>                                   getShell().setSize(300, 300);
>>                                   getShell().setLocation(200, 200);
>>                                  
>>                                   return parent;
>>                  }
>> }
>>
>>
>> To the most simple SWT program, this error does not present any wrong with the GUI. But to some dialog, I get the wrong display as fig_error.png (in attachments) while I execute it as standalone jar file. The correct display as fig_correct.png (in attachments) while I execute it inside the Eclipse. There are not any different with the two executions except that one is executed as a standalone jar file in console with the error message printed like above, and other is executed inside the Eclipse without any error message printed.
>>
>>
>>
>>
>> The second error is about the function "computeSize" of the class Label. The simple code file is CTestSWT.java (in attachments). This code try to find a suitable font size to meet the require of the Label width. So a loop is set up, the font size is changed in the loop, and the prefect Label width with these font size is compute by call "computeSize" of the class Label. After the suitable size is found, it is applied to the Label object.
>>
>> This code is executed inside the Eclipse, and the execution result of the "computeSize" is as blew.
>>
>> Point {75, 14}   200
>> Point {82, 16}   200
>> Point {86, 17}   200
>> Point {95, 20}   200
>> Point {104, 21}   200
>> Point {110, 23}   200
>> Point {129, 25}   200
>> Point {135, 26}   200
>> Point {139, 28}   200
>> Point {154, 30}   200
>> Point {160, 31}   200
>> Point {168, 33}   200
>> Point {179, 35}   200
>> Point {189, 36}   200
>> Point {195, 38}   200
>> Point {208, 40}   200
>>
>> But if I run the program as a standalone jar file in the console, the error occurs. The loop becomes a endless loop because the results of "computeSize" with font size loop become error, like blew.
>>
>> Point {75, 14}   200
>> Point {75, 16}   200
>> Point {75, 17}   200
>> Point {75, 20}   200
>> Point {75, 21}   200
>> Point {75, 23}   200
>> Point {75, 25}   200
>> Point {75, 26}   200
>> Point {75, 28}   200
>> Point {75, 30}   200
>> Point {75, 31}   200
>> Point {75, 33}   200
>> Point {75, 35}   200
>> Point {75, 36}   200
>> Point {75, 38}   200
>>
>> The x value of the Point value are not changed with the different font size. So a endless loop is done.
>>
>>
>>
>> The two errors appear after I upgrade the Eclipse to Luna, and the code is not be changed. It runs without any error in older version of Eclipse, not only inside the Eclipse, but also as a standalone jar file in console.
>>
>> The command line which I run the SWT program as a standalone jar file is like blew.
>> wgl@athena:~/home/SoftDev/dev/CurveSpirit/project/bin$ java -classpath testswt.jar:swt.jar:org.eclipse.core.commands.jar:org.eclipse.core.runtime.jar:org.eclipse.equinox.common.jar:org.eclipse.jface.jar: testswt/CTestSWT
>>
>> My operate system is Debian testing, the jdk is OpenJDK 7u65-2.5.2-4 which is install from Debian, and the Eclipse is Luna. The phenomenon is very strange, and it was not occur in older version of Eclipse.
>>
>> What is wrong? Would you please help me? Thank you very much!
>>
>>
>> With best regards
>>
>> Gufstream
>>
>>
>>
>> <fig_error.png><fig_correct.png><CTestSWT.java>_______________________________________________
>> platform-swt-dev mailing list
>> platform-swt-dev@xxxxxxxxxxx
>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>>
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

Back to the top