C++ script function stepped on
by J. Alan Atherton · in Torque Game Engine · 06/27/2003 (12:06 am) · 2 replies
I've just added a fair chunk to the engine to handle different movement modes for my game. It's essentially just a U32 for bitmasking, along with an enum setup like Torque uses for its masks. Everything works wonderfully... got it to pack and unpack, the data gets through and is applied correctly and everything. There is only one function needed to switch modes, and it's exposed to script.
Now the problem. Whenever I call this function from script via the in-game console, after one or two uses, it disappears. I get a console error that the function doesn't exist, and sure enough, I do a player dump (I added this function to player class) and sure enough, it's not in the list. I tried a player dump before it disappears, and it shows up in the dump list. After it disappears, all functionality is lost (in terms of that function; the rest of the game continues).
My only guess is that somehow I'm stepping on important memory, but before I go and spend hours with the debugger, I thought I'd throw this out and see if anyone has learned from experience.
[edit]Added a bit more clarification[/edit]
Now the problem. Whenever I call this function from script via the in-game console, after one or two uses, it disappears. I get a console error that the function doesn't exist, and sure enough, I do a player dump (I added this function to player class) and sure enough, it's not in the list. I tried a player dump before it disappears, and it shows up in the dump list. After it disappears, all functionality is lost (in terms of that function; the rest of the game continues).
My only guess is that somehow I'm stepping on important memory, but before I go and spend hours with the debugger, I thought I'd throw this out and see if anyone has learned from experience.
[edit]Added a bit more clarification[/edit]
#2
My script function took a string as one of the passed arguments. So, I did one of these: dStrcpy(field, argv[2]); where field was just a char *. I don't know why I was so dense to do it that way in the first place. So I switched the field from being declared as char *field; to being declared as char field[64]; and that seems to have solved the problem. I haven't tested extensively, but I'm sure that was at least a large part, if not all, of the problem. Cheers for the advice, Donavan.
06/27/2003 (8:18 pm)
Well, that seems to have fixed it... I'll explain what happened.My script function took a string as one of the passed arguments. So, I did one of these: dStrcpy(field, argv[2]); where field was just a char *. I don't know why I was so dense to do it that way in the first place. So I switched the field from being declared as char *field; to being declared as char field[64]; and that seems to have solved the problem. I haven't tested extensively, but I'm sure that was at least a large part, if not all, of the problem. Cheers for the advice, Donavan.
Torque Owner J. Donavan Stanley