G4P opening new Window Problem

edited August 13 in Library Questions

This is a old window problem we talked about with Peter Lager and his G4P GUI library. When opening anew window with its default state, the windows opens quite normally but if there is any modification on the elements of this window just after the opening, there may have some crashes. Unfortunately, this may happen after several openings or just at first...

I've made a little program that opens and close a window automatically every 5s...

I can send it to anyone that wants to try on Linux, Mac OS or Windows.

Right now I made the tests on Windows only.

It seems that we can't send files on this forum. I'm trying to copy the code instead.

Here is the first page, it's quite simple, a standard setup.

// Need G4P library
import g4p_controls.*;

String Lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,§ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.§ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.§ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.§ Excepteur sint occaecat cupidatat non proident,§ sunt in culpa qui officia deserunt mollit anim id est laborum.";
String TxtCodeBloc = "Bonjour,§enfant de la nature,§ toi qui veille sur notre avenir infiNi"+"\nPoPol"+"Ne comptons plus sur les périodes dites creuses pour§ assécher le guano sur les rochers humides du Nouvel Empire."; //
String CodeBloc = "";
boolean Sq = false; 
boolean Ouverture = false;
int NbOPen=0;

public void setup(){
  size(300, 200, JAVA2D);
  surface.setLocation(500, 100);
}//Fin setup

public void draw(){
  text("Ouvertures: "+NbOPen,10,150);

  if (Sq == true){
    int m2 = millis();
    int Tps;
    Tps = (m2 % 10000)/1000;
    if (Tps < 5){
    } else {
    if (Tps == 5 && Ouverture == false){
      button2_click1(button2, GEvent.CLICKED);
      Ouverture = true;
    if (Tps == 9 && Ouverture == true){
      if(G4P.getOpenWindowsAsList(null).contains(window1)) {
        Ouverture = false;
   //if (Ouverture == true){ChTx();}//Change the text
  }//Fin Sq true 
}//Fin void draw

public void ChTx(){//Changement du texte

  CodeBloc = Lorem.replace("§", "\n");
  CodeBloc = "";

  textarea1.setText("");//On efface le textarea
  CodeBloc = TxtCodeBloc.replace("§", "\n");
  CodeBloc = "";
}///Fin ChTx


    edited August 13

    Here is the GUI page with all the elements for the 3 windows.

    /** =========================================================
     * ====                   WARNING                        ===
     * =========================================================
     * The code in this tab has been generated from the GUI form
     * designer and care should be taken when editing this file.
     * Only add/edit code inside the event handlers i.e. only
     * use lines between the matching comment tags. e.g.
     void myBtnEvents(GButton button) { //_CODE_:button1:12356:
         // It is safe to enter your event code here  
     } //_CODE_:button1:12356:
     * Do not rename this tab!
     * =========================================================
    public void button1_click1(GButton source, GEvent event) { //_CODE_:button1:976421:
      println("button1 - GButton >> GEvent." + event + " @ " + millis());
      Sq = true;
    } //_CODE_:button1:976421:
    public void button2_click1(GButton source, GEvent event) { //_CODE_:button2:591854:
      println("button2 - GButton >> GEvent." + event + " @ " + millis());
      if(G4P.getOpenWindowsAsList(null).contains(window1)==false) {//Vérifie que la fenêtre n'est pas déjà ouverte
      window1 = GWindow.getWindow(this, "Window title", 100, 500, 300, 300, JAVA2D);
      window1.addDrawHandler(this, "win_draw1");
      label3 = new GLabel(window1, 0, 0, 300, 20);
      label3.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
      label3.setText("Fenêtre automatique");
      dropList1 = new GDropList(window1, 0, 30, 150, 140, 6);
      dropList1.setItems(loadStrings("list_901893"), 0);
      dropList1.addEventHandler(this, "dropList1_click1");
      dropList2 = new GDropList(window1, 150, 30, 150, 80, 3);
      dropList2.setItems(loadStrings("list_383887"), 0);
      dropList2.addEventHandler(this, "dropList2_click1");
      textfield1 = new GTextField(window1, 0, 70, 300, 30, G4P.SCROLLBARS_HORIZONTAL_ONLY);
      textfield1.setText("Ceci est le texte du champ texte dédié à la fenêtre automatique. Il doit normalement dépasser la longueur de la fenêtre.");
      textfield1.addEventHandler(this, "textfield1_change1");
      textarea1 = new GTextArea(window1, 0, 120, 300, 150, G4P.SCROLLBARS_BOTH);
      textarea1.setText("Voici enfin notre texte area qui nous défie chaque jour de trouver les raisons qui nous tourmentent tellement.");
      textarea1.addEventHandler(this, "textarea1_change1");
      label4 = new GLabel(window1, 0, 280, 300, 20);
      label4.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
      label4.setText("Fin de la fenêtre automatique");
      ChTx();//Changement du contenu du textarea
      //Ouverture = true;
      }//Fin if fenêtre ouverte ou pas
    } //_CODE_:button2:591854:
    public void button3_click1(GButton source, GEvent event) { //_CODE_:button3:891620:
      println("button3 - GButton >> GEvent." + event + " @ " + millis());
      if(G4P.getOpenWindowsAsList(null).contains(window1)) {
    Sq = false;
    } //_CODE_:button3:891620:
    synchronized public void win_draw1(PApplet appc, GWinData data) { //_CODE_:window1:468300:
    } //_CODE_:window1:468300:
    public void dropList1_click1(GDropList source, GEvent event) { //_CODE_:dropList1:901893:
      println("dropList1 - GDropList >> GEvent." + event + " @ " + millis());
    } //_CODE_:dropList1:901893:
    public void dropList2_click1(GDropList source, GEvent event) { //_CODE_:dropList2:383887:
      println("dropList2 - GDropList >> GEvent." + event + " @ " + millis());
    } //_CODE_:dropList2:383887:
    public void textfield1_change1(GTextField source, GEvent event) { //_CODE_:textfield1:656990:
      println("textfield1 - GTextField >> GEvent." + event + " @ " + millis());
    } //_CODE_:textfield1:656990:
    public void textarea1_change1(GTextArea source, GEvent event) { //_CODE_:textarea1:909883:
      println("textarea1 - GTextArea >> GEvent." + event + " @ " + millis());
    } //_CODE_:textarea1:909883:
    synchronized public void win_draw2(PApplet appc, GWinData data) { //_CODE_:window2:631775:
    } //_CODE_:window2:631775:
    public void dropList3_click1(GDropList source, GEvent event) { //_CODE_:dropList3:280966:
      println("dropList3 - GDropList >> GEvent." + event + " @ " + millis());
    } //_CODE_:dropList3:280966:
    public void dropList4_click1(GDropList source, GEvent event) { //_CODE_:dropList4:880881:
      println("dropList4 - GDropList >> GEvent." + event + " @ " + millis());
    } //_CODE_:dropList4:880881:
    public void textfield2_change1(GTextField source, GEvent event) { //_CODE_:textfield2:349709:
      println("textfield2 - GTextField >> GEvent." + event + " @ " + millis());
    } //_CODE_:textfield2:349709:
    public void textarea2_change1(GTextArea source, GEvent event) { //_CODE_:textarea2:275440:
      println("textarea2 - GTextArea >> GEvent." + event + " @ " + millis());
    } //_CODE_:textarea2:275440:
    // Create all the GUI controls. 
    // autogenerated do not edit
    public void createGUI(){
      surface.setTitle("Sketch Window");
      label1 = new GLabel(this, 0, 0, 300, 20);
      label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
      label1.setText("Main Applet");
      label2 = new GLabel(this, 0, 40, 140, 30);
      label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
      label2.setText("Lancement de séquence");
      button1 = new GButton(this, 150, 40, 140, 30);
      button1.setText("Ouverture automatique");
      button1.addEventHandler(this, "button1_click1");
      button2 = new GButton(this, 150, 90, 140, 30);
      button2.setText("Ouverture manuelle");
      button2.addEventHandler(this, "button2_click1");
      button3 = new GButton(this, 150, 140, 140, 30);
      button3.setText("Fermeture manuelle");
      button3.addEventHandler(this, "button3_click1");
      window2 = GWindow.getWindow(this, "Window title", 100, 100, 300, 300, JAVA2D);
      window2.addDrawHandler(this, "win_draw2");
      label5 = new GLabel(window2, 0, 0, 300, 20);
      label5.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
      label5.setText("Fenêtre de mise à jour");
      dropList3 = new GDropList(window2, 0, 40, 150, 80, 3);
      dropList3.setItems(loadStrings("list_280966"), 0);
      dropList3.addEventHandler(this, "dropList3_click1");
      dropList4 = new GDropList(window2, 150, 40, 150, 140, 6);
      dropList4.setItems(loadStrings("list_880881"), 0);
      dropList4.addEventHandler(this, "dropList4_click1");
      textfield2 = new GTextField(window2, 0, 70, 300, 30, G4P.SCROLLBARS_NONE);
      textfield2.setText("Le texte B est un ensemble de mots qui se trouve dans la fenêtre dite de mise à jour");
      textfield2.setPromptText("Tapez ici que je vois ce que vous écrivez");
      textfield2.addEventHandler(this, "textfield2_change1");
      textarea2 = new GTextArea(window2, -10, 110, 310, 150, G4P.SCROLLBARS_BOTH);
      textarea2.setText("Donc voici notre texte aera B qui se veut être plus stable que le celui de la fenêtre qui s'active automatiquement.");
      textarea2.addEventHandler(this, "textarea2_change1");
      label6 = new GLabel(window2, -10, 270, 310, 20);
      label6.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
      label6.setText("Label de fin de fenêtre de mise à jour");
    // Variable declarations 
    // autogenerated do not edit
    GLabel label1; 
    GLabel label2; 
    GButton button1; 
    GButton button2; 
    GButton button3; 
    GWindow window1;
    GLabel label3; 
    GDropList dropList1; 
    GDropList dropList2; 
    GTextField textfield1; 
    GTextArea textarea1; 
    GLabel label4; 
    GWindow window2;
    GLabel label5; 
    GDropList dropList3; 
    GDropList dropList4; 
    GTextField textfield2; 
    GTextArea textarea2; 
    GLabel label6;
    edited August 13

    This little program give 3 windows: The main one has 3 buttons, the top button is to launch an automatique sequence of open/close a window where the textarea is changed each time. This is where the program crashes, sometimes with no reason. It can work on a long series and crashes, or when you start the application, It crashes immediately or after a few openings.

    The second and the 3d button are buttons to launch and close the window by yourself. However, it's very boring to do it by hand...that's why I made an automatic session.

    The crash always happens when the change is made on the textarea of the window that is opening. There is a 3d window that always keep opened and where I just refresh the same textarea. On this window, there is no crash.

    I tryed several lines of code in different places to a secure the window but it was useless...There is always a crash some time to time.

    I'd like Peter Lager could solve this issue in his very good library. It's really annoying...eh,eh..., Thank you

  • There are 4 lists to load, you can create any one of them, they have no use.

    "list_901893" "list_383887" "list_280966" "list_880881"

  • I forgot to mention that the textarea behavior of the automatic opening window is also not correct from time to time. The text set in it may be copied several times on itself...and once again, this happens irregularly ...then difficult to solve.

  • G4P provides multiple window support even though Processing was not designed to handle more than one window. It means that we have to make certain allowances, the first is that creating/destroying a window when it is needed causes problems to which I can't find a solution. To overcome this I recommend creating the window once and making it visible/invisible as needed.

    I suggest you read the guides on my website.

  • Thank you for your answer.

Sign In or Register to comment.