[英]SDL_FreeSurface is not freeing RAM / RAM Overflowing
我認為是一個簡單的問題,但我在釋放表面時遇到問題,因為即使我將 SDL_FreeSurface() 添加到我的代碼中,RAM 也會溢出。 沒有這個 function RAM 很好。 這段代碼中還有更多“免費”的東西嗎? 此代碼試圖在屏幕頂部制作文本(乒乓球比賽得分)。
TTF_Init();
TTF_Font* arial = TTF_OpenFont("arial.ttf", 32);
SDL_Color msg_color = { 255,255,255 };
char msg[128];
sprintf_s(msg, "%d %d", g_SCORE_P_LEFT, g_SCORE_P_RIGHT);
SDL_Surface* messageSurface = TTF_RenderText_Solid(arial, msg, msg_color);
SDL_Texture* Message = SDL_CreateTextureFromSurface(m_game_window_renderer, messageSurface);
SDL_Rect msg_rect;
msg_rect.x = 50;
msg_rect.y = 50;
msg_rect.w = 30;
msg_rect.h = 30;
SDL_RenderCopy(m_game_window_renderer, Message, NULL, &msg_rect);
SDL_FreeSurface(messageSurface);
TTF_Quit();
您正在釋放表面,但並未釋放基於它創建的紋理。 將此行添加到末尾:
SDL_DestroyTexture(Message);
您還需要關閉字體:
TTF_CloseFont(arial);
關閉 SDL_TTF 也是一種很好的做法。 在 SDL_Quit(); 之前添加這一行
TTF_Quit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.