• cocos2dx 3.9.1 mac模拟器log输出bug修正


    今天发现某些情况下mac模拟器会出现不输出log的情况, 跟踪了一下发现问题出现在mac/SimulatorApp.mm文件的handleNotification方法。

    NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
    

      

    这句代码在某些情况下str会为nil值导致模拟器不会输出任何log,  原因可能是data的编码中存在个别字符乱码导致整体不输出的情况。

    修改后的代码如下

    - (void)handleNotification:(NSNotification *)note
    {
        //NSLog(@"Received notification: %@", note);
        [_pipeReadHandle readInBackgroundAndNotify] ;
        NSData *data = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem];
        NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
        if (!str)
        {
            str =[[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding] autorelease];
        }
        if (!str)
        {
            str = @"encoding NSData to NSString error";
        }
        //show log to console
        [_consoleController trace:str];
        if(_fileHandle!=nil)
        {
            [_fileHandle writeData:[str dataUsingEncoding:NSUTF8StringEncoding]];
        }
    }
    

      当用utf8无法正常解码改用asc解码输出,这样就能看见输出了

      

  • 相关阅读:
    程序安装打包
    sql 2005 分页存储过程
    带线的无限级下拉树列表
    MapXtreme 2005 学习心得 概述(一)
    存储过程中用到的年,月,周的函数
    委托/事件/线程传参简单理解
    清除svn/vss小工具
    查看数据库连接数
    MapXtreme 2005 学习心得 使用WebTool工具(七)
    C#日期格式化
  • 原文地址:https://www.cnblogs.com/ColaZhang/p/5136481.html
Copyright © 2020-2023  润新知