关于emjoy表情在android5.x以上系统触发jni错误的修改(基于cocos2dx2.1.5修改)

本文主要是介绍关于emjoy表情在android5.x以上系统触发jni错误的修改(基于cocos2dx2.1.5修改),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一直纠结着这个错误,后来看别人的文章找到灵感,于是完善了基于cocos2dx2.1.5修改的大笑


具体报错:JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0xed

解决办法(基于coocs2dx2.1.5):

在CCImage.cpp里面的getBitmapFromJavaShadowStroke方法中,emjoy表情在jstring jstrText = methodInfo.env->NewStringUTF(text);

的时候触发崩溃,原因大致估计是因为emjoy不能被utf识别,于是绕过NewStringUTF,将之转化为byte[]来绕过.具体屏蔽jstring jstrText = methodInfo.env->NewStringUTF(text);修改为

 bool getBitmapFromJavaShadowStroke(	const char *text,int nWidth,int nHeight,CCImage::ETextAlign eAlignMask,const char * pFontName,float fontSize,float textTintR 		= 1.0,float textTintG 		= 1.0,float textTintB 		= 1.0,bool shadow 			= false,float shadowDeltaX 		= 0.0,float shadowDeltaY 		= 0.0,float shadowBlur 		= 0.0,float shadowIntensity 	= 0.0,bool stroke 			= false,float strokeColorR 		= 0.0,float strokeColorG 		= 0.0,float strokeColorB 		= 0.0,float strokeSize 		= 0.0 ){JniMethodInfo methodInfo;if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxBitmap", "createTextBitmapShadowStroke","([BLjava/lang/String;IFFFIIIZFFFZFFFF)V")){CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);return false;}// Do a full lookup for the font path using CCFileUtils in case the given font name is a relative path to a font file asset,// or the path has been mapped to a different location in the app package:std::string fullPathOrFontName = CCFileUtils::sharedFileUtils()->fullPathForFilename(pFontName);// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context// requires this portion of the path to be omitted for assets inside the app package.if (fullPathOrFontName.find("assets/") == 0){fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/"));	// Chop out the 'assets/' portion of the path.}/**create bitmap* this method call Cococs2dx.createBitmap()(java code) to create the bitmap, the java code* will call Java_org_cocos2dx_lib_Cocos2dxBitmap_nativeInitBitmapDC() to init the width, height* and data.* use this approach to decrease the jni call number*///jstring jstrText = methodInfo.env->NewStringUTF(text);/*** 修复emioy表情在android5.x以上系统jni崩溃bug* 将string修改为byte[].绕过jni在android5.x以上系统出现emjoy崩溃问题*/int strLen = strlen(text);jbyteArray byteArray = methodInfo.env->NewByteArray(strLen);methodInfo.env->SetByteArrayRegion(byteArray, 0, strLen, reinterpret_cast<const jbyte*>(text));jstring jstrFont = methodInfo.env->NewStringUTF(fullPathOrFontName.c_str());methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, byteArray,jstrFont, (int)fontSize, textTintR, textTintG, textTintB, eAlignMask, nWidth, nHeight, shadow, shadowDeltaX, -shadowDeltaY, shadowBlur, stroke, strokeColorR, strokeColorG, strokeColorB, strokeSize);methodInfo.env->DeleteLocalRef(byteArray);methodInfo.env->DeleteLocalRef(jstrFont);methodInfo.env->DeleteLocalRef(methodInfo.classID);return true;}

同时java对应修改传入参数

Cocos2dxBitmap.java中,createTextBitmapShadowStroke传入参数修改为byte[]类型,然后将byte[]转化为string来正常直接emjoy的输出

public static void createTextBitmapShadowStroke(byte[] pString_byte,final String pFontName,final int pFontSize,final float fontTintR,final float fontTintG,final float fontTintB,final int pAlignment,final int pWidth,final int pHeight,final boolean shadow,final float shadowDX,final float shadowDY,final float shadowBlur,final boolean stroke,final float strokeR,final float strokeG,final float strokeB,final float strokeSize) throws UnsupportedEncodingException{/*** 将string修改为byte[].绕过jni在android5.x以上系统出现emjoy崩溃问题,然后重新转化为string来继续输出emjoy表情* @author lfy*/String pString=new String(pString_byte,"UTF-8");final int horizontalAlignment=pAlignment&0x0F;final int verticalAlignment=(pAlignment>>4)&0x0F;try{pString=Cocos2dxBitmap.refactorString(pString);}catch(java.lang.Exception e){}final Paint paint=Cocos2dxBitmap.newPaint(pFontName,pFontSize,horizontalAlignment);// set the paint colorpaint.setARGB(255,(int)(255.0*fontTintR),(int)(255.0*fontTintG),(int)(255.0*fontTintB));// modify some char error... s cdy20140731// final TextProperty// textProperty=Cocos2dxBitmap.computeTextProperty(// pString,pWidth,pHeight,paint);// final int bitmapTotalHeight=(pHeight==0?textProperty.mTotalHeight// :pHeight);TextProperty textProperty=null;int bitmapTotalHeight=0;textProperty=Cocos2dxBitmap.computeTextProperty(pString,pWidth,pHeight,paint);bitmapTotalHeight=(pHeight==0?textProperty.mTotalHeight:pHeight);if(bitmapTotalHeight<=0||textProperty.mMaxWidth<=0){textProperty=Cocos2dxBitmap.computeTextProperty(" ",pWidth,pHeight,paint);bitmapTotalHeight=(pHeight==0?textProperty.mTotalHeight:pHeight);}// modify some char error... e// padding needed when using shadows (not used otherwise)float bitmapPaddingX=0.0f;float bitmapPaddingY=0.0f;float renderTextDeltaX=0.0f;float renderTextDeltaY=0.0f;if(shadow){int shadowColor=0xff7d7d7d;paint.setShadowLayer(shadowBlur,shadowDX,shadowDY,shadowColor);bitmapPaddingX=Math.abs(shadowDX);bitmapPaddingY=Math.abs(shadowDY);if(shadowDX<0.0){renderTextDeltaX=bitmapPaddingX;}if(shadowDY<0.0){renderTextDeltaY=bitmapPaddingY;}}final Bitmap bitmap=Bitmap.createBitmap(textProperty.mMaxWidth+(int)bitmapPaddingX,bitmapTotalHeight+(int)bitmapPaddingY,Bitmap.Config.ARGB_8888);final Canvas canvas=new Canvas(bitmap);/* Draw string. */final FontMetricsInt fontMetricsInt=paint.getFontMetricsInt();int x=0;int y=Cocos2dxBitmap.computeY(fontMetricsInt,pHeight,textProperty.mTotalHeight,verticalAlignment);final String[] lines=textProperty.mLines;for(final String line:lines){x=Cocos2dxBitmap.computeX(line,textProperty.mMaxWidth,horizontalAlignment);canvas.drawText(line,x+renderTextDeltaX,y+renderTextDeltaY,paint);y+=textProperty.mHeightPerLine;}// draw again with stroke on if neededif(stroke){final Paint paintStroke=Cocos2dxBitmap.newPaint(pFontName,pFontSize,horizontalAlignment);paintStroke.setStyle(Paint.Style.STROKE);paintStroke.setStrokeWidth(strokeSize*0.5f);paintStroke.setARGB(255,(int)strokeR*255,(int)strokeG*255,(int)strokeB*255);x=0;y=Cocos2dxBitmap.computeY(fontMetricsInt,pHeight,textProperty.mTotalHeight,verticalAlignment);final String[] lines2=textProperty.mLines;for(final String line:lines2){x=Cocos2dxBitmap.computeX(line,textProperty.mMaxWidth,horizontalAlignment);canvas.drawText(line,x+renderTextDeltaX,y+renderTextDeltaY,paintStroke);y+=textProperty.mHeightPerLine;}}Cocos2dxBitmap.initNativeObject(bitmap);}

如此可以正常在聊天中输入emjoy表情了,如果有什么差错,麻烦指正下,个人QQ1908662823


这篇关于关于emjoy表情在android5.x以上系统触发jni错误的修改(基于cocos2dx2.1.5修改)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1125564

相关文章

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

C/C++错误信息处理的常见方法及函数

《C/C++错误信息处理的常见方法及函数》C/C++是两种广泛使用的编程语言,特别是在系统编程、嵌入式开发以及高性能计算领域,:本文主要介绍C/C++错误信息处理的常见方法及函数,文中通过代码介绍... 目录前言1. errno 和 perror()示例:2. strerror()示例:3. perror(

Go标准库常见错误分析和解决办法

《Go标准库常见错误分析和解决办法》Go语言的标准库为开发者提供了丰富且高效的工具,涵盖了从网络编程到文件操作等各个方面,然而,标准库虽好,使用不当却可能适得其反,正所谓工欲善其事,必先利其器,本文将... 目录1. 使用了错误的time.Duration2. time.After导致的内存泄漏3. jsO

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

Python中ModuleNotFoundError: No module named ‘timm’的错误解决

《Python中ModuleNotFoundError:Nomodulenamed‘timm’的错误解决》本文主要介绍了Python中ModuleNotFoundError:Nomodulen... 目录一、引言二、错误原因分析三、解决办法1.安装timm模块2. 检查python环境3. 解决安装路径问题

如何解决mysql出现Incorrect string value for column ‘表项‘ at row 1错误问题

《如何解决mysql出现Incorrectstringvalueforcolumn‘表项‘atrow1错误问题》:本文主要介绍如何解决mysql出现Incorrectstringv... 目录mysql出现Incorrect string value for column ‘表项‘ at row 1错误报错

Linux系统之主机网络配置方式

《Linux系统之主机网络配置方式》:本文主要介绍Linux系统之主机网络配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、查看主机的网络参数1、查看主机名2、查看IP地址3、查看网关4、查看DNS二、配置网卡1、修改网卡配置文件2、nmcli工具【通用

Linux系统之dns域名解析全过程

《Linux系统之dns域名解析全过程》:本文主要介绍Linux系统之dns域名解析全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、dns域名解析介绍1、DNS核心概念1.1 区域 zone1.2 记录 record二、DNS服务的配置1、正向解析的配置