Hi.
I'm trying to use AngelScript as scripting language in my one-day-it-will-be-game and I encountered weird problem today.
I have two registered C++ classes, EventSource and ASConsole derived from it and registered method addListener(EventSource* source, ...)
Now, if I call addListener like this...
ASConsole@ console; // This is actually global variable
void main() {
EventSource@ s = cast<EventSource>(console);
module.addListener(s, ET_READLINE, onLine);
loop();
} ... everything is OK. ASConsole is dynamic_cast-ed to EventSource, pointer is returned and addListener recieves same pointer. But, if I do this...
ASConsole@ console; // This is actually global variable
void main() {
module.addListener(cast<EventSource>(console), ET_READLINE, onLine);
loop();
}
... dynamic_cast returns one pointer (0x81a240), addListener recieves something else (0x8c5f98) and entire thing segfaults.
Am I doing something wrong? And, is there possibility to prevent segfault when this wrong method is used? I would like to let users to use some in-game scripting, but I really don't want to let them crash entire thing.