Re: Outsmarted myself - JOGL instance variables in subclasses.
Posted by LordSmoke on Jan 13, 2017; 8:50pm
URL: https://forum.jogamp.org/Outsmarted-myself-JOGL-instance-variables-in-subclasses-tp4037578p4037580.html
Right, but the GLEventlistener routines in subclasses call that of super classes.
dialog01
declares bgColor
display() {
gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, 1.0f);
gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
...
}
dialog02 extends dialog01
changes bgColor
display() {
super.display()
new stuff...
}
dialog03 extends dialog02
sets its own bgColor
display() {
super.display()
new stuff...
}
Setting the background color in dialog03 changes the bgColor (upon repaint) for all open dialog02 dialogs and other dialog02 descendents since the bgColor is declared in dialog01. Hiding the bgColor in, say, dialog03 doesn't help since the method setting the background color is in dialog01, and that appears to use the original bgColor variable.
Classes at the same "level" at which the variable is declared get their own copies (multiple dialog01 dialogs could all have their own background colors), but subsequently developed subclasses all share the same copy.
This seems to be a general problem of superclass-instanced variables, which will probably bite me when I go to change the geometry from triangle to cube in a later subclass since vertexArray is declared in dialog01.
I have also found this to be an issue with registering the instanced glCanvas with the animator - only the last window is registered since current code uses the dialog01 glCanvas variable, which gets changed (I think) with each construction.
NOTE: I haven't included method arguments, e.g., GLAutoDrawable to display(), to simplify the shown structure.