Loading...
Logo
Processing Forum
Hi everyone :^) 
I have two questions.

First question is :
I have NPE problem. I've tried to solve by myself. But... 
When I start my processing, usually it runs very well, but very very occasionally NPE occurs, not every time. To find the cause of NPE, I've used println  almost everywhere in my code (I'm not sure whether it's a good way though). Now I guess that it occurs when Gwindow is initializing, because println("after window"); didn't execute. Is it right? Then what should I do?
This createControlWindow() method is located in void setup


Copy code
  1. void createControlWindow() 
  2. {
  3.   int cwHeight = ssh+cwh;
  4.   println("ccw in : "+ssw+", "+cwHeight);
  5.   window = new GWindow(this, "ControlWindow", 0, 100, ssw, cwHeight, false, JAVA2D);
  6.   println("after window"); 
  7.   window.setBackground(0); 
  8.   window.addDrawHandler(this, "windowDraw");
  9.   window.addMouseHandler(this, "windowMouse");
  10.   println("ccw end"); 
  11. }

ccw in : 1440, 426
java.lang.NullPointerException
at processing.core.PApplet.handleDraw(PApplet.java:2301)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2141)
at java.lang.Thread.run(Thread.java:680)


Second question is :
As I've mentioned above I've used  println  almost everywhere in my code to find the cause of NPE. Then I've found out that  windowDraw (DrawHandler of Gwindow is called 'windowDraw'.) executes more often than void draw. Can I make that  windowDraw executes only when void draw executes? not more not less.

Replies(8)

Re: G4P > Gwindow NPE

2 months ago
The stack trace (red text) indicates the exception did not occur in the GWindow constructor or it would  appear in the trace - something like

at g4p_controls.GWindow(GWindow.java ???)

The fact that the error is intermittent suggests that the problem is caused by some conflict / timing difference between threads.

The only suggestion at the moment is to ensure that the first line of code inside setup is the call to size(). If this is going to be a problem make sure that ALL G4P commands are called after the call to size()

If this does not help then I suggest you post the setup method code.



Hello quarks, thanks for the answer. Instead of variable sw, sh, I've tried  size(1920, 409, P2D); but the error occurs still  occasionally. 

Copy code
  1. int sw=1920, sh=409;
  2. int ssw=1440; 
  3. int ssh, cwh;

  4. void setup()
  5. {  
  6.   size(sw, sh, P2D);  
  7.   background(0);
  8.     
  9.   sDiff = float(sw)/float(ssw);
  10.   ssh = int(sh/sDiff);
  11.   cwh = 120;
  12.   cwDraw =true;
  13.   colorValue=255;
  14.   
  15.   mDR_cw = false;
  16.   mDR_ccw = false;
  17.   mDR_random = true;  

  18.   superSlowMiniAngle = QUARTER_PI/1000;
  19.   superSlowMaxAngle = QUARTER_PI/900;
  20.   miniminiAngle = QUARTER_PI/100;
  21.   miniAngle = QUARTER_PI/25;
  22.   midiAngle = HALF_PI/3;
  23.   maxAngle = QUARTER_PI;
  24.   maxmaxAngle = HALF_PI;
  25.  
  26.   section=1;
  27.   scene0();
  28.   
  29.   ex_rxNum=0;

  30.   smooth();
  31.   noFill(); 
  32.   noCursor();
  33.   frameRate(24);

  34.   createControlWindow();
  35. }
Are you using any other libraries?

Yes, these are the libraries. I didn't code with oscP5 yet.

import oscP5.*;
import netP5.*;
import java.util.Calendar;
import point2line.*;
import g4p_controls.*;
I can't see anything that might cause a problem.

Did the main sketch window open?

If it did open did to draw the background?


Also try using JAVA2D rather than P2D i.e.
  size(sw, sh); 

and see if that makes a difference?
It doesn't make a difference. When using P2D the main sketch window was open with gray color background and stopped (Actually my background color is black). And when using JAVA2D or just   size (sw, sh);  the main sketch window was not open. 

Buy the way, would you mind if I ask you my second question which I updated probably at the same time when you were writing the first reply??? Sorry if I disturb you.
 

Can I make that  windowDraw executes only when void draw executes? not more not less.
That is not possible because the GWindow has its own PApplet obejct so is running in its own thread.


Just had an idea - change the method header for the windowDraw method from

void windowDraw(

to

synchronized public void windowDraw(

and see if that solves the problem.
It doesn't make a difference. 
Anyway thank you so much. I've learned a lot. Have a nice weekend, quarks!!!