Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ SDL/TTF:TTF_RenderText_Blended_Wrapped返回NULL_C++_Sdl_Truetype - Fatal编程技术网

C++ SDL/TTF:TTF_RenderText_Blended_Wrapped返回NULL

C++ SDL/TTF:TTF_RenderText_Blended_Wrapped返回NULL,c++,sdl,truetype,C++,Sdl,Truetype,这是我呈现文本的方法(file=Csurface.cpp): 当我试图将信息从循环中的向量渲染到屏幕时,该方法在一段时间后开始返回NULL。这似乎是在随机调用该方法之后发生的。仅当我尝试在循环中呈现文本(file=Capp\u OnRender.cpp)时才会发生这种情况: 要呈现到屏幕的字符串的文本看起来很好(不是空的/NULL)。曲面(surf_return)为空的原因可能是什么 异常消息: CaseL.CPP 30在Game.exe 0x76Dcc42D中抛出的异常:微软C++异常:内存

这是我呈现文本的方法(file=Csurface.cpp):

当我试图将信息从循环中的向量渲染到屏幕时,该方法在一段时间后开始返回NULL。这似乎是在随机调用该方法之后发生的。仅当我尝试在循环中呈现文本(file=Capp\u OnRender.cpp)时才会发生这种情况:

要呈现到屏幕的字符串的文本看起来很好(不是空的/NULL)。曲面(surf_return)为空的原因可能是什么

异常消息:

CaseL.CPP 30在Game.exe 0x76Dcc42D中抛出的异常:微软C++异常:内存位置0x00 32 e950。


我可以读取内存不足的
消息

使用后,您必须释放
surf\u text\u increment
,这样可以避免内存泄漏。像这样:

BOOST_FOREACH(Incredient & incredient_value, v_incredients)
    {
        if (y > G_SCREEN_HEIGHT / 100 * 95) {
            x_buttons = G_SCREEN_WIDTH / 100 * 40;
            x_text = G_SCREEN_WIDTH / 100 * 41;
            y = G_SCREEN_HEIGHT / 100 * 20;
        }
        std::string text_incredient = i_game_logic.get_text_incredient(incredient_value);
        surf_text_incredient = Csurface::onLoadText(text_incredient.c_str(), font_large, text_color, G_SCREEN_WIDTH / 100 * 30);
        if (surf_list_incredients != NULL) {
            y_text = y + G_SCREEN_HEIGHT / 100 * 1;
            Csurface::OnDraw(surf_list_incredients, surf_button_buy, x_buttons, y);
            Csurface::OnDraw(surf_list_incredients, surf_text_incredient, x_text, y_text);
            y += G_SCREEN_HEIGHT / 100 * 7;
        }
        else {
            throw 30;
        }
        SDL_FreeSurface(surf_text_incredient);
    }

我可以读取内存不足的
消息

使用后,您必须释放
surf\u text\u increment
,这样可以避免内存泄漏。像这样:

BOOST_FOREACH(Incredient & incredient_value, v_incredients)
    {
        if (y > G_SCREEN_HEIGHT / 100 * 95) {
            x_buttons = G_SCREEN_WIDTH / 100 * 40;
            x_text = G_SCREEN_WIDTH / 100 * 41;
            y = G_SCREEN_HEIGHT / 100 * 20;
        }
        std::string text_incredient = i_game_logic.get_text_incredient(incredient_value);
        surf_text_incredient = Csurface::onLoadText(text_incredient.c_str(), font_large, text_color, G_SCREEN_WIDTH / 100 * 30);
        if (surf_list_incredients != NULL) {
            y_text = y + G_SCREEN_HEIGHT / 100 * 1;
            Csurface::OnDraw(surf_list_incredients, surf_button_buy, x_buttons, y);
            Csurface::OnDraw(surf_list_incredients, surf_text_incredient, x_text, y_text);
            y += G_SCREEN_HEIGHT / 100 * 7;
        }
        else {
            throw 30;
        }
        SDL_FreeSurface(surf_text_incredient);
    }

printf的输出是什么(“错误:%s”,TTF_GetError())?您能在
TTF\u RenderText\u Blended\u Wrapped
之后添加上一行吗?抱歉,我花了一些时间重新报告错误;我现在得到:“Game.exe中的0x76Dcc42D抛出异常:微软C++异常:内存位置0x00Game.exe 0x76Dcc42D中的MexyExpExpRebug的异常CsPur.CPP30OUT:微软C++异常:内存位置0x00在Game.exe 0x76Dcc42D中抛出的异常CppyOnRelord.CPP30异常:微软C++异常:内存位置0x00 34 e8d8的int。“是代码> CppyOnReald.CPP < /代码>文件之一?它是包含循环的文件,其中OnLoad TrimeTo()函数被命名为<代码> Print(“错误:%s”,TTFFGETError())的输出。你能在代码< TTFFEnter TrimeByEndDyBux[/Cuth]之后添加前面的行吗?抱歉占用了我一些时间来重述错误;我现在得到:“在Game.exe 0x76Dcc42D中抛出的异常:微软C++异常:内存位置0x00Game.exe 0x76Dcc42D中的MexyExpExpRebug的异常CsPur.CPP30OUT:微软C++异常:内存位置0x00在Game.exe 0x76Dcc42D中抛出的异常CppyOnRelord.CPP30异常:微软C++异常:内存位置0x00 34 e8d8的int。“<代码> CppyOnReald.CPP < /Cord>文件之一?它是包含OnLoad Trk()函数调用的循环文件。
BOOST_FOREACH(Incredient & incredient_value, v_incredients)
    {
        if (y > G_SCREEN_HEIGHT / 100 * 95) {
            x_buttons = G_SCREEN_WIDTH / 100 * 40;
            x_text = G_SCREEN_WIDTH / 100 * 41;
            y = G_SCREEN_HEIGHT / 100 * 20;
        }
        std::string text_incredient = i_game_logic.get_text_incredient(incredient_value);
        surf_text_incredient = Csurface::onLoadText(text_incredient.c_str(), font_large, text_color, G_SCREEN_WIDTH / 100 * 30);
        if (surf_list_incredients != NULL) {
            y_text = y + G_SCREEN_HEIGHT / 100 * 1;
            Csurface::OnDraw(surf_list_incredients, surf_button_buy, x_buttons, y);
            Csurface::OnDraw(surf_list_incredients, surf_text_incredient, x_text, y_text);
            y += G_SCREEN_HEIGHT / 100 * 7;
        }
        else {
            throw 30;
        }
        SDL_FreeSurface(surf_text_incredient);
    }