关于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

相关文章

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

在MySQL执行UPDATE语句时遇到的错误1175的解决方案

《在MySQL执行UPDATE语句时遇到的错误1175的解决方案》MySQL安全更新模式(SafeUpdateMode)限制了UPDATE和DELETE操作,要求使用WHERE子句时必须基于主键或索引... mysql 中遇到的 Error Code: 1175 是由于启用了 安全更新模式(Safe Upd

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创

修改若依框架Token的过期时间问题

《修改若依框架Token的过期时间问题》本文介绍了如何修改若依框架中Token的过期时间,通过修改`application.yml`文件中的配置来实现,默认单位为分钟,希望此经验对大家有所帮助,也欢迎... 目录修改若依框架Token的过期时间修改Token的过期时间关闭Token的过期时js间总结修改若依

MySQL修改密码的四种实现方式

《MySQL修改密码的四种实现方式》文章主要介绍了如何使用命令行工具修改MySQL密码,包括使用`setpassword`命令和`mysqladmin`命令,此外,还详细描述了忘记密码时的处理方法,包... 目录mysql修改密码四种方式一、set password命令二、使用mysqladmin三、修改u

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

SpringBoot中的404错误:原因、影响及解决策略

《SpringBoot中的404错误:原因、影响及解决策略》本文详细介绍了SpringBoot中404错误的出现原因、影响以及处理策略,404错误常见于URL路径错误、控制器配置问题、静态资源配置错误... 目录Spring Boot中的404错误:原因、影响及处理策略404错误的出现原因1. URL路径错

使用Python在Excel中插入、修改、提取和删除超链接

《使用Python在Excel中插入、修改、提取和删除超链接》超链接是Excel中的常用功能,通过点击超链接可以快速跳转到外部网站、本地文件或工作表中的特定单元格,有效提升数据访问的效率和用户体验,这... 目录引言使用工具python在Excel中插入超链接Python修改Excel中的超链接Python

C#实现系统信息监控与获取功能

《C#实现系统信息监控与获取功能》在C#开发的众多应用场景中,获取系统信息以及监控用户操作有着广泛的用途,比如在系统性能优化工具中,需要实时读取CPU、GPU资源信息,本文将详细介绍如何使用C#来实现... 目录前言一、C# 监控键盘1. 原理与实现思路2. 代码实现二、读取 CPU、GPU 资源信息1.

在C#中获取端口号与系统信息的高效实践

《在C#中获取端口号与系统信息的高效实践》在现代软件开发中,尤其是系统管理、运维、监控和性能优化等场景中,了解计算机硬件和网络的状态至关重要,C#作为一种广泛应用的编程语言,提供了丰富的API来帮助开... 目录引言1. 获取端口号信息1.1 获取活动的 TCP 和 UDP 连接说明:应用场景:2. 获取硬