游戏项目是基于cocos2d-x开发的,但线上发现一个bug就是玩家在设置完自定义头像后直接闪退。凡是在设置该玩家头像的地方,游戏就直接闪退。最终定位到的问题是图片数据源有问题,我的机器是win7,图片能预览,但同事xp系统该图片是无法预览的,默认的系统自带的图片查看工具也无法显示图片。

把图片拉到sublime text中,查看文件二进制,发现它并非一个完整的jpeg格式

没有jpeg格式的结束标识0xff  0xd9

 

我在windows下调试代码,发现是在CCImageCommon_cpp.h中的_initWithJpgData方法调用jpeg_finish_decompress函数时程序直接退出了

bool CCImage::_initWithJpgData(void * data, int nSize, bool bNeedDecode /*= false*/)
{
    int nRandomBytes = 0;
    if (bNeedDecode) nRandomBytes = RANDOM_BYTES;     if (bNeedDecode)
    {
        data = (unsigned char *)data + nRandomBytes;
        nSize = nSize - nRandomBytes;
    }     /* these are standard libjpeg structures for reading(decompression) */
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    /* libjpeg data structure for storing one row, that is, scanline of an image */
    JSAMPROW row_pointer[1] = {0};
    unsigned long location = 0;
    unsigned int i = 0;     bool bRet = false;
    do 
    {
        /* here we set up the standard libjpeg error handler */
        cinfo.err = jpeg_std_error( &jerr );         /* setup decompression process and source, then read JPEG header */
        jpeg_create_decompress( &cinfo );         jpeg_mem_src( &cinfo, (unsigned char *) data, nSize );         /* reading the image header which contains image information */
        jpeg_read_header( &cinfo, true );         // we only support RGB or grayscale
        if (cinfo.jpeg_color_space != JCS_RGB)
        {
            if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr)
            {
                cinfo.out_color_space = JCS_RGB;
            }
        }
        else
        {
            break;
        }         /* Start decompression jpeg here */
        jpeg_start_decompress( &cinfo );         /* init image info */
        m_nWidth  = (short)(cinfo.image_width);
        m_nHeight = (short)(cinfo.image_height);
        m_bHasAlpha = false;
        m_bPreMulti = false;
        m_nBitsPerComponent = 8;
        row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components];
        CC_BREAK_IF(! row_pointer[0]);         m_pData = new unsigned char[cinfo.output_width*cinfo.output_height*cinfo.output_components];
        CC_BREAK_IF(! m_pData);         /* now actually read the jpeg into the raw buffer */
        /* read one scan line at a time */
        while( cinfo.output_scanline < cinfo.image_height )
        {
            jpeg_read_scanlines( &cinfo, row_pointer, 1 );
            for( i=0; i<cinfo.image_width*cinfo.output_components;i++)
            {
                m_pData[location++] = row_pointer[0][i];
            }
        }         jpeg_finish_decompress( &cinfo );
        jpeg_destroy_decompress( &cinfo );
        /* wrap up decompression, destroy objects, free pointers and close open files */       
        bRet = true;
    } while (0);     CC_SAFE_DELETE_ARRAY(row_pointer[0]);
    return bRet;
}

后面我用jpegtran(https://github.com/imagemin/jpegtran-bin)工具复制有问题的图片时, 也提示错误了

 

参考文章:

[1] 小议libjpeg解压损坏文件时的错误处理

[2] JPEG File Layout and Format

解决方案可以参考这篇文章:libjpeg解压损坏文件时的错误处理

libjpeg的问题的更多相关文章

  1. libjpeg 编译makfile

    一.准备 首先需要下载libjpeg库,网址在这里:http://www.ijg.org/ 如果不想编译就在这下载吧:http://pan.baidu.com/s/1hqeTDre 二.编译 1. 解 ...

  2. 编译libjpeg库

    最近在写车牌识别软件,需要用到BMP转成JPG的功能,自然就想到借助libjpeg来实现 OS: win7 64位 编译器: VS2008 1. 下载源代码下载地址:http://www.ijg.or ...

  3. 嵌入式 linux 移植修改后的libjpeg 实现内存中解码

    1.修改libjpeg源码,使之实现内存解码. 修改libjpeg中读取或者输出jpeg文件的函数接口文件jdatadst.c和jdatasrc.c见下面这篇帖子. http://blog.163.c ...

  4. libjpeg 交叉编译动态库和静态库

    1.下载libjpeg库,解压之     得到了jpeg6b和libtool-2.2.4两个文件夹. 2.编译安装libtool工具.   这是配置libtool,这里需要注意:configure 参 ...

  5. linux x64下编译libjpeg,libpng,zlib

    libJpeg编译: 下载libjpeg源码:http://www.ijg.org/,下载jpegsrc.v9a.tar.gz 解压源码,命令:tar -zxvf jpegsrc.v9a,源码文件夹为 ...

  6. imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be

    imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be ...

  7. VS2010编译libjpeg

    环境:win7旗舰版 x64 VS2010 下载源代码下载地址:http://www.ijg.org/,选择windows format file 解压源代码,修改源代码中jconfig.vc为jco ...

  8. 【转】VS2013编译libjpeg库

    原文地址:http://blog.csdn.net/weixinhum/article/details/42718959 现在,很多图像处理工具和开源库都给出了图像解码的函数接口,然而有时这些接口并不 ...

  9. imod报错:error while loading shared libraries: libjpeg.so.62的解决办法

    the file libjpeg.so.62(in /usr/lib/libjpeg.so.62)belongs to the package libjpeg62so try to reinstall ...

  10. <转>libjpeg解码内存中的jpeg数据

    转自http://my.unix-center.net/~Simon_fu/?p=565 熟悉libjpeg的朋友都知道libjpeg是一个开源的库.Linux和Android都是用libjpeg来 ...

随机推荐

  1. [转]解决阿里云mysql不能连接,配置mysql远程连接

    默认是不能用客户端远程连接的,阿里云提供的help.docx里面做了设置说明,mysql密码默认存放在/alidata/account.log 首先登录: mysql -u root -h local ...

  2. git stash命令使用手册

    修改记录压栈保存: git stash push -u -m "msg" // -u ~ --意思是包含未被跟踪的文件git stash push -m "msg&quo ...

  3. JSP中的指令概述和示例

    一.JSP——Java server page :java服务端的页面,这是属于一个后端技术 1.前端技术: html.css.javascript 2.后端技术: java语言.框架(mybatis ...

  4. js数组去重与性能分析(时间复杂度很重要)

    随着js的深入和实际项目对性能的要求,算法的简单实现已经不能满足需要,在不同的应用场景下,时间复杂度很重要. 首先是创建数组与性能处理函数: // 保证时间差的明显程度,创建不同量级的数组,size为 ...

  5. 2019 A类

  6. 处理javabean的JSP标签

    (1) 关于javabean要求: 1,具有无参的构造函数. 2,针对每一个成员变量,因改提供相应get/set. 3,implments Serializable(实现才能对象序列化). (2) 使 ...

  7. Orleans入门

    一.Grains 二.开发一个Grain 三.开发一个客户端 四.运行应用程序 五.调式 一.Grains Grains是Orleans编程模型的关键原语. Grains是Orleans应用程序的构建 ...

  8. Winform给TextBox设置默认值(获取焦点后默认值消失)

    主要是通过TextBox的获取焦点Enter和失去焦点Leave两个事件来实现的, 思路如下: 1.设置一个字符串常量,作为TextBox的默认值: 2.在界面的构造方法中将默认值赋值给TextBox ...

  9. app分组

    将项目中中的urls.py复制到app当中 清空项目名称文件夹下的urls.py文件中的内容,并写入一下内容 from django.conf.urls import url,include urlp ...

  10. WEB应用从服务器主动推送Data到客户端有那些方式?

    1)  html5 websocket 2)  WebSocket 通过 Flash 3)  XHR长时间连接 4)  XHR Multipart Streaming 5)  不可见的Iframe 6 ...