- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在转换一些代码以停止使用 char*,而是使用 std::string 来避免内存泄漏和/或缓冲区过载。
但是我遇到了一个出现上述错误的函数。我并没有真正改变太多 atm:
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#L59 https://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,但还是有同样的错误,所以最好尝试查明问题并从那里开始。
希望你能帮助新手 ;-)
最佳答案
我假设以下两行试图初始化一个字符串:
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
}
关于c++ - basic_string::_S_construct null 无效 - 不知道为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18769939/
我正在从命令行读取输入文件。 int main(int argc, char **argv) { Scene myScene; string filename = argv[1]; mySce
所以我将 Bison 用于我正在进行的项目。我的 Bison 文件看起来与此类似: %{ #include .... %} %union { int intVal; double dVal;
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我正在转换一些代码以停止使用 char*,而是使用 std::string 来避免内存泄漏和/或缓冲区过载。 但是我遇到了一个出现上述错误的函数。我并没有真正改变太多 atm: GuiText::Gu
我从数据库函数返回一个字符串或 NULL 到主程序,有时我从异常中得到这个错误: basic_string::_S_construct NULL not valid 我认为是因为数据库函数返回 NUL
我是 C++ 的新手,我尝试编写一个简单的字符串反向程序。当我编译它时,一切正常,但是当我运行它时,出现以下错误: terminate called after throwing an instanc
我在这个程序中收到 std::logic_error: basic_string::_s_construct null not valid。我该如何解决?我已经尝试过 previously poste
我一直在尝试将 cfg 读入多重链接列表,但我收到此错误,请有人帮忙。它不断给出这个错误。我不认为有什么错误。请检查这段代码并告诉我哪里有错误导致程序崩溃并出现图片中所附的异常 #include
在这里,我尝试使用 send() 方法将字符串发送到函数参数中并作为套接字中的参数。 user_main.cpp int main(int argc, char *argv[] ) { con
在 Debian 上,我需要读取一个环境变量,否则返回一个空字符串。这是我的代码: std::string getEnv(std::string var) { char* val = ::ge
if(player!=NULL) player->shuffled(); 我这样做是为了避免将空引用传递给字符串构造函数,但是在编译时仍然会出错。 最佳答案 不知何故,您正在调用 std::s
我是一名优秀的程序员,十分优秀!