わかりましたので、更新して画面に反映できる整数を表示しようとしました。(例: マウス位置の x 座標と y 座標を表示する)、思い通りに実行されましたが、古き良きタスク マネージャーを開くと、7 分間実行した後に約 600 MB に達したことがわかりました。画面にレンダリングした整数をコメントアウトしたとき(描画または更新されないように)。プログラムは、7 分後に 20MB 前後で停止しました。私は問題を見つけることができませんでした。誰かが私がどこで間違ったのかを理解するのを手伝ってくれますか? ありがとう。
//TextMangager.h
#pragma once
#ifndef TEXTMANAGER_H
#define TEXTMANAGER_H
#include <SDL_ttf.h>
#include "graphicsManager.h"
#include <sstream>
struct textManager{
public:
textManager(){}
~textManager();
void SetText(std::string msg, int x, int y);
void draw();
void setFont(std::string filepath, int size);
void changeFontSize(int size);
int getWidth();
int getHeight();
void setColor(int r, int g, int b);
void intToString(Uint32 number, int x, int y);
private:
TTF_Font*font;
SDL_Texture*texture;
SDL_Rect dst;
SDL_Rect src;
SDL_Surface*surface;
SDL_Color color;
std::stringstream ss;
std::string text;
};
#endif // TEXTMANAGER_H
//TextManager.cpp の一部
void textManager::intToString(Uint32 number, int x, int y)
{
ss << number;
text = ss.str().c_str();
surface = TTF_RenderText_Blended(font, text.c_str(), color);
if (surface == NULL)
cout << "surface is NULL \n" << SDL_GetError() << "\n";
texture = SDL_CreateTextureFromSurface(Gfx::Instance()->getRenderer(), surface);
SDL_FreeSurface(surface);
src.x = 0;
src.y = 0;
src.w = dst.w = surface->w;
src.h = dst.h = surface->h;
dst.x = x;
dst.y = y;
SDL_QueryTexture(texture, NULL, NULL, &src.w, &src.h);
ss.str(std::string().c_str());
}
void textManager::draw()
{
SDL_RenderCopy(Gfx::Instance()->getRenderer(), texture, &src, &dst);
}
textManager::~textManager()
{
if (texture != NULL)
SDL_DestroyTexture(texture);
font = NULL;
surface = NULL;
ss.clear();
delete surface;
}