Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed menu, model, and binding leaks

  • Loading branch information...
commit 05bbe6e5a54f1386a9544d2db4ea0ca348ae07ad 1 parent bd32c2c
Matt Rasmussen authored
20 examples/tests/windows.py
View
@@ -6,27 +6,17 @@
import summon
from summon.core import *
-'''
-win = summon.Window()
-for i in range(100):
- menu = summon.Menu()
- for i in range(10):
- menu.add_entry("a", lambda x: None)
- menu.add_submenu("b", summon.Menu())
- menu.delete()
-'''
+
+
wins = []
-for i in xrange(1):
+for i in xrange(5):
wins.append(summon.Window("%d" % i))
-time.sleep(2)
+time.sleep(10)
for win in wins:
win.close()
+time.sleep(2)
-gc.collect()
-
-print list(summon.get_windows())
-print summon.get_summon_state().models
2  lib/summon/__init__.py
View
@@ -50,7 +50,7 @@ def version():
def start_summon_thread():
"Starts the main SUMMON thread"
-
+
# start summon thread
_summon_thread = threading.Thread(target=summon_core.summon_main_loop)
_summon_thread.setDaemon(True)
3  src/MVC/Binding.cpp
View
@@ -30,7 +30,8 @@ namespace Summon
{
Binding::Binding()
-{}
+{
+}
Binding::~Binding()
{
3  src/MVC/Command.h
View
@@ -73,6 +73,9 @@ extern Command *g_lastRegisteredCommand;
class CommandAttr
{
public:
+ virtual ~CommandAttr()
+ {}
+
inline bool Has(CommandId cmdId) {
return m_set.find(cmdId) != m_set.end();
}
82 src/Summon/Summon.cpp
View
@@ -50,6 +50,7 @@
#include "SummonWindow.h"
#include "summon_scene_graph.h"
#include "screenshot.h"
+#include "Menu.h"
// constants
@@ -163,67 +164,6 @@ static void Timer(int value);
-class Menu
-{
-public:
- Menu(int menuid = 0)
- : menuid(menuid)
- {
- }
-
- ~Menu()
- {
- if (menuid != 0)
- glutDestroyMenu(menuid);
- }
-
- int create(void (*func)(int))
- {
- menuid = glutCreateMenu(func);
- return menuid;
- }
-
- void addEntry(const char *text, int value)
- {
- glutSetMenu(menuid);
- glutAddMenuEntry(text, value);
- items.push_back(value);
- }
-
- void addSubMenu(const char *text, int submenuid)
- {
- glutSetMenu(menuid);
- glutAddSubMenu(text, submenuid);
- items.push_back(-1);
- }
-
- void removeItem(int index)
- {
- glutSetMenu(menuid);
- glutRemoveMenuItem(index);
- fflush(stdout);
- items.erase(items.begin() + index - 1);
- // NOTE: items automatically slide down just like glut's behavior
- }
-
- void setEntry(int index, const char *text, int value)
- {
- glutSetMenu(menuid);
- glutChangeToMenuEntry(index, text, value);
- items[index] = value;
- }
-
- void setSubMenu(int index, const char *text, int submenuid)
- {
- glutSetMenu(menuid);
- glutChangeToSubMenu(index, text, submenuid);
- }
-
-
- int menuid;
- vector<int> items; // callback ids for each item
-};
-
class SummonModule : public CommandExecutor, public GlutViewListener
{
@@ -243,8 +183,7 @@ class SummonModule : public CommandExecutor, public GlutViewListener
m_timerCommand(NULL),
m_timerDelay(0)
- {
- }
+ {}
virtual ~SummonModule()
{
@@ -460,13 +399,17 @@ class SummonModule : public CommandExecutor, public GlutViewListener
int menuid = menu->create(Summon::MenuCallback);
m_menus[menuid] = menu;
((NewMenuCommand*) &command)->SetReturn(Int2Scm(menuid));
-
} break;
case DEL_MENU_COMMAND: {
// delete a menu
int menuid = ((DelMenuCommand*) &command)->menuid;
Menu *menu = m_menus[menuid];
+ for (unsigned int i=0; i<menu->items.size(); i++) {
+ int value = menu->items[i];
+ if (value >= 0)
+ m_menuItems.erase(value);
+ }
delete menu;
m_menus.erase(menuid);
} break;
@@ -474,12 +417,10 @@ class SummonModule : public CommandExecutor, public GlutViewListener
case ADD_MENU_ENTRY_COMMAND: {
// add an entry to a menu
AddMenuEntryCommand *cmd = (AddMenuEntryCommand*) &command;
-
m_menus[cmd->menuid]->addEntry(cmd->text.c_str(),
m_nextMenuItem);
m_menuItems[m_nextMenuItem] = cmd->func;
m_nextMenuItem++;
-
} break;
case ADD_SUBMENU_COMMAND: {
@@ -492,7 +433,7 @@ class SummonModule : public CommandExecutor, public GlutViewListener
RemoveMenuItemCommand *cmd = (RemoveMenuItemCommand*) &command;
Menu *menu = m_menus[cmd->menuid];
- int value = menu->items[cmd->index];
+ int value = menu->items[cmd->index-1];
if (value >= 0)
m_menuItems.erase(value);
menu->removeItem(cmd->index);
@@ -876,8 +817,9 @@ class SummonModule : public CommandExecutor, public GlutViewListener
{
// init glut
int argc = 1;
- char **argv = new char* [1];
- argv[0] = (char*) "summon"; // avoid compiler warning (GLUT's fault)
+ char* argv0 = "summon";
+ char **argv = &argv0; //new char* [1];
+ //argv[0] = (char*) "summon"; // avoid compiler warning (GLUT's fault)
glutInit(&argc, argv);
// create hidden window
@@ -928,7 +870,7 @@ class SummonModule : public CommandExecutor, public GlutViewListener
// if SUMMON is already initialized, then do not do any more
// window decoration processing
- if (!IsRunning()) {
+ if (m_state == SUMMON_STATE_UNINITIALIZED) {
if (tries < maxtries &&
(glutGet(GLUT_WINDOW_WIDTH) != INIT_WINDOW_SIZE ||
glutGet(GLUT_WINDOW_HEIGHT) != INIT_WINDOW_SIZE))
3  src/Summon/SummonController.cpp
View
@@ -49,7 +49,8 @@ SummonController::SummonController(CommandExecutor *global, SummonView *view,
SummonController::~SummonController()
-{}
+{
+}
10 src/Summon/summonCommands.cpp
View
@@ -55,11 +55,11 @@ void summonCommandsInit()
# define gl() AddAttr(g_glAttr)
// add glAttr to glut commands
- g_glAttr.Add(new TranslateCommand());
- g_glAttr.Add(new ZoomCommand());
- g_glAttr.Add(new ZoomXCommand());
- g_glAttr.Add(new ZoomYCommand());
- g_glAttr.Add(new FocusCommand());
+ TranslateCommand tc; g_glAttr.Add(&tc);
+ ZoomCommand zc; g_glAttr.Add(&zc);
+ ZoomXCommand zxc; g_glAttr.Add(&zxc);
+ ZoomYCommand zyc; g_glAttr.Add(&zyc);
+ FocusCommand fc; g_glAttr.Add(&fc);
// global commands
RegisterScriptCommand(GetWindowsCommand) g()
Please sign in to comment.
Something went wrong with that request. Please try again.