We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › pushMatrix() null pointer exception from subclass
Page Index Toggle Pages: 1
pushMatrix() null pointer exception from subclass (Read 809 times)
pushMatrix() null pointer exception from subclass
Feb 19th, 2008, 6:43pm
 
Hi
I have made an OpenGL application that animates a series of Plane instances in a Scene instance (my class names). You can probably guess roughly what I mean by that.

So my Scene and Plane classes have draw() methods that do any matrix transformations required and then render content (at the moment just a 'test card').

Everything works fine.

But.. now I have subclassed Scene as CopyTemplateScene and overridden my createPlane() method to return a CopyPlane ('copy' as in 'text') instead of a Plane for the collection of planes to be rendered. Standard stuff, surely.

But now my application gets into the Scene instance but then breaks on the Plane.draw() method on the first (and any subsequent) pushMatrix() calls, with the following error.

java.lang.RuntimeException: java.lang.NullPointerException
at processing.opengl.PGraphicsOpenGL.requestDisplay(PGraphicsOpenGL.java:172)
at processing.core.PApplet.run(PApplet.java:1562)
at java.lang.Thread.run(Thread.java:613)


So everything works in my Scene subclass, but when it comes to the Plane subclass it falls apart.

Does anybody have any idea why this might be?! I don't want to end up writing a lot of conditional code to make different types of Plane...
Re: pushMatrix() null pointer exception from subcl
Reply #1 - Feb 19th, 2008, 7:01pm
 
Doesn't happen if I don't override my Scene class's createPlaneFromXML method. Must be something to do with switching in another return type.

class CopyTemplateScene extends Scene{
 CopyTemplateScene(String $scene_name){
   super($scene_name);
 }
 
 Plane createPlaneFromXML(XMLElement xml){
   return new CopyPlane(xml);
 }
}

How am I supposed to do this..? Hope this isn't just me not knowing Java - I would expect the compiler to catch stuff like this if it is illegal...
Page Index Toggle Pages: 1