Game Development Community

postEvent crashing TGB [solved] still a bug although...

by Max Kielland · in Torque Game Builder · 02/22/2013 (8:37 pm) · 2 replies

I was just going to make an event manager when I discovered that there already was one in TGB 1.7.6
I managed to create the manager, register my events, make a subscriber all without any errors, but as soon I try to post an event TGB crashes on me.

function TestClass::onModuleUpdate(%this,%data) {

  echo(%this SPC %data);  
}

new ScriptObject(Listener) { class = TestClass; };
new EventManager(GameEventManager);
GameEventManager.registerEvent("ModuleUpdate");
GameEventManager.subscribe(Listener,"ModuleUpdate");
GameEventManager.dumpEvents();
GameEventManager.dumpSubscribers();
GameEventManager.postEvent("ModuleUpdate","Data");

This is dumped to the console.
(null) Events
ModuleUpdate
(null) Events
ModuleUpdate Subscribers
Listener -> onModuleUpdate

As soon I execute postEvent it crashes.

#1
02/23/2013 (7:47 am)
I got it to work.

It turned out that there is an undocumented field (Queue) that has to be set, otherwise it will crash the whole TGB (...and you think this would have been caught in QA tests).

Here is the working code:

new ScriptObject(Listener) { class = TestClass; };
new EventManager(GameEventManager) { queue = "EventQueue";} ;
GameEventManager.registerEvent("ModuleUpdate");
GameEventManager.subscribe(Listener,"ModuleUpdate");
GameEventManager.dumpEvents();
GameEventManager.dumpSubscribers();
GameEventManager.postEvent("ModuleUpdate","Data");

function TestClass::onModuleUpdate(%this,%data) {

  echo(%this SPC %data);  
}
#2
02/24/2013 (10:51 am)
<shrug> More of a lack of documentation, though I agree it shouldn't crash. Every event manager object I've ever seen sets this field, so I never tried to create one without it and didn't know this caused a crash.