Trashing the stack at runtime???

Started by
10 comments, last by garyfletcher 18 years, 8 months ago
I'm 100% sure that your overwriting memory some how. Either on the stack or on the heap. Why dont you paste your code.
Advertisement
Okay..code is:

#include <cstdlib>#include <iostream>#include <windows.h>#include <SDL/SDL.h>#include <GL/gl.h>#include <boost/shared_ptr.hpp>#include "HeapFactory.h"#include "Profiler.h"#include "Log.h"#include "ObjectFactory.h"#include "Messages.h"#include "Settings.h"#include "Game.h"#include "Utility."#include "Kernel.h"DEFINE_HIERARCHICALHEAP(CPongTask, "Pong", "TaskHeap");DEFINE_HEAP(CApplication, "Application");bool CPongTask::Start(){			utility::InitRandomiser();			glMatrixMode(GL_PROJECTION);			glLoadIdentity();			glOrtho(0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f);			glClearColor(0.0f, 0.0f, 0.0f, 1.0f);			glShadeModel(GL_SMOOTH);			glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);			glEnable(GL_BLEND);			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);			paddleWidth=0.1f; paddleHeight=0.01f;			p1pos=p2pos=0.5f;			ballX=0.5f; ballY=0.5f;			ballVX=(float)(rand()%20-10)/20;			ballVY=(float)(rand()%20-10)/20;			ballSize=0.01f;			return true;}		void CPongTask ::Update(){			glClear(GL_COLOR_BUFFER_BIT);			if(CInputTask::mouseDown(SDL_BUTTON_LEFT))kernel::CKernel::GetSingleton().KillAllTasks();			glBegin(GL_QUADS);			{				glColor4f(1.0f,1.0f,1.0f,1.0f);								//draw the ball				glVertex2f(ballX-ballSize, ballY-ballSize);				glVertex2f(ballX+ballSize, ballY-ballSize);				glVertex2f(ballX+ballSize, ballY+ballSize);				glVertex2f(ballX-ballSize, ballY+ballSize);								//paddles				glVertex2f(p2pos-paddleWidth, 0);				glVertex2f(p2pos+paddleWidth, 0);				glVertex2f(p2pos+paddleWidth, paddleHeight);				glVertex2f(p2pos-paddleWidth, paddleHeight);				glVertex2f(p1pos-paddleWidth, 1-paddleHeight);				glVertex2f(p1pos+paddleWidth, 1-paddleHeight);				glVertex2f(p1pos+paddleWidth, 1);				glVertex2f(p1pos-paddleWidth, 1);			}			glEnd();			p1pos+=((float)CInputTask::dX)/200.0f;			if(p1pos<paddleWidth)p1pos=paddleWidth;			if(p1pos>1-paddleWidth)p1pos=1-paddleWidth;			ballX+=ballVX*CGlobalTimer::dT; ballY+=ballVY*CGlobalTimer::dT;			if(ballX<ballSize)ballVX=utility::qAbs(ballVX);			if(ballX>1-ballSize)ballVX=-utility::qAbs(ballVX);			if(ballY<ballSize+paddleHeight)			{				if((ballX>p2pos-paddleWidth)&&(ballX<p2pos+paddleWidth))				{					ballVY=utility::qAbs(ballVY);				}else{					kernel::CKernel::GetSingleton().KillAllTasks();				}			}			if(ballY>1-ballSize-paddleHeight)			{				if((ballX>p1pos-paddleWidth)&&(ballX<p1pos+paddleWidth))				{					ballVY=-utility::qAbs(ballVY);				}else{					kernel::CKernel::GetSingleton().KillAllTasks();				}			}			if(ballX>p2pos)p2pos+=0.1f*CGlobalTimer::dT;			if(ballX<p2pos)p2pos-=0.1f*CGlobalTimer::dT;			if(p2pos<paddleWidth)p2pos=paddleWidth;			if(p2pos>1-paddleWidth)p2pos=1-paddleWidth;}void CApplication::Run(int argc, char *argv[]){	//open logfiles	if(!logger::CLogger::Get().Init())return;	//create a couple of singletons	CSettingsManager* CSm = new CSettingsManager();	kernel::CKernel* CKer = new kernel::CKernel();	//parse the 'settings.eng' file	CSm->GetSingletonPtr()->ParseFile("settings.esf");		//parse command-line arguments	//skip the first argument, which is always the program name	if(argc>1)		for(int i=1;i<argc;i++)			CSm->GetSingletonPtr()->ParseSetting(std::string(argv));    	videoTask = boost::shared_ptr<CVideoUpdate>(new CVideoUpdate());	videoTask->priority=10000;	CKer->GetSingletonPtr()->AddTask(videoTask);	inputTask = boost::shared_ptr<CInputTask>(new CInputTask());	inputTask->priority=20;	CKer->GetSingletonPtr()->AddTask(inputTask);	soundTask = boost::shared_ptr<CSoundTask>(new CSoundTask());	soundTask->priority=50;	CKer->GetSingletonPtr()->AddTask(soundTask);	globalTimer = boost::shared_ptr<CGlobalTimer>(new CGlobalTimer());	globalTimer->priority=10;	CKer->GetSingletonPtr()->AddTask(globalTimer);	boost::shared_ptr<CPongTask> pong = boost::shared_ptr<CPongTask>(new CPongTask());	pong->priority=100;	CKer->GetSingletonPtr()->AddTask(pong);	//set up the profiler with an output handler	profile::CProfileLogHandler profileLogHandler;	profile::CProfileSample::outputHandler=&profileLogHandler;	//main game loop	CKer->GetSingletonPtr()->Execute();		//clean up singletons	delete CKer->GetSingletonPtr();	delete CSm->GetSingletonPtr();}int main(int argc, char *argv[]){    std::cout << "Starting app - open logs" << std::endl;        int bookmark = HeapFactory::GetMemoryBookmark ();    	//open logfiles	if(!logger::CLogger::Get().Init())return 1;		logger::CLogger::Get().Write(LOG_APP,"Started");		    	CApplication* CApp = new CApplication();	CApp->GetSingletonPtr()->Run(argc,argv);	delete CApp->GetSingletonPtr();			logger::CLogger::Get().Write(LOG_APP,"Ended");	HeapFactory::PrintInfo ();    HeapFactory::ReportMemoryLeaks (bookmark);	return 0;}


If you need more let me know..:)
Gary.Goodbye, and thanks for all the fish.

This topic is closed to new replies.

Advertisement