I don't see any place where you change the value of 'bLoadMedia' apart from when you initialize it.
Anyone got any ideas where 4k a sec is coming from?
does this delete the pointer to node originally created of is this now a dangling pointer?
sorry GD.net died 3 times when posting and then it locked me out, and then there was food!
Node* pTBDel= head;
delete pTBDel->current;///DELETE THE ITEM REFERENCE
delete pTBDel;///DELETE THE POINTER
head= head->next;
count--;
DUH!!! Don't delete the reference to head before moving it forwards, I put the delete before changing head's pointer reference.
head= head->next; ///UPDATE THE SMEGGING REFERENCE FIRST
delete pTBDel->current;///DELETE THE ITEM REFERENCE
delete pTBDel;///DELETE THE POINTER
//head= head->next;
Sorry to be a pain, I do try and solve these things myself generally but this one was driving me mad.
And strangely enough was the cause of the other memory leak as well, I have no idea how they were linked as it shouldn't have been calling until input was passed to the program through the keyboard.
As always I have a lot to learn and no time to learn it in lol.
(1) Use standard containers (of objects, not pointers) instead of rolling your own data structures.
(2) Use a smart pointer (probably std::unique_ptr) when you need polymorphism.
(3) Be very clear about which object owns which resource, and release the resource in the object's destructor.
I haven't had a memory leak in many years.
Hindsight is a wonderful thing, sometimes you just need to be that kid falling flat on your face to realize that's why people don't do it.
But... I have a vision, it is a very stubborn one. Until I know I can't do it, i'm not taking anyone else's word on it ;)
I'm still no closer to figuring out why my program is causing infinitely exponential 4k from what seems to be SDL_RenderPresent(Renderer);
Any ideas, i've isolated the issue right down to basics:
#include <SDL2/SDL.h>
#include <iostream>
#include <stdio.h>
#define WINDOW_HANDLE "BasicEngine strip down"
///MAIN VARIABLES
bool appRunning= true;
const int WindowWidth = 1024;
const int WindowHeight = 768;
SDL_Rect screenCoords;
SDL_Window* Window= NULL;
SDL_Renderer* Renderer= NULL;
///FORWARD DECLARATIONS
bool OnInit();
bool fLoadMedia();
void OnEvent(SDL_Event* Event);
void OnLoop();
void OnRender();
void OnCleanup();
int main(int argc, char* argv[])
{
if(!OnInit()) { return false; }
SDL_Event Event;
while(appRunning)
{
while(SDL_PollEvent(&Event)!= 0)
{
OnEvent(&Event);
}
OnRender(); ///WTF ARE THESE CAUSING EXPONENTIAL MEMORY CREATION!?
}
OnCleanup();
return false;
}
bool OnInit()
{
if(SDL_Init(SDL_INIT_VIDEO)!= 0)
{
printf("Unable to Init SDL: %s", SDL_GetError());
return false;
} else {
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
if(
(Window=
SDL_CreateWindow(
WINDOW_HANDLE,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
WindowWidth,
WindowHeight,
SDL_WINDOW_SHOWN)
)==nullptr)
{
return false;
}
if((Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ))== nullptr) {
return false;
}
}
return true;
}
void OnEvent(SDL_Event* Event)
{
if(Event->type== SDL_QUIT) appRunning= false;
if(Event->type== SDL_KEYDOWN)
{
switch(Event->key.keysym.sym)
{
case SDLK_ESCAPE:
appRunning= false;
break;
}
}
}
void OnRender()
{
///WTF ARE THESE CAUSING EXPONENTIAL MEMORY CREATION!?
SDL_SetRenderDrawColor(Renderer, 100, 0x00, 200, 0xFF);
SDL_RenderClear(Renderer);
///UPDATE THE SCREEN
SDL_RenderPresent(Renderer);
}
void OnCleanup()
{
if(Renderer)
{
SDL_DestroyRenderer(Renderer);
Renderer= nullptr;
}
if(Window)
{
SDL_DestroyWindow(Window);
Window= nullptr;
}
SDL_Quit();
}
When writing any software, there are too many actual challenges to spend time chasing ghosts.
Games/Projects Currently In Development:
Discord RPG Bot | D++ - The Lightweight C++ Discord API Library | TriviaBot Discord Trivia Bot