processing / processing-android

Processing mode and core library to create Android apps with Processing
http://android.processing.org
778 stars 292 forks source link

Unable to run sketch in Android mode #618

Open VigneshVelmurugan opened 3 years ago

VigneshVelmurugan commented 3 years ago

I keep getting the following error despite me trying both createFonts() and loadFonts(). Does anyone else have this issue with processing 3 in android mode? Could anyone please tell me a way to tackle this?

Thank you

Inefficient font rendering: use createFont() with a TTF/OTF instead of loadFont(). FATAL EXCEPTION: Animation Thread Process: processing.test.try_with_five_meters, PID: 26610 java.lang.OutOfMemoryError: Failed to allocate a 9763216 byte allocation with 9081184 free bytes and 8868KB until OOM, target footprint 268435456, growth limit 268435456 at processing.a2d.PGraphicsAndroid2D.loadPixels(PGraphicsAndroid2D.java:2011) at processing.a2d.PGraphicsAndroid2D.endDraw(PGraphicsAndroid2D.java:249) at meter.Meter.drawMeterScaleLabels(Meter.java:1562) at meter.Meter.updateMeter(Meter.java:366) at processing.test.try_with_five_meters.try_with_five_meters.draw(try_with_five_meters.java:133) at processing.core.PApplet.handleDraw(PApplet.java:1852) at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:476) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:516)

dzaima commented 3 years ago

The error is an OutOfMemoryError - your app is apparently using 270 megabytes of RAM. Either you really are using that much (in which case you can't do much about it), or you're doing something wrong.

Are you by any chance calling the createFont or loadFont function on every frame (i.e. in the draw function or a function it calls)? Cause you should only be calling it once (e.g. in setup) and saving the PFont in a variable.

(equivalently, doing loadImage, createGraphics, or many more intensive things in the draw function can easily result in very high memory usage)

VigneshVelmurugan commented 3 years ago

Thank you @dzaima , I am only calling the function in setup(). Here is my code:

`import meter.*;

Meter m1,m2,m3,m4,m5; int thumb_ang,index_ang,middle_ang,ring_ang,little_ang;

void setup() { fullScreen(); //size(displayWidth,displayHeight); background(100,200,102); thumb_ang = 20; index_ang = 20; middle_ang = 20; ring_ang = 20; little_ang = 20; // Uncomment the following two lines to see the available fonts String[] fontList = PFont.list(); printArray(fontList); PFont desFont = createFont("Montserrat-Black",32); textFont(desFont); //desFont = loadFont("Serif.bold-30.vlw"); //textFont(desFont,30);

m1 = new Meter(this, 25, 60); //(x,y) of upper left corner of the meter m1.setMeterWidth(350); m1.setTitle("Thumb"); String[] scaleLabels = {"0", "20", "40", "60", "80", "100", "120", "140", "160", "180"}; m1.setScaleLabels(scaleLabels); m1.setDisplayDigitalMeterValue(true); m1.setArcColor(color(141, 113, 178)); m1.setArcThickness(15); m1.setMaxScaleValue(180); m1.setMinInputSignal(0); m1.setMaxInputSignal(180); m1.setNeedleThickness(3);

int mx = m1.getMeterX(); int my = m1.getMeterY(); int mw = m1.getMeterWidth(); int mh = m1.getMeterHeight(); int spacing = 100;

m2 = new Meter(this,mx+mw+spacing,60); //(x,y) of upper left corner of the meter m2.setMeterWidth(350); m2.setTitleFontSize(20); m2.setTitle(" Index Finger"); m2.setScaleLabels(scaleLabels); m2.setScaleFontSize(18); m2.setDisplayDigitalMeterValue(true); m2.setArcColor(color(141,113,178)); m2.setArcThickness(15); m2.setMaxScaleValue(180); m2.setMinInputSignal(0); m2.setMaxInputSignal(180); m2.setNeedleThickness(3);

m3 = new Meter(this,mx,my+mh+spacing); //(x,y) of upper left corner of the meter m3.setMeterWidth(450); m3.setTitleFontSize(20); m3.setTitle(" Middle Finger"); m3.setScaleLabels(scaleLabels); m3.setScaleFontSize(18); m3.setDisplayDigitalMeterValue(true); m3.setArcColor(color(141,113,178)); m3.setArcThickness(15); m3.setMaxScaleValue(180); m3.setMinInputSignal(0); m3.setMaxInputSignal(180); m3.setNeedleThickness(3);

m4 = new Meter(this,mx+mw+spacing,my+mh+spacing); //(x,y) of upper left corner of the meter m4.setMeterWidth(450); m4.setTitleFontSize(20); m4.setTitle(" Ring Finger"); m4.setScaleLabels(scaleLabels); m4.setScaleFontSize(18); m4.setDisplayDigitalMeterValue(true); m4.setArcColor(color(141,113,178)); m4.setArcThickness(15); m4.setMaxScaleValue(180); m4.setMinInputSignal(0); m4.setMaxInputSignal(180); m4.setNeedleThickness(3);

m5 = new Meter(this,mx,my+2mh+2spacing); //(x,y) of upper left corner of the meter m5.setMeterWidth(450); m5.setTitleFontSize(20); m5.setTitle(" Little Finger"); m5.setScaleLabels(scaleLabels); m5.setScaleFontSize(18); m5.setDisplayDigitalMeterValue(true); m5.setArcColor(color(141,113,178)); m5.setArcThickness(15); m5.setMaxScaleValue(180); m5.setMinInputSignal(0); m5.setMaxInputSignal(180); m5.setNeedleThickness(3);

}

void draw(){

//text("Sensor Values",300,30);
m1.updateMeter(thumb_ang);
m2.updateMeter(index_ang);
m3.updateMeter(middle_ang);
m4.updateMeter(ring_ang);
m5.updateMeter(little_ang);

}`