So, I've been searching relentlessly in my code for this tiny little bug, and I cannot find it at all. I've looked at references, passes, types, arguments, and every other constructor. My code returns a boolean true when asking if texture == NULL. I've checked everything possibly related to this texture. I've never had this problem before, and it makes zero sense to me. Here's the class cSprite constructor that takes the renderer and loads a texture with it:
cSprite::cSprite(SDL_Renderer* passed_renderer, std::string passed_filepath, //...//) {
renderer = passed_renderer;
if (renderer == NULL) {
*errorcheck = true;
}
texture = NULL;
texture = IMG_LoadTexture(renderer, passed_filepath.c_str());
if (texture == NULL) {
*errorcheck = true;
}
Any one have a clue what I did wrong? Here's the passing of the renderer in a while loop function of another class (which contains both headers of the other classes cSprite and cSetup):
std::string CurrentFilePath;
CurrentFilePath = "mainbox.png";
cSpriteObj = new cSprite(cSetupObj->GetRenderer(),
CurrentFilePath, //...//);
For clarity's sake, here's the renderer's construction in cSetup:
renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) {
quit = true;
}
And the GetRenderer() function in that same class:
SDL_Renderer* cSetup::GetRenderer() {
return renderer;
}
I get no errors at all. I run it, and a white window appears for a moment, and disappears, since I have the while loop make it close if I recieve an error. I know there's no error messages to tell me if something went wrong, but when I did the error checks, I ran the code after each one I implemented. The window only froze. However, once I set up an error checker for texture, THAT'S when it closed itself. Can someone help? I have no idea what's wrong with the code. It has the exact same settings and headers as some other working SDL2 projects I have.
EDIT: I just rearranged the code instead. I'm not 100% sure what the issue was before, but I think I did something wrong equating the renderers. The functions now just take the passed renderer and use it directly.
SDL_GetError()? And how do you create/passerrorcheck? - olevegardcoutwhere you seterrorcheckto true. So, for instance, here :if (texture == NULL) { *errorcheck = true; }You should add soemthing likestd::cout << "Error! " << SDL_GetError() << std::endl;inside theifstatement - olevegard