On 8/23/05, Kai Sterker <[EMAIL PROTECTED]> wrote:
On 8/22/05, Tyler Nielsen <[EMAIL PROTECTED]> wrote:

> To get adonthell/tests to compile I had to add in test/Makefile.am:
> -L$(top_builddir)/src/py-wrappers/adonthell -ladonthell_py_runtime
> But then when I run guitest or inputtest, it just gives 'Floating
> point exception'.

This might be a problem caused by the last change I committed only a
few days ago. There are a few problems that I haven't adressed yet. So
things might be broken. Can you try any of the python scripts? Do they
work? At least the eventtest.py should ...

So, I finally got around to digging into the 'Floating point exception' problem I was having.  Basically what it looks like is that there is a problem with some of the static initilization.  'event_type::NamedTypes' and 'event_type::Types' were being constructed after 'TimeEventManager'.  TimeEventManager uses NamedTypes and Types in it's constructor so I was getting a crash.  I found more infomation about it at: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

I'm not sure if there is a better way to fix it, but attached is a patch that fixes the problem for me.  After that, I'm getting most of the python scripts to run.  I'm still looking though the structure of the code, but I am heading down the path of resolving some of the audio tasks.

Tyler Nielsen

Index: src/event/types.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event/types.cc,v
retrieving revision 1.2
diff -u -r1.2 types.cc
--- src/event/types.cc	14 Aug 2005 16:51:20 -0000	1.2
+++ src/event/types.cc	10 Sep 2005 23:24:43 -0000
@@ -34,36 +34,30 @@
 using events::event_type;
 using events::manager_base;
 
-// Types of events registered with the event subsystem by name
-std::hash_map<std::string, event_type*> event_type::NamedTypes;
-
-// Types of events by id
-std::vector<event_type*> event_type::Types;
-
 // register a new type of event
 void event_type::register_type (const std::string & name, manager_base *manager, new_event creator)
 {
-    std::hash_map<std::string, event_type*>::iterator i = NamedTypes.find (name);   
-    if (i == NamedTypes.end())
+    std::hash_map<std::string, event_type*>::iterator i = NamedTypes().find (name);   
+    if (i == NamedTypes().end())
     {
-        NamedTypes[name] = new event_type ((u_int8) Types.size(), manager, creator);
-        Types.push_back (NamedTypes[name]);
+        NamedTypes()[name] = new event_type ((u_int8) Types().size(), manager, creator);
+        Types().push_back (NamedTypes()[name]);
     }
     
     else if ((*i).second == NULL) 
     {
-        (*i).second = new event_type ((u_int8) Types.size(), manager, creator);
-        Types.push_back ((*i).second);
+        (*i).second = new event_type ((u_int8) Types().size(), manager, creator);
+        Types().push_back ((*i).second);
     }
 }
 
 // remove event type from list of registered event types
 void event_type::remove_type (const std::string & name)
 {
-    std::hash_map<std::string, event_type*>::iterator i = NamedTypes.find (name);   
-    if (i != NamedTypes.end())
+    std::hash_map<std::string, event_type*>::iterator i = NamedTypes().find (name);   
+    if (i != NamedTypes().end())
     {
-        Types[(*i).second->id()] = NULL;
+        Types()[(*i).second->id()] = NULL;
         delete (*i).second;
         (*i).second = NULL;
     }
@@ -72,8 +66,8 @@
 // get id of given event type
 u_int8 event_type::get_id (const std::string & name)
 {
-    std::hash_map<std::string, event_type*>::iterator i = NamedTypes.find (name);   
-    if (i != NamedTypes.end() && (*i).second != NULL) return (*i).second->id ();
+    std::hash_map<std::string, event_type*>::iterator i = NamedTypes().find (name);   
+    if (i != NamedTypes().end() && (*i).second != NULL) return (*i).second->id ();
     
     fprintf (stderr, "event_type::get_id: event type '%s' not registered!\n", name.c_str());
     return 255;
@@ -82,8 +76,8 @@
 // instanciate new event of given type
 event *event_type::instanciate_event (const std::string & name)
 {
-    std::hash_map<std::string, event_type*>::iterator i = NamedTypes.find (name);   
-    if (i != NamedTypes.end() && (*i).second != NULL) return (*i).second->instanciate ();
+    std::hash_map<std::string, event_type*>::iterator i = NamedTypes().find (name);   
+    if (i != NamedTypes().end() && (*i).second != NULL) return (*i).second->instanciate ();
 
     fprintf (stderr, "event_type::instanciate_event: event type '%s' not registered!\n", name.c_str());
     return NULL;
@@ -92,7 +86,7 @@
 // get manager for given event id
 manager_base *event_type::get_manager (const u_int8 & id)
 {
-    if (id < Types.size() && Types[id] != NULL) return Types[id]->manager ();
+    if (id < Types().size() && Types()[id] != NULL) return Types()[id]->manager ();
 
     fprintf (stderr, "event_type::get_manager: event id '%i' not registered!\n", id);
     return NULL;    
@@ -103,4 +97,18 @@
     Id = id;
     Manager = manager;
     InstanciateEvent = creator;
+}
+
+// Types of events registered with the event subsystem by name
+std::hash_map<std::string, event_type*>& event_type::NamedTypes ()
+{
+    static std::hash_map<std::string, event_type*> *NamedTypes = new std::hash_map<std::string, event_type*>();
+    return *NamedTypes;
+}
+
+// Types of events by id
+std::vector<event_type*>& event_type::Types ()
+{
+    static std::vector<event_type*> *Types = new std::vector<event_type*>();
+    return *Types;
 }
Index: src/event/types.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/event/types.h,v
retrieving revision 1.2
diff -u -r1.2 types.h
--- src/event/types.h	14 Aug 2005 16:51:20 -0000	1.2
+++ src/event/types.h	10 Sep 2005 23:24:43 -0000
@@ -139,10 +139,10 @@
     new_event InstanciateEvent;
     
     /// Types of events registered with the event subsystem by name
-    static std::hash_map<std::string, event_type*> NamedTypes;
+    static std::hash_map<std::string, event_type*>& NamedTypes ();
     
     /// Types of events by id
-    static std::vector<event_type*> Types;
+    static std::vector<event_type*>& Types ();
 };
 
 #ifndef SWIG
_______________________________________________
Adonthell-devel mailing list
Adonthell-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/adonthell-devel

Reply via email to