Removed many memoryleaks in Example Browser, reducing some technical debt.
When running the Example Browser with Basic Example, 'visual leak detector' show no leak. Many other individual examples still leak, so it is work-in-progress. Disabled the profiler window (too many leaks)
This commit is contained in:
@@ -42,19 +42,65 @@
|
||||
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
|
||||
#include "../Importers/ImportBullet/SerializeSetup.h"
|
||||
|
||||
#include "Bullet3Common/b3HashMap.h"
|
||||
|
||||
struct GL3TexLoader : public MyTextureLoader
|
||||
{
|
||||
b3HashMap<b3HashString, GLint> m_hashMap;
|
||||
|
||||
virtual void LoadTexture(Gwen::Texture* pTexture)
|
||||
{
|
||||
Gwen::String namestr = pTexture->name.Get();
|
||||
const char* n = namestr.c_str();
|
||||
GLint* texIdPtr = m_hashMap[n];
|
||||
if (texIdPtr)
|
||||
{
|
||||
pTexture->m_intData = *texIdPtr;
|
||||
}
|
||||
}
|
||||
virtual void FreeTexture(Gwen::Texture* pTexture)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct OpenGLExampleBrowserInternalData
|
||||
{
|
||||
Gwen::Renderer::Base* m_gwenRenderer;
|
||||
CommonGraphicsApp* m_app;
|
||||
// MyProfileWindow* m_profWindow;
|
||||
btAlignedObjectArray<Gwen::Controls::TreeNode*> m_nodes;
|
||||
GwenUserInterface* m_gui;
|
||||
GL3TexLoader* m_myTexLoader;
|
||||
struct MyMenuItemHander* m_handler2;
|
||||
btAlignedObjectArray<MyMenuItemHander*> m_handlers;
|
||||
|
||||
OpenGLExampleBrowserInternalData()
|
||||
: m_gwenRenderer(0),
|
||||
m_app(0),
|
||||
// m_profWindow(0),
|
||||
m_gui(0),
|
||||
m_myTexLoader(0),
|
||||
m_handler2(0)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
static CommonGraphicsApp* s_app=0;
|
||||
|
||||
static CommonWindowInterface* s_window = 0;
|
||||
static CommonParameterInterface* s_parameterInterface=0;
|
||||
static CommonRenderInterface* s_instancingRenderer=0;
|
||||
static OpenGLGuiHelper* s_guiHelper=0;
|
||||
static MyProfileWindow* s_profWindow =0;
|
||||
//static MyProfileWindow* s_profWindow =0;
|
||||
static SharedMemoryInterface* sSharedMem = 0;
|
||||
|
||||
#define DEMO_SELECTION_COMBOBOX 13
|
||||
const char* startFileName = "0_Bullet3Demo.txt";
|
||||
char staticPngFileName[1024];
|
||||
static GwenUserInterface* gui = 0;
|
||||
//static GwenUserInterface* gui = 0;
|
||||
static GwenUserInterface* gui2 = 0;
|
||||
static int sCurrentDemoIndex = -1;
|
||||
static int sCurrentHightlighted = 0;
|
||||
static CommonExampleInterface* sCurrentDemo = 0;
|
||||
@@ -123,9 +169,9 @@ void MyKeyboardCallback(int key, int state)
|
||||
//b3Printf("key=%d, state=%d", key, state);
|
||||
bool handled = false;
|
||||
|
||||
if (gui && !handled )
|
||||
if (gui2 && !handled )
|
||||
{
|
||||
handled = gui->keyboardCallback(key, state);
|
||||
handled = gui2->keyboardCallback(key, state);
|
||||
}
|
||||
|
||||
if (!handled && sCurrentDemo)
|
||||
@@ -226,8 +272,8 @@ static void MyMouseMoveCallback( float x, float y)
|
||||
bool handled = false;
|
||||
if (sCurrentDemo)
|
||||
handled = sCurrentDemo->mouseMoveCallback(x,y);
|
||||
if (!handled && gui)
|
||||
handled = gui->mouseMoveCallback(x,y);
|
||||
if (!handled && gui2)
|
||||
handled = gui2->mouseMoveCallback(x,y);
|
||||
if (!handled)
|
||||
{
|
||||
if (prevMouseMoveCallback)
|
||||
@@ -244,8 +290,8 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
if (sCurrentDemo)
|
||||
handled = sCurrentDemo->mouseButtonCallback(button,state,x,y);
|
||||
|
||||
if (!handled && gui)
|
||||
handled = gui->mouseButtonCallback(button,state,x,y);
|
||||
if (!handled && gui2)
|
||||
handled = gui2->mouseButtonCallback(button,state,x,y);
|
||||
|
||||
if (!handled)
|
||||
{
|
||||
@@ -333,7 +379,10 @@ void selectDemo(int demoIndex)
|
||||
CommonExampleInterface::CreateFunc* func = gAllExamples->getExampleCreateFunc(demoIndex);
|
||||
if (func)
|
||||
{
|
||||
s_parameterInterface->removeAllParameters();
|
||||
if (s_parameterInterface)
|
||||
{
|
||||
s_parameterInterface->removeAllParameters();
|
||||
}
|
||||
int option = gAllExamples->getExampleOption(demoIndex);
|
||||
s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2);
|
||||
CommonExampleOptions options(s_guiHelper, option);
|
||||
@@ -341,12 +390,15 @@ void selectDemo(int demoIndex)
|
||||
sCurrentDemo = (*func)(options);
|
||||
if (sCurrentDemo)
|
||||
{
|
||||
if (gui)
|
||||
if (gui2)
|
||||
{
|
||||
gui->setStatusBarMessage("Status: OK", false);
|
||||
gui2->setStatusBarMessage("Status: OK", false);
|
||||
}
|
||||
b3Printf("Selected demo: %s",gAllExamples->getExampleName(demoIndex));
|
||||
gui->setExampleDescription(gAllExamples->getExampleDescription(demoIndex));
|
||||
if (gui2)
|
||||
{
|
||||
gui2->setExampleDescription(gAllExamples->getExampleDescription(demoIndex));
|
||||
}
|
||||
|
||||
sCurrentDemo->initPhysics();
|
||||
if(resetCamera)
|
||||
@@ -437,10 +489,10 @@ void MyComboBoxCallback(int comboId, const char* item)
|
||||
void MyGuiPrintf(const char* msg)
|
||||
{
|
||||
printf("b3Printf: %s\n",msg);
|
||||
if (gui)
|
||||
if (gui2)
|
||||
{
|
||||
gui->textOutput(msg);
|
||||
gui->forceUpdateScrollBars();
|
||||
gui2->textOutput(msg);
|
||||
gui2->forceUpdateScrollBars();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,10 +501,10 @@ void MyGuiPrintf(const char* msg)
|
||||
void MyStatusBarPrintf(const char* msg)
|
||||
{
|
||||
printf("b3Printf: %s\n", msg);
|
||||
if (gui)
|
||||
if (gui2)
|
||||
{
|
||||
bool isLeft = true;
|
||||
gui->setStatusBarMessage(msg,isLeft);
|
||||
gui2->setStatusBarMessage(msg,isLeft);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,12 +512,12 @@ void MyStatusBarPrintf(const char* msg)
|
||||
void MyStatusBarError(const char* msg)
|
||||
{
|
||||
printf("Warning: %s\n", msg);
|
||||
if (gui)
|
||||
if (gui2)
|
||||
{
|
||||
bool isLeft = false;
|
||||
gui->setStatusBarMessage(msg,isLeft);
|
||||
gui->textOutput(msg);
|
||||
gui->forceUpdateScrollBars();
|
||||
gui2->setStatusBarMessage(msg,isLeft);
|
||||
gui2->textOutput(msg);
|
||||
gui2->forceUpdateScrollBars();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +586,7 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
{
|
||||
// printf("select %d\n",m_buttonId);
|
||||
sCurrentHightlighted = m_buttonId;
|
||||
gui->setExampleDescription(gAllExamples->getExampleDescription(sCurrentHightlighted));
|
||||
gui2->setExampleDescription(gAllExamples->getExampleDescription(sCurrentHightlighted));
|
||||
}
|
||||
|
||||
void onButtonF(Gwen::Controls::Base* pControl)
|
||||
@@ -549,26 +601,6 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
|
||||
|
||||
|
||||
};
|
||||
#include "Bullet3Common/b3HashMap.h"
|
||||
|
||||
struct GL3TexLoader : public MyTextureLoader
|
||||
{
|
||||
b3HashMap<b3HashString,GLint> m_hashMap;
|
||||
|
||||
virtual void LoadTexture( Gwen::Texture* pTexture )
|
||||
{
|
||||
Gwen::String namestr = pTexture->name.Get();
|
||||
const char* n = namestr.c_str();
|
||||
GLint* texIdPtr = m_hashMap[n];
|
||||
if (texIdPtr)
|
||||
{
|
||||
pTexture->m_intData = *texIdPtr;
|
||||
}
|
||||
}
|
||||
virtual void FreeTexture( Gwen::Texture* pTexture )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void quitCallback()
|
||||
@@ -623,7 +655,7 @@ struct QuickCanvas : public Common2dCanvasInterface
|
||||
|
||||
m_curNumGraphWindows++;
|
||||
|
||||
MyGraphInput input(gui->getInternalData());
|
||||
MyGraphInput input(gui2->getInternalData());
|
||||
input.m_width=width;
|
||||
input.m_height=height;
|
||||
input.m_xPos = 10000;//GUI will clamp it to the right//300;
|
||||
@@ -669,12 +701,50 @@ struct QuickCanvas : public Common2dCanvasInterface
|
||||
|
||||
OpenGLExampleBrowser::OpenGLExampleBrowser(class ExampleEntries* examples)
|
||||
{
|
||||
m_internalData = new OpenGLExampleBrowserInternalData;
|
||||
|
||||
gAllExamples = examples;
|
||||
}
|
||||
|
||||
OpenGLExampleBrowser::~OpenGLExampleBrowser()
|
||||
{
|
||||
deleteDemo();
|
||||
deleteDemo();
|
||||
for (int i = 0; i < m_internalData->m_nodes.size(); i++)
|
||||
{
|
||||
delete m_internalData->m_nodes[i];
|
||||
}
|
||||
delete m_internalData->m_handler2;
|
||||
for (int i = 0; i < m_internalData->m_handlers.size(); i++)
|
||||
{
|
||||
delete m_internalData->m_handlers[i];
|
||||
}
|
||||
m_internalData->m_handlers.clear();
|
||||
m_internalData->m_nodes.clear();
|
||||
delete s_parameterInterface;
|
||||
s_parameterInterface = 0;
|
||||
delete s_app->m_2dCanvasInterface;
|
||||
s_app->m_2dCanvasInterface = 0;
|
||||
|
||||
m_internalData->m_gui->exit();
|
||||
|
||||
|
||||
delete m_internalData->m_gui;
|
||||
delete m_internalData->m_gwenRenderer;
|
||||
delete m_internalData->m_myTexLoader;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
delete m_internalData->m_app;
|
||||
s_app = 0;
|
||||
|
||||
|
||||
|
||||
// delete m_internalData->m_profWindow;
|
||||
|
||||
delete m_internalData;
|
||||
|
||||
gAllExamples = 0;
|
||||
}
|
||||
|
||||
@@ -732,11 +802,10 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
char title[1024];
|
||||
sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode);
|
||||
simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina);
|
||||
|
||||
|
||||
s_app = simpleApp;
|
||||
}
|
||||
#endif
|
||||
m_internalData->m_app = s_app;
|
||||
char* gVideoFileName = 0;
|
||||
args.GetCmdLineArgument("mp4",gVideoFileName);
|
||||
#ifndef NO_OPENGL3
|
||||
@@ -792,43 +861,67 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
{
|
||||
GL3TexLoader* myTexLoader = new GL3TexLoader;
|
||||
m_internalData->m_myTexLoader = myTexLoader;
|
||||
|
||||
gui = new GwenUserInterface;
|
||||
GL3TexLoader* myTexLoader = new GL3TexLoader;
|
||||
|
||||
Gwen::Renderer::Base* gwenRenderer = 0;
|
||||
if (sUseOpenGL2 )
|
||||
{
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
}
|
||||
sth_stash* fontstash = simpleApp->getFontStash();
|
||||
|
||||
if (sUseOpenGL2)
|
||||
{
|
||||
m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
}
|
||||
#ifndef NO_OPENGL3
|
||||
else
|
||||
{
|
||||
sth_stash* fontstash=simpleApp->getFontStash();
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader);
|
||||
}
|
||||
else
|
||||
{
|
||||
sth_stash* fontstash = simpleApp->getFontStash();
|
||||
m_internalData->m_gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer, fontstash, width, height, s_window->getRetinaScale(), myTexLoader);
|
||||
}
|
||||
#endif
|
||||
|
||||
gui2 = new GwenUserInterface;
|
||||
|
||||
m_internalData->m_gui = gui2;
|
||||
|
||||
m_internalData->m_myTexLoader = myTexLoader;
|
||||
|
||||
|
||||
|
||||
gui2->init(width, height, m_internalData->m_gwenRenderer, s_window->getRetinaScale());
|
||||
|
||||
|
||||
}
|
||||
//gui = 0;// new GwenUserInterface;
|
||||
|
||||
GL3TexLoader* myTexLoader = m_internalData->m_myTexLoader;
|
||||
// = myTexLoader;
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
gui->init(width,height,gwenRenderer,s_window->getRetinaScale());
|
||||
|
||||
|
||||
|
||||
|
||||
// gui->getInternalData()->m_explorerPage
|
||||
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl;
|
||||
if (gui2)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// gui->getInternalData()->m_explorerPage
|
||||
Gwen::Controls::TreeControl* tree = gui2->getInternalData()->m_explorerTreeCtrl;
|
||||
|
||||
|
||||
//gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader);
|
||||
|
||||
|
||||
// s_profWindow= setupProfileWindow(gui2->getInternalData());
|
||||
//m_internalData->m_profWindow = s_profWindow;
|
||||
// profileWindowSetVisible(s_profWindow,false);
|
||||
gui2->setFocus();
|
||||
|
||||
s_parameterInterface = s_app->m_parameterInterface = new GwenParameterInterface(gui2->getInternalData());
|
||||
s_app->m_2dCanvasInterface = new QuickCanvas(myTexLoader);
|
||||
|
||||
//gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader);
|
||||
|
||||
|
||||
s_profWindow= setupProfileWindow(gui->getInternalData());
|
||||
profileWindowSetVisible(s_profWindow,false);
|
||||
gui->setFocus();
|
||||
|
||||
s_parameterInterface = s_app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData());
|
||||
s_app->m_2dCanvasInterface = new QuickCanvas(myTexLoader);
|
||||
|
||||
|
||||
///add some demos to the gAllExamples
|
||||
|
||||
@@ -839,7 +932,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
//int curDemo = 0;
|
||||
int selectedDemo = 0;
|
||||
Gwen::Controls::TreeNode* curNode = tree;
|
||||
MyMenuItemHander* handler2 = new MyMenuItemHander(-1);
|
||||
m_internalData->m_handler2 = new MyMenuItemHander(-1);
|
||||
|
||||
char* demoNameFromCommandOption = 0;
|
||||
args.GetCmdLineArgument("start_demo_name", demoNameFromCommandOption);
|
||||
@@ -847,7 +940,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
selectedDemo = -1;
|
||||
}
|
||||
|
||||
tree->onReturnKeyDown.Add(handler2, &MyMenuItemHander::onButtonD);
|
||||
tree->onReturnKeyDown.Add(m_internalData->m_handler2, &MyMenuItemHander::onButtonD);
|
||||
int firstAvailableDemoIndex=-1;
|
||||
Gwen::Controls::TreeNode* firstNode=0;
|
||||
|
||||
@@ -894,13 +987,18 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
MyMenuItemHander* handler = new MyMenuItemHander(d);
|
||||
m_internalData->m_handlers.push_back(handler);
|
||||
|
||||
pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA);
|
||||
pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB);
|
||||
pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC);
|
||||
pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE);
|
||||
pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG);
|
||||
pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF);
|
||||
|
||||
#endif
|
||||
// pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
// pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
// pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD);
|
||||
@@ -910,6 +1008,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
else
|
||||
{
|
||||
curNode = tree->AddNode(nodeUText);
|
||||
m_internalData->m_nodes.push_back(curNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -928,6 +1027,9 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
}
|
||||
|
||||
}
|
||||
free(demoNameFromCommandOption);
|
||||
demoNameFromCommandOption = 0;
|
||||
|
||||
btAssert(sCurrentDemo!=0);
|
||||
if (sCurrentDemo==0)
|
||||
{
|
||||
@@ -935,9 +1037,11 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
gui->registerFileOpenCallback(fileOpenCallback);
|
||||
gui->registerQuitCallback(quitCallback);
|
||||
|
||||
gui2->registerFileOpenCallback(fileOpenCallback);
|
||||
gui2->registerQuitCallback(quitCallback);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1044,7 +1148,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
|
||||
{
|
||||
|
||||
if (s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera())
|
||||
if (gui2 && s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera())
|
||||
{
|
||||
char msg[1024];
|
||||
float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance();
|
||||
@@ -1053,7 +1157,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
float camTarget[3];
|
||||
s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget);
|
||||
sprintf(msg,"dist=%f, pitch=%f, yaw=%f,target=%f,%f,%f", camDist,pitch,yaw,camTarget[0],camTarget[1],camTarget[2]);
|
||||
gui->setStatusBarMessage(msg, true);
|
||||
gui2->setStatusBarMessage(msg, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1061,16 +1165,24 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
static int toggle = 1;
|
||||
if (renderGui)
|
||||
{
|
||||
if (!pauseSimulation)
|
||||
processProfileData(s_profWindow,false);
|
||||
// if (!pauseSimulation)
|
||||
// processProfileData(s_profWindow,false);
|
||||
|
||||
if (sUseOpenGL2)
|
||||
if (sUseOpenGL2)
|
||||
{
|
||||
|
||||
saveOpenGLState(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight());
|
||||
|
||||
saveOpenGLState(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
|
||||
}
|
||||
BT_PROFILE("Draw Gwen GUI");
|
||||
gui->draw(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight());
|
||||
BT_PROFILE("Draw Gwen GUI");
|
||||
if (m_internalData->m_gui)
|
||||
{
|
||||
m_internalData->m_gui->draw(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
|
||||
}
|
||||
if (gui2)
|
||||
{
|
||||
gui2->draw(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
|
||||
}
|
||||
|
||||
if (sUseOpenGL2)
|
||||
{
|
||||
restoreOpenGLState();
|
||||
@@ -1084,14 +1196,20 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
toggle=1-toggle;
|
||||
{
|
||||
BT_PROFILE("Sync Parameters");
|
||||
s_parameterInterface->syncParameters();
|
||||
if (s_parameterInterface)
|
||||
{
|
||||
s_parameterInterface->syncParameters();
|
||||
}
|
||||
}
|
||||
{
|
||||
BT_PROFILE("Swap Buffers");
|
||||
s_app->swapBuffer();
|
||||
}
|
||||
|
||||
gui->forceUpdateScrollBars();
|
||||
if (gui2)
|
||||
{
|
||||
gui2->forceUpdateScrollBars();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user