alexskyy / android-augment-reality-framework

Automatically exported from code.google.com/p/android-augment-reality-framework
GNU General Public License v3.0
0 stars 0 forks source link

activity force close when added too many markers #25

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When i have added around 10+ marker in LocalDataSource.java , the ARData will 
force close without any crash notification which result the apps to be crashed 
or force exit, so i have posted my issues on stackoverflow ,this is the link to 
my question : 
http://stackoverflow.com/questions/16813706/android-apps-activity-force-back 

Is there any way to prevent this to be happened? 
This is my logcat : http://pastebin.com/dvi7MBML
This is my AndroidManifest : http://pastebin.com/Y5f46JJF

Just let me know if you need any files to be referred , please help me because 
i got to submit this system at the end of June, thank you!!

Original issue reported on code.google.com by ronyong9...@gmail.com on 29 May 2013 at 3:51

GoogleCodeExporter commented 8 years ago
I've answered on SO but here is "an" answer to help anyone else which 
experiences the problem..

In com/jwetherell/augmented_reality/ui/objects/PaintableObject.java

Try changing the method:

public float getTextWidth(String txt) {
    if (txt == null) throw new NullPointerException();
    //return paint.measureText(txt);
    return paint.measureText(txt, 0, txt.length);
}
Or try this if that doesn't work:

public float getTextWidth(String txt) {
    if (txt == null) throw new NullPointerException();
    //return paint.measureText(txt);

    char[] seq = new char[txt.length()];
    for(int i =0; i < txt.length(); i++) {
        seq[i] = txt.charAt(i);
    }
    return paint.measureText(seq, 0, seq.length);
}
If all else fails, try this:

public float getTextWidth(String txt) {
    if (txt == null) throw new NullPointerException();
    //return paint.measureText(txt);

    char[] seq = new char[txt.length()];
    for(int i =0; i < txt.length(); i++) {
       seq[i] = txt.charAt(i);
    }
    Rect bounds = new Rect();
    paint.getTextBounds(seq, 0, seq.length, bounds);
    return bounds.width();
}
I believe this is a JNI issue and theses are work arounds for the known JNI 
issue. I haven't compiled the code, so there may some mistakes but you get the 
idea.

Original comment by phishman3579@gmail.com on 29 May 2013 at 11:44

GoogleCodeExporter commented 8 years ago
hi Mr phishman, thx for your reply , but the problem is still there , the 
activity still force closed

Original comment by ronyong9...@gmail.com on 30 May 2013 at 12:00

GoogleCodeExporter commented 8 years ago
this is the logcat that i run with your third solution -pastebin.com/j7Vsp2pg 
,thank you

Original comment by ronyong9...@gmail.com on 30 May 2013 at 12:01

GoogleCodeExporter commented 8 years ago
Thank you so much Mr Justin , your solution and effort saved me from getting 
fail of this subject, thank you , the problem is solved, thank you

Original comment by ronyong9...@gmail.com on 31 May 2013 at 5:10

GoogleCodeExporter commented 8 years ago
This is another work around, if the ones above do not work.

private StaticLayout measure(TextPaint textPaint, String text, Integer 
wrapWidth) {
    int boundedWidth = Integer.MAX_VALUE;
    if (wrapWidth != null && wrapWidth > 0) {
        boundedWidth = wrapWidth;
    }
    StaticLayout layout = new StaticLayout(text, textPaint, boundedWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    return layout;
}

private float getMaxLineWidth(StaticLayout layout) {
    float maxLine = 0.0f;
    int lineCount = layout.getLineCount();
    for (int i=0; i<lineCount; i++) {
        if (layout.getLineWidth(0) > maxLine) {
            maxLine = layout.getLineWidth(0);
        }
    }
    return maxLine;
}

public float getTextWidth(String text) {
    if (text == null) throw new NullPointerException();

    TextPaint textPaint = new TextPaint(paint);
    int widthWrap = 1000; // you may have to change this
    StaticLayout layout = measure(textPaint, text, widthWrap);
    return getMaxLineWidth(layout);
}

Original comment by phishman3579@gmail.com on 31 May 2013 at 5:16