BiLachner / TurtleMiner

A mod for Minetest to let builder become programmer
GNU General Public License v3.0
10 stars 9 forks source link

Crash when attempting to access turtle inventory #8

Open ghost opened 7 years ago

ghost commented 7 years ago

Right clicking on turtle, and selecting 'inventory' button, results in Minetest window becoming a blank grey screen.

Log snippet:

2017-01-22 08:13:07: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'turtleminer' in callback on_playerReceiveFields(): /home/avril/. minetest/mods/turtleminer/t_api.lua:149: attempt to index local 'turtle' (a nil value) 2017-01-22 08:13:07: ERROR[Main]: stack traceback: 2017-01-22 08:13:07: ERROR[Main]: /home/avril/.minetest/mods/turtleminer/t_api.lua:149: in function 'on_receive_fields' 2017-01-22 08:13:07: ERROR[Main]: /home/avril/.minetest/mods/turtleminer/t_api.lua:235: in function </home/avril/.minetest/mods/turtleminer/t_api.lua:232> 2017-01-22 08:13:07: ERROR[Main]: /usr/local/share/minetest/builtin/game/register.lua:412: in function </usr/local/share/minetest/builtin/game/register.lua:392> 2017-01-22 08:13:07: ACTION[Server]: Portals for player singleplayer changed, writing to file 2017-01-22 08:13:07: ACTION[Server]: singleplayer leaves game. List of players: 2017-01-22 08:13:07: ACTION[Main]: Triggering shutdown cache to file write check

ghost commented 7 years ago

I was just experimenting with breaking a few blocks and trying to get inventory out of the turtle with a pipeworks filter/injector block. I tried removing the block afterward, and confirmed it to have nothing to do with the crash.

Edit: Also, there is nothing but two pieces of ethereal:dry_dirt blocks in inventory. Don't know if that's relevant for isolating the cause, but there you go. :P

Edit 2: Also, the remote I had bound to the turtle has now stopped working. It seems that the game is somehow failing to track the turtle's data. I get "Already bound to (id=t_1)" when I try to bind to it, and "Unable to find test (id=t_1)" when trying to use the remote.

Edit 3: The game also crashes when I tell the turtle to "build beneath". It seems that the turtle is stuck in an invalid state. I also cannot break it, implying the game still thinks it has inventory.

Edit 4: In fact, any command I give it, whether using the remote or just directly right clicking on it, results in a game crash.

Edit 5: I've recreated the crash in a new world. Ostensibly the other mods did have something to do with it. Specifically, the mesecons screwdriver (item ID screwdriver:screwdriver). The tool is designed to change orientation of blocks. (Right click to rotate along one axis, left to rotate along another.) I will do some testing and see if I can come up with specific steps to recreate the bug.

Edit 6: Rotating the turtle's axis is sometimes possible, and sometimes not. When rotating it, the turtle will think that, e.g., forward is up and etc. It does not seem to be able to right itself. (At least, not via the remote.) Changing orientation of the turtle should probably be prevented to avoid confusion.

octacian commented 7 years ago

This is interesting. I thought I had eliminated the remote control issues. Will have to do some testing. BTW, turtles do not at this point support pipeworks, so it's not the culprit. The screwdriver is definitely an issue, though I don't think it caused the main problem. I'll disable the screwdriver in nodedef just to be safe.

I'd recommend that you get maptools and use the admin pick to break your turtle, I'll do some testing once I have finished recovering from an HDD failure and see if I can find the problem.

octacian commented 7 years ago

@avrildev well, I think I've figured it out. Not really sure though, as this is a weird error. I think that somehow, the file containing a table of all turtles in the world is somehow being overwritten or is not written to at all. What operating system are you on? Could you attempt to recreate this, copying this file before and after the issue (path below)?

File path on Linux: ~/.minetest/worlds/<worldname>/turtles.list

if you're on a different OS, let me know.

ghost commented 7 years ago

Hello @octacian. I am currently using an up to date Linux Mint (Linux client0 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux)

I will let you know what I find.

Edit: After messing around, breaking and placing turtles I finally recreated the crash. Interestingly, I think my original hypothesis was wrong. It doesn't seem to have anything to do with the orientation. Instead, it has something to do with when turtles are broken and then placed again. I suppose that makes more sense!

Here's the contents of the file when the mod was working as normal and I spawned in the first turtle:

return {["version"] = 1, ["turtles"] = {["t_1"] = {["owner"] = "singleplayer", ["pos"] = {["y"] = 9, ["x"] = -5, ["z"] = -1}, ["name"] = "iliketurtles"}}}

And here it is after the crash:

return {["version"] = 1, ["turtles"] = {}}

I'd guess there's a bug in the spawning code when dealing with multiple turtles and/or when existing turtles already have been spawned. Something along those lines.

octacian commented 7 years ago

This is really weird. I messed around with the screwdriver, placed 10 turtles, and logged out and back in several times, and everything was fine for me. The crash must be caused by something else, in turn causing the file to be "corrupted." However, that doesn't really make sense either as the crash seems to be caused by a "corrupt" turtles.list file.

Maybe it is caused by other mods you have installed. Would you mind providing a list of mods aside from the default ones? Or just try it without any extra mods.

In case you haven't already, delete turtleminer and clone the latest version.

ghost commented 7 years ago

@octacian I just recreated the bug on the latest clone, with no other mods enabled. The problem seems to be when you try to break a turtle when it has inventory.

Edit: it is also using flat terrain generation, and is in creative mode with damage enabled, if that helps.

Edit 2:

1) Create a new flat world, creative mode, damage enabled. 2) Plonk down a turtle. 3) Right click on the turtle, and put another turtle inside the turtle's inventory. 4) Try to break the turtle you put down. 5) Right click on the turtle again, and try to switch back to the "Main" tab. 6) Observe crash. :P

Edit 3: I would examine the code that writes to turtles.list very closely. It looks to me, like the actual bug happens when I try to break the turtle, and it fails to break... but maybe the code thinks it's still broken. The crash, however, is just a symptom of the corrupted turtles.list, I'd guess. The specific error in the log file is "attempt to index nil value", probably a value read from turtles.list after the file is erroneously overwritten.

octacian commented 7 years ago

Ah, interesting. I think I will rewrite break code to just drop the items in inventory. Will see, I'm unsure about this issue as dropping items could cause a lot of entities to suddenly be spawned.