Highscore Memory Overflow Bug fixed
This commit is contained in:
parent
5b42e91728
commit
8dbdf176f3
@ -18,6 +18,7 @@ TTF_Font * font = NULL;
|
|||||||
|
|
||||||
void HIGHSCORES_Initialize(){
|
void HIGHSCORES_Initialize(){
|
||||||
printf("Initializing Highscores...\n");
|
printf("Initializing Highscores...\n");
|
||||||
|
Message_rect = (SDL_Rect) {.x = 0, .y = 0, .w = 2, .h = 2 };
|
||||||
White = (SDL_Color) {255, 255, 255 };
|
White = (SDL_Color) {255, 255, 255 };
|
||||||
ul = malloc(10 * sizeof(User));
|
ul = malloc(10 * sizeof(User));
|
||||||
font = TTF_OpenFont("assets/fonts/monofur.ttf", 48);
|
font = TTF_OpenFont("assets/fonts/monofur.ttf", 48);
|
||||||
@ -58,15 +59,17 @@ void HIGHSCORES_Draw(SDL_Renderer * renderer){
|
|||||||
Message_rect.y = 70;
|
Message_rect.y = 70;
|
||||||
Message_rect.x = 50;
|
Message_rect.x = 50;
|
||||||
SDL_RenderCopy(renderer, Message, NULL, &Message_rect);
|
SDL_RenderCopy(renderer, Message, NULL, &Message_rect);
|
||||||
|
SDL_DestroyTexture(Message);
|
||||||
while (count < entriesGot) {
|
while (count < entriesGot) {
|
||||||
sprintf(buffer, format, ul[count].Username, ul[count].Score);
|
sprintf(buffer, format, ul[count].Username, ul[count].Score);
|
||||||
HIGHSCORES_GenerateTexture(renderer, buffer);
|
HIGHSCORES_GenerateTexture(renderer, buffer);
|
||||||
Message_rect.y = ((Message_rect.h + 10) * (count + 1)) + 140;
|
Message_rect.y = ((Message_rect.h + 10) * (count + 1)) + 140;
|
||||||
Message_rect.x = 50;
|
Message_rect.x = 50;
|
||||||
SDL_RenderCopy(renderer, Message, NULL, &Message_rect);
|
SDL_RenderCopy(renderer, Message, NULL, &Message_rect);
|
||||||
|
SDL_DestroyTexture(Message);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
} /* HIGHSCORES_Draw */
|
||||||
|
|
||||||
void HIGHSCORES_Deinitialize(){
|
void HIGHSCORES_Deinitialize(){
|
||||||
printf("De-initializing Highscores...\n");
|
printf("De-initializing Highscores...\n");
|
||||||
@ -84,7 +87,9 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer, char * text){
|
|||||||
TTF_SizeText(font, text, &w, &h);
|
TTF_SizeText(font, text, &w, &h);
|
||||||
surfaceMessage = TTF_RenderText_Solid(font, text, White); // as TTF_RenderText_Solid could only be used on SDL_Surface then you have to create the surface first
|
surfaceMessage = TTF_RenderText_Solid(font, text, White); // as TTF_RenderText_Solid could only be used on SDL_Surface then you have to create the surface first
|
||||||
Message = SDL_CreateTextureFromSurface(renderer, surfaceMessage); // now you can convert it into a texture
|
Message = SDL_CreateTextureFromSurface(renderer, surfaceMessage); // now you can convert it into a texture
|
||||||
Message_rect = (SDL_Rect) {.x = 0, .y = 0, .w = w, .h = h }; // create a rect
|
SDL_FreeSurface(surfaceMessage);
|
||||||
|
Message_rect.w = w;
|
||||||
|
Message_rect.h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HIGHSCORES_ReloadList(int * usercount){
|
void HIGHSCORES_ReloadList(int * usercount){
|
||||||
|
Loading…
Reference in New Issue
Block a user