Unhandled Exception thrown in SDL_CreateTextureFromSurface

Hello I am trying to make a small game and I follow this tutorial for the framework https://www.youtube.com/watch?v=bKiejuOaJtU&list=PLhJr2LOK-xwxQlevIZ97ZABLw72Eu9he7&index=4. I am working with Visual Studio 2019, In my Graphic.cpp in the class SDL_Texture* Graphics::LoadTexture I convert the surface into a texture to be able to render it using the renderer. However I am getting an Unhandled Exception and I cant figure out why?

Here I uploaded the error and the header code.Thanks in advance!

//---------------------------------------------------------------
// Graphics
//---------------------------------------------------------------

class Graphics {

public:
static const int SCREEN_WIDTH = 800;
static const int SCREEN_HEIGHT = 600;

private:
static Graphics* sInstance;
static bool sInitialize;

SDL_Window* mWindow;
SDL_Surface* mBackBuffer;
SDL_Renderer* mRenderer;

public:
static Graphics* Instance();
static void Release();
static bool Initialized();

SDL_Texture* LoadTexture(std::string path);
SDL_Texture* CreateTextTexture(TTF_Font* font, std::string text);

void ClearBackBuffer();

void DrawTexture(SDL_Texture* tex, SDL_Rect* clip = NULL, SDL_Rect* rend = NULL);

void Render();

private:
Graphics();
~Graphics();
bool Init();
};

#endif

Hi and welcome to the forum and the community.

As the error message states, you have received a read access violation error, which means that you’re trying to read/use an uninitialized part of memory. The error message also states that “this was nullptr”, which makes me think that your Graphics class instance isn’t initialized/created properly.

By looking at your code, I can see that you have a static Graphics* sInstance variable, and I assume some kind of singleton pattern is supposed to be used in the class.
Have you maybe forgotten to execute the Instance() function to initialize the Graphics instance, before using that specific class and executing other functions in it?

Yes I checked that later on and was able to resolved, thank your for responding!