GithubHelp home page GithubHelp logo

smalldesktopdisplay-team / smalldesktopdisplay Goto Github PK

View Code? Open in Web Editor NEW
82.0 5.0 29.0 4.58 MB

License: GNU Affero General Public License v3.0

C++ 10.46% C 89.27% Dockerfile 0.01% CMake 0.04% Makefile 0.01% Shell 0.03% Processing 0.12% Python 0.02% HTML 0.05% JavaScript 0.01%

smalldesktopdisplay's Issues

重启BUG问题

问题描述

我在使用该项目扩展编程的过程中遇到问题是这样的,初始heap区域(RAM除去.bss与.data)有40KB左右可使用,但是我在继续添加我的代码发现总是重启。

问题原因

跟着代码跑了一遍并使用`system_get_free_heap_size`打印heap,发现有个函数会导致heap区域枯竭,并且随后的字体加载程序会使用`malloc`函数获取内存,且该`malloc`操作不做任何检查空指针,随机使用空指针去赋值,导致控制在操作错误。

代码跟踪路径

SmallDesktopDisplay.cpp->void setup()->getCityWeater()->:
  if (httpCode == HTTP_CODE_OK)
  {
     ....
     weaterData(&jsonCityDZ, &jsonDataSK, &jsonFC);
     ....
  }
weaterData()->clk.loadFont(ZdyLwFont_20)->loadFont("", false);->loadMetrics();->gxAdvance[gNum] =  (uint8_t)readInt32(); // xAdvance - to move x cursor
由于上面代码:gxAdvance =  (uint8_t*)malloc( gFont.gCount );    // xAdvance - to move x cursor
这里并没有申请成功,使得 &gxAdvance  =  NULL。那么就是NULL被赋值,导致错误。

解决

  • 方案一:在系列函数加入空指针检查,检测申请失败与成功
  • 方案二:在追部分代码过程时发现,某些代码中的变量未及时释放,导致内存吃紧,这是我查看代码的过程:
// 获取城市天气
void getCityWeater()
{
	heapa=23920
	
  // String URL = "http://d1.weather.com.cn/dingzhi/" + cityCode + ".html?_="+String(now());//新
  String URL = "http://d1.weather.com.cn/weather_index/" + cityCode + ".html?_=" + String(now()); //原来
  //创建 HTTPClient 对象
  HTTPClient httpClient;
	
	heapa=23808
	
	...............
	
  //如果服务器响应OK则从服务器获取响应体信息并通过串口输出
  if (httpCode == HTTP_CODE_OK)
  {
		heapa=22856
		
    String str = httpClient.getString();	
    int indexStart = str.indexOf("weatherinfo\":");
    int indexEnd = str.indexOf("};var alarmDZ");
		
		heapa=5424

		.....
		
		heapa=4568
    Serial.printf( "heapa size:%u\r\n", system_get_free_heap_size());
    weaterData(&jsonCityDZ, &jsonDataSK, &jsonFC);
    Serial.println("获取成功");
  }
  
	...............
}

可以看到由于str变量获取的网页回应导致大量的heap被占用,且未被释放就进入了下一个高内存消耗的函数weaterData.
这里建议:str.~String();放在weaterData(&jsonCityDZ, &jsonDataSK, &jsonFC);

字库问题

你好,我最近在复刻该项目,但是遇到了字库缺字的问题,具体是我所在的城市名称不在字库中。我注意到了《如何制作字库》这个教程,但是用GB2312的3000多个常用字生成的字库编译出来要占2M flash。我先是尝试修改linkscript,让程序正常编译和链接,最后生成的2M bin文件下载到设备上后无法执行。后来了解到ESP8266的程序执行空间IROM在内存的映射中只有1M,也就是说,程序最大只能1M我该链接脚本也无济于事。
最后回到了如何在现有字库上增加少量特殊字的问题,所以想咨询你一下,代码中的ZdyLwFont_20字库是基于那些字生成的,如果可以的话,希望得到你这份字库的所有字符。非常感谢!
我在
SmallDesktopDisplay
这个仓库中也提交了同样的请求,但是我不知道你们这个项目组和这个人的关系。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.