Tabs on Android (tab)--a magical character (ii)

Source: Internet
Author: User

Received last said, mainly on the last question, I think is the Android bug, Uncle Lee think is cocos2dx bug, asked me to submit a bug. So I went on to study the next.


The last thing I said would call the Java layer function to create an image, and then set it as a texture to the sprite, where it crash, where the code is as follows:

public static void Createtextbitmapshadowstroke (String pstring,final string pfontname, Final int pfontsize, final float fo nttintr,final float FONTTINTG, final float fonttintb, final int palignment,final int pWidth, final int pheight, final bool Ean shadow,final float shadowdx, final float shadowdy, final float shadowblur,final boolean stroke, final float stroker, F inal float strokeg,final float strokeb, final float strokesize) {                ... final textproperty textproperty = Cocos2dxbitmap . Computetextproperty (Pstring, PWidth, pheight, paint); final int bitmaptotalheight = (Pheight = = 0? textproperty.mtotalhe Ight:pheight); final Bitmap Bitmap = Bitmap.createbitmap (textproperty.mmaxwidth+ (int) Bitmappaddingx, bitmaptotalheight+ (int) bitmappaddingy, Bitmap.Config.ARGB_8888); Cocos2dxbitmap.initnativeobject (bitmap);}
The crash is in Bitmap.createbitmap, where the first parameter and the second parameter are 0, and the 2 parameters are obtained by Textproperty. Look at this textproperty again. As follows:

private static Textproperty Computetextproperty (final String pstring,final int pWidth, final int pheight, final Paint PPai NT) {FINAL fontmetricsint fm = Ppaint.getfontmetricsint (); final int h = (int) math.ceil (fm.bottom-fm.top); int maxcontent Width = 0;final string[] lines = cocos2dxbitmap.splitstring (pstring, Pwidth,pheight, ppaint); if (pWidth! = 0) {MAXCONTENTW Idth = PWidth;} else {/* Compute the max width. */int temp = 0;for (final String line:lines) {temp = (int) Floatmath.ceil (ppaint.measure Text (line, 0,line.length ()));                It's right here!! if (Temp > maxcontentwidth) {maxcontentwidth = temp;}}} return new Textproperty (maxcontentwidth, H, lines);}
Note that the for-loop thing, it is understood that if there are a lot of words, then the width of this texture is certainly the widest line in many words. As for the width of this line how to take, that is, by Ppaint to draw the time, look at the picture is how big, so there is a measure function, you can calculate the length.

This paint and this measure are all functions that Android provides to us. if this width and height can not be 0, should throw an exception, but Android did not do so, he let him directly crash, so this must be Android bug!!!



But cocos2dx in the design should also be avoidable, you can manually determine whether this value is 0.

But who would be bored like me to find this problem ....


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.