Repository navigation
Creating a custom renderer #49
Copy link
Copy link
Closed
Description
Issue by kiwistrongis
Thursday Mar 13, 2014 at 00:42 GMT
Originally opened as processing/processing-android-archive#64
Moved from processing/processing#2390
Hi there, just working on something that will resolve the problems SMT was having with the latest version of processing - a custom renderer. I have it working fully on the desktop on Windows and Linux ( can't test on mac ). I ran into a problem on Android however.
This works on the desktop:
void setup(){
size( 800, 600, Renderer.class.getName());
}
void draw(){
background( 30);
fill( 200, 100, 100, 200);
noStroke();
rect( 10, 10, 100, 100);
}
/*
public int sketchWidth() {
return 800;
}
public int sketchHeight() {
return 600;
}
public String sketchRenderer() {
return Renderer.class.getName();
}
*/
public static class Renderer extends PGraphics3D {
public Renderer(){
super();}
}However this fails on android:
void setup(){
//size( 800, 600, Renderer.class.getName());
}
void draw(){
background( 30);
fill( 200, 100, 100, 200);
noStroke();
rect( 10, 10, 100, 100);
}
public int sketchWidth() {
return 800;
}
public int sketchHeight() {
return 600;
}
public String sketchRenderer() {
return Renderer.class.getName();
}
public static class Renderer extends PGraphics3D {
public Renderer(){
super();}
}With the following logcat output:
D/AndroidRuntime(17635):
D/AndroidRuntime(17635): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime(17635): CheckJNI is OFF
D/AndroidRuntime(17635): Calling main entry com.android.commands.am.Am
D/AndroidRuntime(17635): Shutting down VM
D/AndroidRuntime(17649):
D/AndroidRuntime(17649): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime(17649): CheckJNI is OFF
D/AndroidRuntime(17649): Calling main entry com.android.commands.pm.Pm
D/AndroidRuntime(17649): Shutting down VM
I/AndroidRuntime(17649): NOTE: attach of thread 'Binder Thread #3' failed
D/AndroidRuntime(17713):
D/AndroidRuntime(17713): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime(17713): CheckJNI is OFF
D/AndroidRuntime(17713): Calling main entry com.android.commands.am.Am
D/AndroidRuntime(17713): Shutting down VM
I/AndroidRuntime(17713): NOTE: attach of thread 'Binder Thread #3' failed
D/AndroidRuntime(17741): Shutting down VM
E/AndroidRuntime(17741): FATAL EXCEPTION: main
E/AndroidRuntime(17741): java.lang.RuntimeException: Unable to start activity ComponentInfo{processing.test.asdf/processing.test.asdf.asdf}: java.lang.NullPointerException
E/AndroidRuntime(17741): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960)
E/AndroidRuntime(17741): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
E/AndroidRuntime(17741): at android.app.ActivityThread.access$600(ActivityThread.java:127)
E/AndroidRuntime(17741): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
E/AndroidRuntime(17741): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17741): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(17741): at android.app.ActivityThread.main(ActivityThread.java:4447)
E/AndroidRuntime(17741): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17741): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(17741): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(17741): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(17741): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(17741): Caused by: java.lang.NullPointerException
E/AndroidRuntime(17741): at android.view.ViewGroup.addViewInner(ViewGroup.java:3342)
E/AndroidRuntime(17741): at android.view.ViewGroup.addView(ViewGroup.java:3214)
E/AndroidRuntime(17741): at android.view.ViewGroup.addView(ViewGroup.java:3184)
E/AndroidRuntime(17741): at processing.core.PApplet.onCreate(Unknown Source)
E/AndroidRuntime(17741): at android.app.Activity.performCreate(Activity.java:4466)
E/AndroidRuntime(17741): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)
E/AndroidRuntime(17741): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
E/AndroidRuntime(17741): ... 11 more
Help of any kind would be nice. Advice as to where to look and the like would be great.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
processing-bugs commentedon Jul 18, 2014
Thursday Mar 13, 2014 at 00:57 GMT
Take a look around line
470ofprocessing.core.PApplet:Then, a little bit later:
There is simply no code to accommodate for a custom renderer. I don't know what steps would be necessary to get around this... but this should be enough to get you going in the right direction.
processing-bugs commentedon Jul 18, 2014
Thursday Mar 13, 2014 at 01:20 GMT
:S Thanks, I had a feeling this was the case, but didn't know where to look. I'll take a look to see if it can be worked around tomorrow, but I'm not optimistic :(.
kiwistrongis commentedon Aug 8, 2014
Hey @codeanticode, I saw you assigned yourself this. I've actually been recently tasked to try to get SMT to work on android. This issue is kinda my first step. Are you working on it? I don't want to step on your toes.
codeanticode commentedon Aug 8, 2014
Hi @kiwistrongis, I assigned this issue to myself simply because I was involved in the discussion from the beginning and could give you a hand in figuring out what is needed to add custom renderer support in Android. I'm not planning to implement it myself, so you your pull requests are welcome!
Anyways, as Calsign pointed out a while ago, the onCreate method only checks if the renderer is either JAVA2D or P2D/P3D, so you need to add some handling code in there. The other thing you need is to provide a subclass of SurfaceView that actually creates the appropriate renderer. If you take a look, the SurfaceView for JAVA2D essentially looks like:
so it you were to implement your own inside your renderer's library package, should probably be something like
Hope this helps!
kiwistrongis commentedon Aug 8, 2014
Cool. So conveniently enough our renderer just extends PGraphics3D and just adds an unusual feature we needed. I was planning on just adapting SurfaceViewGL to work on anything that extends PGraphicsOpenGL.
kiwistrongis commentedon Aug 9, 2014
So here's what I've got so far: kiwistrongis@95a4c3d
I was almost done until I decided to rebase onto the lastest master :(. Now I'm getting these errors when I try to run my test sketch:
I'm going to manually rebase ( or cherry-pick? ) back onto the old version so I can keep working for now, but any idea where the problem is?
kiwistrongis commentedon Aug 9, 2014
Yup I'm stuck on that now... I figured out the other problem I was having (it was with my test custom renderer), and I can't keep testing until I work around it.
kiwistrongis commentedon Aug 9, 2014
Ooooookay. So I rebased onto c44b09e cause 899a08a looked suspect, and I can once again compile processing-android and test my sketches. Aaaand its working :). I'll try to figure out exactly which commit caused the above problems later.
So, this commit: kiwistrongis@d701ecf should add support for custom renderers that extend PGraphicsOpenGL, given that they have the empty constructor. I've been testing with this sketch: kiwistrongis/processing-shell/test_android/test_android.pde.
Now with SMT I've got some problems with some classes not being loaded, which is weird, but w/e, the custom renderers thing is working.
codeanticode commentedon Aug 9, 2014
Hi @kiwistrongis, excellent work! Once you feel your changes are ready please submit a pull request. The commits from @imilka represent ongoing GSOC work aiming to properly support a number of missing features (signed package export, device and sdk selection, etc) which we are still debugging and testing.
kiwistrongis commentedon Aug 9, 2014
Alrighty. I think I'll comment what I've done, then submit the pull request.
kiwistrongis commentedon Aug 11, 2014
Submitted: #61
Let me know if you want me to change the code style to fit in better, or if you want me to walk forward through the commits and solve the other problem I ran into.
kiwistrongis commentedon Aug 14, 2014
I just found out that I made that silly semicolon mistake in my last commit... sorry :(