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

相关文章

SpringBoot排查和解决JSON解析错误(400 Bad Request)的方法

《SpringBoot排查和解决JSON解析错误(400BadRequest)的方法》在开发SpringBootRESTfulAPI时,客户端与服务端的数据交互通常使用JSON格式,然而,JSON... 目录问题背景1. 问题描述2. 错误分析解决方案1. 手动重新输入jsON2. 使用工具清理JSON3.

基于Python实现一个简单的题库与在线考试系统

《基于Python实现一个简单的题库与在线考试系统》在当今信息化教育时代,在线学习与考试系统已成为教育技术领域的重要组成部分,本文就来介绍一下如何使用Python和PyQt5框架开发一个名为白泽题库系... 目录概述功能特点界面展示系统架构设计类结构图Excel题库填写格式模板题库题目填写格式表核心数据结构

Linux系统中的firewall-offline-cmd详解(收藏版)

《Linux系统中的firewall-offline-cmd详解(收藏版)》firewall-offline-cmd是firewalld的一个命令行工具,专门设计用于在没有运行firewalld服务的... 目录主要用途基本语法选项1. 状态管理2. 区域管理3. 服务管理4. 端口管理5. ICMP 阻断

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socket read timed out的问题

《如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socketreadtimedout的问题》:本文主要介绍解决Druid线程... 目录异常信息触发场景找到版本发布更新的说明从版本更新信息可以看到该默认逻辑已经去除总结异常信息触发场景复

Python struct.unpack() 用法及常见错误详解

《Pythonstruct.unpack()用法及常见错误详解》struct.unpack()是Python中用于将二进制数据(字节序列)解析为Python数据类型的函数,通常与struct.pa... 目录一、函数语法二、格式字符串详解三、使用示例示例 1:解析整数和浮点数示例 2:解析字符串示例 3:解

CentOS 7 YUM源配置错误的解决方法

《CentOS7YUM源配置错误的解决方法》在使用虚拟机安装CentOS7系统时,我们可能会遇到YUM源配置错误的问题,导致无法正常下载软件包,为了解决这个问题,我们可以替换YUM源... 目录一、备份原有的 YUM 源配置文件二、选择并配置新的 YUM 源三、清理旧的缓存并重建新的缓存四、验证 YUM 源

基于Python+PyQt5打造一个跨平台Emoji表情管理神器

《基于Python+PyQt5打造一个跨平台Emoji表情管理神器》在当今数字化社交时代,Emoji已成为全球通用的视觉语言,本文主要为大家详细介绍了如何使用Python和PyQt5开发一个功能全面的... 目录概述功能特性1. 全量Emoji集合2. 智能搜索系统3. 高效交互设计4. 现代化UI展示效果

Windows 系统下 Nginx 的配置步骤详解

《Windows系统下Nginx的配置步骤详解》Nginx是一款功能强大的软件,在互联网领域有广泛应用,简单来说,它就像一个聪明的交通指挥员,能让网站运行得更高效、更稳定,:本文主要介绍W... 目录一、为什么要用 Nginx二、Windows 系统下 Nginx 的配置步骤1. 下载 Nginx2. 解压