LUA bad argument #2

让人想犯罪 __ 提交于 2020-01-25 08:15:25

问题


i am a total beginner with LUA / ESP8266 and i am trying to find out where this error comes from:

PANIC: unprotected error in call to Lua API (bad argument #2 to 'set' (index out of range))

This is the Whole Message in serial monitor:

NodeMCU 2.2.0.0 built with Docker provided by frightanic.com
.branch: master
.commit: 11592951b90707cdcb6d751876170bf4da82850d
.SSL: false
.Build type: float
.LFS: disabled
.modules: adc,bit,dht,file,gpio,i2c,mqtt,net,node,ow,spi,tmr,uart,wifi
 build created on 2019-12-07 23:52
 powered by Lua 5.1.4 on SDK 2.2.1(6ab97e9)
> Config done, IP is 192.168.2.168
LED-Server started
PANIC: unprotected error in call to Lua API (bad argument #2 to 'set' (index out of range))

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 27780, room 16 
tail 4
chksum 0xbc
load 0x3ffe8000, len 2188, room 4 
tail 8
chksum 0xba
load 0x3ffe888c, len 136, room 0 
tail 8
chksum 0xf2
csum 0xf2
å¬ú‰.Éo‰ísÉÚo|Ï.å.õd$`..#íú..æÑ2rí.lúN‡.Éo„..l`.Ñ‚r€lÑ$.å...l`.Ñ‚s≤pɉ$.å....l`.Ñ‚r€l.èæ.å...$l`.{$é.êo.Ñü¬cc.ÑÑ".|l.Bè.c.‰è¬.lc‰ÚnÓ.2NN‚....å#€‚n.ÏéÑ.l..$Ïådè|Ïl.é.lÄ.o¸.Ñæ.#".llÏÑè..c...åû„åc.l.Ñb.{$r.

I Uploaded this code (https://github.com/Christoph-D/esp8266-wakelight) to the ESP8266, and did build the correct NodeMCU firmware with all required modules.

The Serial output is ok for a couple of seconds, then i get this error and it starts to repeat rebooting.

Where would i start looking for the Problem?

Thanks a lot!!!

EDIT: there are only a few places in the lua files where anything about "set" is written:

local function update_buffer(buffer, c)
  if not c.r_frac then c.r_frac = 0 end
  if not c.g_frac then c.g_frac = 0 end
  if not c.b_frac then c.b_frac = 0 end
  local r2 = c.r_frac >= 0 and c.r + 1 or c.r - 1
  local g2 = c.g_frac >= 0 and c.g + 1 or c.g - 1
  local b2 = c.b_frac >= 0 and c.b + 1 or c.b - 1
  local r3, g3, b3
  local set = buffer.set
  for i = 1, NUM_LEDS do
    if i > c.r_frac then r3 = c.r else r3 = r2 end
    if i > c.g_frac then g3 = c.g else g3 = g2 end
    if i > c.b_frac then b3 = c.b else b3 = b2 end
    set(buffer, i - 1, g3, r3, b3)
  end
end

Is there anything wrong?


回答1:


Just above the for-loop where set is called, try adding this:

print(buffer:size(), NUM_LEDS)

If everything is OK, it should print the same number twice. If NUM_LEDS is larger, then that's your bug.

I don't really get why it uses the global variable in that place anyway; it'd make much more sense to use buffer:size() instead for exactly this reason.



来源:https://stackoverflow.com/questions/59231437/lua-bad-argument-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!