basic_string::_S_construct null 无效 - 不知道为什么?

basic_string::_S_construct null not valid - can't figure out why?

本文关键字:不知道 为什么 无效 construct string basic null      更新时间:2023-10-16

我正在转换一些代码,以便停止使用 char*,并使用 std::string 来避免内存泄漏和/或缓冲区过载。

但是我遇到了一个函数,我得到了上述错误。我并没有真正改变太多自动取款机:

GuiText::GuiText(std::string t, int s, XeColor c) {
origText = NULL;
text = NULL;
size = s;
color = c;
alpha = c.a;
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
maxWidth = 0;
wrap = false;
textDynNum = 0;
textScroll = SCROLL_NONE;
textScrollPos = 0;
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
textScrollDelay = TEXT_SCROLL_DELAY;
alignmentHor = ALIGN_CENTRE;
alignmentVert = ALIGN_MIDDLE;
if (!t.empty()) {
    origText = strdup(t.c_str());
    text = charToWideChar(gettext(t.c_str()));
}
for (int i = 0; i < 20; i++)
    textDyn[i] = NULL;
}

所有代码都在这里 https://github.com/siz-/xmplayer/blob/temp/source/libwiigui/gui_text.cpp#L32

一切都是菊花,因为我有很多 GuiText 实例,但是当我在第 59 行和 gui.h 中使用 const char* 注释函数以实际使我的代码使用正确的函数时,我得到上述错误。我不明白为什么..

https://github.com/siz-/xmplayer/blob/temp/source/libwiigui/gui_text.cpp#L59https://github.com/siz-/xmplayer/blob/temp/source/libwiigui/gui.h#L685

如何使用它的示例:https://github.com/siz-/xmplayer/blob/temp/source/menu.cpp#L427

有什么想法吗?我已经转换了gui_text.cpp所有内容,但相同的错误,因此最好尝试查明问题并从那里开始。

希望你能帮助新手;-)

我假设以下 2 行正在尝试初始化字符串:

origText = NULL;
text = NULL;

它应该 1) 在初始值设定项列表中初始化,2) 如果它为空,则不需要,并且 3) 无效(您不能将字符串初始化为 NULL )。

GuiText::GuiText(std::string t, int s, XeColor c) :
    origText(t),
    size(s),
    color(c),
    alpha(c.a),
    style(FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE),
    // etc
{
    // etc
}
相关文章: