basic_string::_S_construct null 无效 - 不知道为什么?
basic_string::_S_construct null not valid - can't figure out why?
我正在转换一些代码,以便停止使用 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
}
相关文章:
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 我不知道为什么这段代码会让核心被转储?
- 反转字符串.不知道为什么这个逻辑是错误的.C++
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- if-else 语句仅按特定顺序工作,我不知道为什么
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 函数抛出seg错误,我不知道为什么
- 我不知道为什么复制构造函数的调用在 c++ 中不稳定
- 随着时间的推移,我的程序越来越慢,我不知道为什么.内存泄漏
- 分段故障(核心转储)-不知道为什么
- "错误:在'.标记'之前出现预期的主表达式,我不知道为什么
- 我正在制作c ++代码,但发生错误我不知道为什么
- std::cout << glGetString(GL_RENDER) << std::endl;抛出错误但不GL_Renderer或GL_Verision,我不知道为什么?
- 不知道为什么它不会停止循环
- 我的Arduino串行命令行不起作用,我不知道为什么
- 我正在编写一个拆分为 3 的合并排序,我不知道为什么它不起作用
- C++单例模式代码无法运行,不知道为什么?
- 我不知道为什么我的矢量无法推回
- 罗马数字输出C++总是"-858993460",不知道为什么?
- 合成错误不知道为什么会发生这种情况,请检查一下并告诉我这是我的编码还是视觉工作室