This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Aedda's profile picture

[MC1.7.10][CC1.75] Turtles randomly pause/freeze on function calls

Started by Aedda, 12 January 2016 - 01:54 AM
Aedda #1
Posted 12 January 2016 - 02:54 AM
I've been having this problem since I added CC to the MinecraftUnabridged mod pack, which is also the first instance of using 1.75.

I made a mining turtle, set its label, and gave it 20k in fuel. I then wrote a simple script to dig down to bed rock and return, nothing more. At first it seemed to be working, but then once the turtle did not return. I went into creative and found it, it was frozen on the return trip.

Nothing I could think of would fix it so I broke it and brought it back to the surface. After reviewing the code and finding no error, I repeated the process. It worked the next 40 or so times, then failed to return.

This time it froze six blocks into the digging down process. I tried breaking the next block in the path to see if that would have an effect, nothing. I accidentally clicked with a bucket of water, and it suddenly woke up and mined to bedrock and returned.

It worked for another day, then froze twice in an hour. I riddled my program with breadcrumbs which revealed it was not getting stuck in a loop somewhere but rather the function calls themselves were not returning. while turtle.up() do for instance would never get to the code in the while loop nor the code after, if turtle.detect() then same thing.

By chance, I opened the turtle and bumped a key. It immediately woke up. Now I knew something was very wrong.

I had AromaBackup installed and it had recently finished a backup cycle before a couple of the incidents. Someone told me it could cause this issue, so I discontinued using it and it seemed the problem resolved.

Three days later (tonight) I'm in the nether, my turtle is making a path of cobble across a lava lake when it freezes on the return trip. I ran out to it, opened its term and hit a key and again it woke up and finished.


local depth = 0

while (turtle.detectDown()) do <-- froze here
  turtle.digDown()
end

while (turtle.down()) do <-- froze here
  depth = depth + 1
  turtle.digDown() <-- froze here
end

while (depth > 0) do
  if (turtle.up()) then <-- froze here
	depth = depth - 1
  end
end


The initial program that showed the problem, simply digs to bedrock and returns.

This has pretty much made turtles useless since I need to hand-hold them the entire time, never sure were or when they will break. I would be thankful for some suggestions or advice, or if this could be looked at internally to see if there is any clue in the source code for this occurring.

Thanks for reading, and for any input.
Bomb Bloke #2
Posted 12 January 2016 - 07:38 AM
Of the top of my head, I can tell you that the turtle functions look like this (or would, if they were still written in Lua):

turtle.up = function()
  local responseNum = turtle.native.up()

  while true do
    local event, id, result = os.pullEvent("turtle_response")
    if id == responseNum then return result end
  end
end

A special function is called which actually performs the action. This returns a number, and the code then yields until an suitable event comes back with that number; the event also reports whether the action was successful.

So for whatever reason, your turtle isn't being resumed when it should be. The event must be appearing in its event queue eventually (or else tapping a button - which adds a new event to the queue - wouldn't get it going again), though.

I've only encountered this behaviour in one modpack (and quite an old one at that), and I'm fairly sure it had something to do with the other mods installed. I suspect you're best off attempting to implement a workaround for it rather than stripping things out, though.

My first bet is that if you simply start a timer before every turtle function call (which'll generate a new event after the specified amount of time has passed), that may be sufficient to keep things moving. Eg:

local function up()
  os.startTimer(1)
  turtle.up()
end
Aedda #3
Posted 12 January 2016 - 10:09 AM
So for whatever reason, your turtle isn't being resumed when it should be. The event must be appearing in its event queue eventually (or else tapping a button - which adds a new event to the queue - wouldn't get it going again), though.

Seems like something worth investigating by the author.

I've only encountered this behaviour in one modpack (and quite an old one at that), and I'm fairly sure it had something to do with the other mods installed. I suspect you're best off attempting to implement a workaround for it rather than stripping things out, though.

Yeah since days can go by without the issue it would be impossible to swap mods out in order to test. Again the author finding the specific cause might help them track down which one is responsible.

My first bet is that if you simply start a timer before every turtle function call (which'll generate a new event after the specified amount of time has passed), that may be sufficient to keep things moving.

Interesting workaround, if it works. I will give it a try and see if it reoccurs. Thanks for this!
Bomb Bloke #4
Posted 12 January 2016 - 10:41 AM
Seems like something worth investigating by the author.

That's unlikely to happen if you can't reproduce the issue under CC 1.76 (and provide steps as to how to do it). There're no further updates intended for MC 1.7.10, I'm afraid.

Again the author finding the specific cause might help them track down which one is responsible.

Erm, the author of which mod, exactly? In case it's not clear, you're the only one in a position to replicate the bug, and therefore to narrow down what's triggering it.
Aedda #5
Posted 13 January 2016 - 12:50 AM
Seems like something worth investigating by the author.
That's unlikely to happen if you can't reproduce the issue under CC 1.76 (and provide steps as to how to do it). There're no further updates intended for MC 1.7.10, I'm afraid.

That is unfortunate since I estimate I will not be updating Minecraft until around May, oh well.

Again the author finding the specific cause might help them track down which one is responsible.
Erm, the author of which mod, exactly? In case it's not clear, you're the only one in a position to replicate the bug, and therefore to narrow down what's triggering it.

I was referring to ComputerCraft and as for narrowing it down the same could be said for the author as only the author can see what is going on behind the scenes. So in any case this will most likely go unresolved.

Anyway thanks for the help, hopefully it works, and cheers!