Immersive Engineering

Immersive Engineering

134M Downloads

[Suggestion] CCT Compat: `getInputQueueElement()` instead of crashing the program, output `nil` or something else.

TwistedGate opened this issue ยท 2 comments

commented

Explain your idea

Using version 1.18.2-8.2.2-154.

I had multiple instances where the whole program would crash.

Even tho i do this index > crusher.getQueueSize() check in

local function get(index)
  if index > crusher.getQueueSize() then return {name="?", count=0} end
  return crusher.getInputQueueElement(index)
end

it crashes anyway because just after the check the queue changed it's size.. causing the program to just nope right the fuck out.

Instead of crashing the whole program it could just output nil or something, if the index is <1 or >queueSize.

There it is happening
grafik

Edit-1: Added IE version up top.
Edit-2: Added Screenshot of it finaly happening again.

commented

not perfectly sure if this is still valid because the reference is old but afaik throwing exceptions is perfectly okay to do

http://www.computercraft.info/forums2/index.php?/topic/2649-error-handling/

local ok, val = crusher.getInputQueueElement(index)
if ok then return val end
return {name="?", count=0}

and as a side note, the return CAN be null

commented

not perfectly sure if this is still valid because the reference is old but afaik throwing exceptions is perfectly okay to do

http://www.computercraft.info/forums2/index.php?/topic/2649-error-handling/

local ok, val = crusher.getInputQueueElement(index)
if ok then return val end
return {name="?", count=0}

and as a side note, the return CAN be null

You don't understand, it crashes the program outright.
There is no return value coming from crusher.getInputQueueElement(index) if the index is out of bounds

if(index < 0||index >= queue.size())
throw new RuntimeException("Invalid index, queue contains "+queue.size()+" elements");