cocos2d-x3.0.1,載入cocostudio ui編輯器匯出的json檔案出現"Buffer is too small" && 0解決方案

來源:互聯網
上載者:User

標籤:使用   os   檔案   io   re   問題   

剛到這個公司,開始進行cocos2d-x的真正項目開發,為了以後能夠更好擴充,改動不大,決定使用3.X版本開發,而且使用ui編輯器。在匯入的時候,今天遇到一個問題,Buffer is too small,搜了不少,但是都沒有解決的方案,最後查到一個錯誤誘因,是因為ui中使用了label所致,於是我試了試,發現還真是label導致的問題,每次運行異常都發生在CCDevice.cpp的

bool setFont(const char * pFontName = NULL, int nSize = 0)中的strcpy_s(tNewFont.lfFaceName, LF_FACESIZE, fontName.c_str());,因為fontName.c_str()過長導致越界,tNewFont.lfFaceName長度只有32位元組,然後看了fontName為什麼過長,而其他的都正常,發現TextRead.cpp檔案中

void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)。

std::string fontName = DICTOOL->getStringValue_json(options, P_FontName, "微軟雅黑");
std::string fontFilePath = jsonPath.append(fontName);
label->setFontName(fontFilePath );

這幾句代碼將fontFilePath路徑給增加了,實際上只用傳遞fontName就行,於是,改為

std::string fontName = DICTOOL->getStringValue_json(options, P_FontName, "微軟雅黑");
// std::string fontFilePath = jsonPath.append(fontName);
label->setFontName(fontName);

編譯之後正常。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.