OpenBlocks

OpenBlocks

56M Downloads

java.lang.ClassCastException - Computercraft - Tanks

Opened this issue ยท 2 comments

commented

Hi,
I found a bug with the Openblock Tanks. I connected my tank with a Computercraft Network. If i use the getTankInfo function to fast (Or rather at the same time) i get a "Java Exception Thrown: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number".

I use this Simple "thread" API to execute multiple functions on the same time (for reproducing): http://pastebin.com/KYtYxqHh

commented

Anyway, I think I see failing path and it's probably problem with "thread" script.

OpenPeripheral code calls os.pullEvent("task_complete") to wait for result of task. This in turn calls

return coroutine.yield("task_complete")

which is supposed to be captured by main ComputerCraft thread via corountine.resume. It then makes sure that only filtered event ("task_complete") can resume main corountine.

Now, in "thread" result of coroutine.resume is discarded (line 20), so this filter is never used. That causes our code to receive unexpected data (like key event).

For correct implementation of filter handling, I suggest looking at code of built-in parralel.runUntilLimit.

EDIT: Looking at "thread" code again, it seems to be half correct - filter is present and correctly checked, but never updated with result of resume. I think that changing line 20 to:

_,thread.filter=coroutine.resume(t.cr, evt, ...)

should fix it.

commented

It's probably more OpenPeripheral issue and not specific to OpenBlocks tank.

Anyway, that's not a lot of info. I have rough idea what may be wrong, but I cannot reproduce that, Do you have (simplified) example of failing code?