MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 430 forks source link

[1.6.1.6] Looped microcontrollers crash from a yield timeout on save load. #2285

Closed Vectrobe closed 7 years ago

Vectrobe commented 7 years ago

Basically if you have a microcontroller that uses a simple while loop for its code, upon loading the world (singleplayer) after exiting it for a period of time the mc will crash with "too long without yielding".

You cant just call sleep either as these don't have an OS at all, don't know about the pcall method. Microcontrollers aren't documented so I have no idea what hard functions/instructions they have...

NickNackGus commented 7 years ago

With patience and difficulty, you can trace os.sleep(seconds) to a loop that repeatedly calls computer.pullSignal(seconds); this can be called without an OS, but keep in mind that it is actually waiting for a signal (such as a keyboard), or otherwise timing out (the number of seconds you provide). It sounds like you don't particularly care about timing, but if you did you would need to execute the command again if a signal is received and you want a more accurate delay. Please reply if you get an error while using computer.pullSignal().

Vectrobe commented 7 years ago

Does it support floating point values or just an integer count of seconds?

magik6k commented 7 years ago

It does, with 0.05s precision

xarses commented 7 years ago

http://ocdoc.cil.li/block:microcontroller has a sleep example.

When your coding into the EEPROM, all of the helpful library-APIs that come from OpenOS aren't present any longer. so most of the places that you would 'require' won't work. There are pointers all over the docs about some of the low level calls that can substitute, but ya. We are probably missing a good EEPROM survivors guide

The things that you still get are the 'component' and whatever that provides when you load a proxy. You also get whichever of computer|robot|drone is relevant to where the bios is running.

You can also see some examples for working with a bios in @fnuecke's drone remote (https://gist.github.com/fnuecke/6bcbd66910b946b54ec7). You can also do this to introspect the runtime similar to running lua on OpenOS