oss-forks / indic-text-renderer

Automatically exported from code.google.com/p/indic-text-renderer
Other
0 stars 0 forks source link

After successfully building and running on (HTC One X)Android Device i am getting local reference table overflow Error when i add more text to EditIndicText #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.If I add a long String in EditIndicText I am getting local reference table 
overflow Error

What is the expected output? What do you see instead?
Application Crashing

What version of the product are you using? On what operating system?
Ubuntu 10.04

Please provide any additional information below.
May be the problem is with the JNI Methods of  complex-script-rendering.c class 

Original issue reported on code.google.com by d...@neevtech.com on 29 Sep 2012 at 6:40

GoogleCodeExporter commented 9 years ago
yes, this is a bug in code. adding PushLocalFrame and PopLocalFrame in 
draw_bitmap function solves the problem.

Original comment by Sarim2...@gmail.com on 20 Dec 2012 at 4:41

GoogleCodeExporter commented 9 years ago
@sarim   could u please provide a working code implemented on complex 
rendering. c file

Original comment by sant...@braindigit.com on 13 Jan 2013 at 4:56

GoogleCodeExporter commented 9 years ago
@Sarim2:
           So far by hit and trial I have added following on draw_bitmap
(*env)->PushLocalFrame(env,256); at top
(*env)->PopLocalFrame(env,NULL); at bottom

Is this what you are referring to?.Further though it renders the whole font,it 
all comes on a single line as I haven't added any new line .What I want is the 
default behaviour of EditText i.e when text becomes long,it automatically moves 
to next line.

Finally how do I tell Complex rendering.C to choose a particular font from 
Harfbuzz meaning I want Devanagari font to be displayed.

Original comment by sant...@braindigit.com on 14 Jan 2013 at 8:03

GoogleCodeExporter commented 9 years ago
Can you please let me know which FT and harfbuzz codes that you are using? 
Since those are not in this project's repository, I am using some combination 
(see issue #8) and I am getting very fuzzy rendering of the fonts

Original comment by rgubb...@gmail.com on 19 Jan 2013 at 6:55

GoogleCodeExporter commented 9 years ago
Sant... and Sarim2, pushing and popping local frame is only a temp soln as it 
the new local reference table will also overflow after some more time. The 
solution to this is to add the following line

                 (*env)->DeleteLocalRef(env,row);

at the end of the following loop

    for (i = 0; i < bitmap->rows; i++) { ... }

in draw_bitmap() in complex-script-rendering.c where ret is being prepared one 
row at a time. Also add the same line just before the loop start, right after 
the creation of ret where row got created once and used to provide the object 
type to create ret. So, the loop would like this.

(*env)->DeleteLocalRef(env,row);
for (i = 0; i < bitmap->rows; i++)
{
   // same code as now
   ...
   (*env)->DeleteLocalRef(env,row);
}

The reason is as follows. The variable row gets created and refer to a large 
locally created object but never de-references it. This adds an entry into 
local reference table which has some max value (say 512). But row keeps 
referencing to new object and hence adding new entries to the local reference 
table without ever de-referencing any of them. Hence the local reference table 
overflows after some time although row would have long been rendered useless. 
With the above line added to the loop, row dereferenes the object and hence 
removes that entry from the local ref table avoiding its overflow.

Further I would add the following two lines at the end of the same function.
    (*env)->DeleteLocalRef(env, ret);
    (*env)->DeleteLocalRef(env, classType);

Original comment by rgubb...@gmail.com on 21 Jan 2013 at 10:57

GoogleCodeExporter commented 9 years ago
@rgubb
          So far using PushLocalFrame and PopLocalFrame,I am able to render long text without any problem and I will surely try your solution and thanks for explaining this issue.
     Further I have successfully implemented Indic Text renderer to render fonts,but the rendering is slow for long text.I assume that you have already implemented Indic Text on your project.So could you share tips on how to make rendering fast so that my application will be responsive.

Original comment by sant...@braindigit.com on 24 Jan 2013 at 1:54

GoogleCodeExporter commented 9 years ago
@rgubb
   Is it (*env)->DeleteLocalRef(env, classType);
   or
      (*env)->DeleteLocalRef(env, cls);
 So far I have done this as 
    void draw_bitmap(
        jclass cls;
    jmethodID mid;

    // Create array to send back
    (*env)->PushLocalFrame(env,256);
        row=
        ret=
        (*env)->DeleteLocalRef(env,row);
    for (i = 0; i < bitmap->rows; i++) {

          //at end
           (*env)->DeleteLocalRef(env,row);
        }

     //
     //
     (*env)->CallVoidMethod(env, jobj, mid, ret, xStart, yStart);
     (*env)->MonitorExit(env, lock);
     (*env)->DeleteLocalRef(env, ret);
     (*env)->DeleteLocalRef(env, cls);
     (*env)->PopLocalFrame(env,NULL);
Is this all you are referring to?Since I am no expert in ndk projects,your 
approval would be great.

Original comment by sant...@braindigit.com on 25 Jan 2013 at 4:43

GoogleCodeExporter commented 9 years ago
Sant..

Yes, it is cls and NOT classType.

You have done what is needed for releasing all local refs in time.

Regarding the rendering speed, yes it is very slow and in fact long texts and 
dynamically edited texts are so slow that it'll annoy the users. There are two 
optimizations that are possible. Due to lack of time, I have not tried it. See 
if you can try it and profile the execution speed.
1. Currently row and ret form 2D array from bitmap->buffer which is 1D array. 
We can instead pass 1D array directly and handle the same in the drawGlyph 
function in EditIndicText.java.

2. One can completely avoid going from C to Java as the drawGlyph eventually 
makes another native call. If you are adventurous, you can give it a shot.

Without the above optimization there is almost nothing you can do abour the 
speed.

Original comment by rgubb...@gmail.com on 25 Jan 2013 at 3:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@rgubb:
         Thanks a lot for the tips.But I am no expert on C,so I have to refer it from basics,but I will do it.And I hope you be there to assist me,after I have implemented what you have said so far.A little light of guidance would be great for me to walk through.
     If we can optimize it,it would be great for other developers out there and all other Android users having trouble getting Native language font to their devices.

And is it better that I open a new issue about code optimization,so that other 
developers also can give in their ideas?

Original comment by sant...@braindigit.com on 28 Jan 2013 at 8:38

GoogleCodeExporter commented 9 years ago

Original comment by sanimap@gmail.com on 18 Mar 2013 at 5:45