when I am trying to render multi lines of text I get this exception ("Exception thrown at 0x00000000710020BA (SDL2_ttf.dll) in Project16-test record.exe: 0xC0000005: Access violation reading location 0x0000000000000008. occurred")
and this is my code:
#include "Ltext.h"
TTF_Font *gFont = TTF_OpenFont("carson.ttf", 24);
SDL_Color gTextColor = { 0, 0, 0, 0xFF };
Ltext::Ltext()
{
texy = 0;
texw = 0;
texh = 0;
mTexture = NULL;
textSurface = NULL;
gRecordingDeviceCount = 0;
}
Ltext::~Ltext()
{
}
void Ltext::loadtext(const char* text, SDL_Color textColor,SDL_Renderer* gren)
{
free();
SDL_SetRenderDrawColor(gren, 255, 255, 255, 255);
SDL_RenderClear(mrender);
//Render text surface
textSurface = TTF_RenderText_Solid(gFont, text, textColor);
if(textSurface != NULL)
{
//Create texture from surface pixels
mTexture = SDL_CreateTextureFromSurface(gren, textSurface);
if (mTexture == NULL)
{
printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError());
}
//Get rid of old surface
SDL_FreeSurface(textSurface);
}
else
{
printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());
}
int x = 0;
SDL_QueryTexture(mTexture, NULL, NULL, &texw, &texh);
SDL_Rect dest = { 0,texy,texw,texh };
SDL_RenderCopy(gren, mTexture, NULL, &dest);
SDL_RenderPresent(gren);
texy = texy + 25;
}
void Ltext::free()
{
//Free texture if it exists
if (mTexture != NULL)
{
SDL_DestroyTexture(mTexture);
mTexture = NULL;
}
}