Game Crash when using Lua String Patterns
#1
I have been attempting to write a plugin which, upon the user pressing a button, teleports the user to a location specified on a sign relative to the back side of the button. When I push the button, MCServer crashes.

Plugin File: http://pastebin.com/b9eVGa8v
Related log entries: http://pastebin.com/fLn7r4KY

Based on the log entries, the game seems to crash when the log statment is executed for GoY on line 64.

I have tested this code in Lua and it _should_ work. Even so, there should be no reason for MCServer crashing due to a Lua plugin.

So... I am not sure if I am doing something wrong or if there is a problem with the MCServer code. Does anyone have a solution to this problem?

Also, pardon some of my code comments. I know at least one of them is misleading Smile
Reply
Thanks given by:
#2
Hello, welcome to the forum.

That is weird behavior indeed. I can't see anything wrong with the plugin code, and as you wrote, even bad code shouldn't crash the server. I'll test if I can reproduce this on my machine when I get back home.

Of course, there are situations when bad code *can* crash the server; those are because of how our C++-to-Lua bindings are implemented - if you store a cPlayer object within a hook, and then call a function on it, say, an hour later when the player is already gone, you will crash the server. But in this instance there's nothing like that in the plugin code.
Reply
Thanks given by:
#3
Ah, found it. The server has a problem when you call the LOG function with no params (or nil as a param) - it tries to interpret the nil value as a cCompositeChat object and crashes on that. Your problem is that one of your GoX, GoY and GoZ variables are not assigned, so you're effectively calling LOG(nil).
Reply
Thanks given by:
#4
Fixed in 5d4dd103a12a44c8482d524c38841221da1d8fb2. Trying to log a nil value now produces an error message and stacktrace in the server console.
Reply
Thanks given by:
#5
Quote:Fixed in 5d4dd103a12a44c8482d524c38841221da1d8fb2. Trying to log a nil value now produces an error message and stacktrace in the server console.

Thanks!

Also, if anyone was wondering what was wrong with my code, it was because I was not escaping the square brackets with %, so the actual pattern to match is:

Code:
"%[%s*(%d+)%s+(%d+)%s+(%d+)%s*%]"
Reply
Thanks given by:
#6
I'm still wondering, why use buttons and signs? There are so many other ways of doing this without affecting the game world at all. You could have "teleporter zones" that would teleport players whenever they just stepped in them. Or if you insist on buttons, still there's no need for signs, just make the plugin store the destination coords in a separate config file or a SQLite database, so that the admin can edit them, but they don't need a sign.
Reply
Thanks given by:
#7
(02-21-2015, 12:50 AM)xoft Wrote: I'm still wondering, why use buttons and signs? There are so many other ways of doing this without affecting the game world at all. You could have "teleporter zones" that would teleport players whenever they just stepped in them. Or if you insist on buttons, still there's no need for signs, just make the plugin store the destination coords in a separate config file or a SQLite database, so that the admin can edit them, but they don't need a sign.

yeah, you are right on that one. I guess I was just playing around. I prefer the buttons so that the user can specify when to teleport. I will look into the SQLite database thing.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)