invalid key to 'next'

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

invalid key to 'next'

Agi Shi
Hi all!  I'm nullsquared, new to the mailing list, with a bit of a complicated situation.

This code: http://lua.pastebin.com/f7b33bcca

Works 100% under Lua 5.0.x (paired with any recent version of luabind), but fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'

When sheet.update() is called, it iterates over the passed in table and creates a GUI; the table itself is only read, not modified, and it is iterated over via standard luabind table iterators.

I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Josh Simmons
I'd be looking at the ChangeLog if I were you.
Also using standard library names as local variables is going to end
you in trouble eventually.

On Sun, May 24, 2009 at 12:06 PM, Agi Shi <[hidden email]> wrote:
> Hi all!  I'm nullsquared, new to the mailing list, with a bit of a
> complicated situation.
> This code: http://lua.pastebin.com/f7b33bcca
> Works 100% under Lua 5.0.x (paired with any recent version of luabind), but
> fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'
> When sheet.update() is called, it iterates over the passed in table and
> creates a GUI; the table itself is only read, not modified, and it is
> iterated over via standard luabind table iterators.
> I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Jim Whitehead II
In reply to this post by Agi Shi
On Sun, May 24, 2009 at 3:06 AM, Agi Shi <[hidden email]> wrote:
> Hi all!  I'm nullsquared, new to the mailing list, with a bit of a
> complicated situation.
> This code: http://lua.pastebin.com/f7b33bcca
> Works 100% under Lua 5.0.x (paired with any recent version of luabind), but
> fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'
> When sheet.update() is called, it iterates over the passed in table and
> creates a GUI; the table itself is only read, not modified, and it is
> iterated over via standard luabind table iterators.
> I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?

As stated in the Lua reference manual, this means that during the
iteration you are assigning to a key that didn't exist prior to the
iteration.  This was the case in Lua 5.0, however the error is not
guaranteed to happen each and every time.

Keep in mind that the assignment can be setting the element to nil.
You can do any assignments to keys that already existed prior to the
iteration, just not any new ones.

- Jim
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Agi Shi
I see.  However, the only iteration I'm doing in Lua is this:

    local function buttons(table)
        local pos = vec2(0, 0)
        for key, val in pairs(table) do
            for key2, val2 in pairs(val) do
                --log(type(val2))
                val2.position = vec2(pos.x, pos.y)
                pos.x = pos.x + val2.size.x
            end
        end
        return table
    end

I'm not modifying the table itself, only the values of the table.  And
I've now realized that naming the table 'table' is a bad idea, so I've
changed it (but the same issue occurs).

On Sun, May 24, 2009 at 6:08 AM, Jim Whitehead II <[hidden email]> wrote:

>
> On Sun, May 24, 2009 at 3:06 AM, Agi Shi <[hidden email]> wrote:
> > Hi all!  I'm nullsquared, new to the mailing list, with a bit of a
> > complicated situation.
> > This code: http://lua.pastebin.com/f7b33bcca
> > Works 100% under Lua 5.0.x (paired with any recent version of luabind), but
> > fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'
> > When sheet.update() is called, it iterates over the passed in table and
> > creates a GUI; the table itself is only read, not modified, and it is
> > iterated over via standard luabind table iterators.
> > I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?
>
> As stated in the Lua reference manual, this means that during the
> iteration you are assigning to a key that didn't exist prior to the
> iteration.  This was the case in Lua 5.0, however the error is not
> guaranteed to happen each and every time.
>
> Keep in mind that the assignment can be setting the element to nil.
> You can do any assignments to keys that already existed prior to the
> iteration, just not any new ones.
>
> - Jim
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Adrian Sietsma
Agi Shi wrote:

> I see.  However, the only iteration I'm doing in Lua is this:
>
>     local function buttons(table)
>         local pos = vec2(0, 0)
>         for key, val in pairs(table) do
>             for key2, val2 in pairs(val) do
>                 --log(type(val2))
>                 val2.position = vec2(pos.x, pos.y)
>                 pos.x = pos.x + val2.size.x
>             end
>         end
>         return table
>     end
>
> I'm not modifying the table itself, only the values of the table.  And
> I've now realized that naming the table 'table' is a bad idea, so I've
> changed it (but the same issue occurs).
>
Is there a possibility that val2.position does not exist when you assign to
it ? That would be an insert, which will break pairs(). I notice that eg
debugWin has no initial position.

Adrian
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Matthew Wild
On Sun, May 24, 2009 at 1:40 PM, Adrian Sietsma
<[hidden email]> wrote:

> Agi Shi wrote:
>>
>> I see.  However, the only iteration I'm doing in Lua is this:
>>
>>    local function buttons(table)
>>        local pos = vec2(0, 0)
>>        for key, val in pairs(table) do
>>            for key2, val2 in pairs(val) do
>>                --log(type(val2))
>>                val2.position = vec2(pos.x, pos.y)
>>                pos.x = pos.x + val2.size.x
>>            end
>>        end
>>        return table
>>    end
>>
>> I'm not modifying the table itself, only the values of the table.  And
>> I've now realized that naming the table 'table' is a bad idea, so I've
>> changed it (but the same issue occurs).
>>
> Is there a possibility that val2.position does not exist when you assign to
> it ? That would be an insert, which will break pairs(). I notice that eg
> debugWin has no initial position.
>

Are you sure? Read again, it isn't val2 being iterated over.

After a first read through I can't see how that code could cause the
error. Is this the exact place pointed to by the error message?

Matthew.
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Jerome Vuarand
In reply to this post by Agi Shi
2009/5/24 Agi Shi <[hidden email]>:
> Hi all!  I'm nullsquared, new to the mailing list, with a bit of a
> complicated situation.
> This code: http://lua.pastebin.com/f7b33bcca
> Works 100% under Lua 5.0.x (paired with any recent version of luabind), but
> fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'
> When sheet.update() is called, it iterates over the passed in table and
> creates a GUI; the table itself is only read, not modified, and it is
> iterated over via standard luabind table iterators.
> I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?

You should reduce your code to something shorter showing the problem.
What you pasted is just too long to find the bug visually, and it's
incomplete so we cannot run it.
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Agi Shi
Thanks for all of the advice, it is greatly appreciated.

My teammate spent a full night debugging this issue.  Put your helmets
on because this will blow you away xD.

The issue was Direct3D.  Apparently, our project ran fine under
OpenGL.  However, Direct3D caused it to break given the identical Lua
code.  After his night-of-debugging (NOD), making the Direct3D device
use consistent floating point instead of fast floating points (doubles
instead of floats) fixed it.  I have no clue how this issue resulted
in "invalid key to 'next'" O_o

On Sun, May 24, 2009 at 12:43 PM, Jerome Vuarand
<[hidden email]> wrote:

> 2009/5/24 Agi Shi <[hidden email]>:
>> Hi all!  I'm nullsquared, new to the mailing list, with a bit of a
>> complicated situation.
>> This code: http://lua.pastebin.com/f7b33bcca
>> Works 100% under Lua 5.0.x (paired with any recent version of luabind), but
>> fails under Lua 5.1.4 with the runtime error message: invalid key to 'next'
>> When sheet.update() is called, it iterates over the passed in table and
>> creates a GUI; the table itself is only read, not modified, and it is
>> iterated over via standard luabind table iterators.
>> I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?
>
> You should reduce your code to something shorter showing the problem.
> What you pasted is just too long to find the bug visually, and it's
> incomplete so we cannot run it.
>
Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Asko Kauppi

You might be surprised to know this is a known issue.

http://lua-users.org/lists/lua-l/2006-03/msg00359.html


Agi Shi kirjoitti 24.5.2009 kello 22:07:

> Thanks for all of the advice, it is greatly appreciated.
>
> My teammate spent a full night debugging this issue.  Put your helmets
> on because this will blow you away xD.
>
> The issue was Direct3D.  Apparently, our project ran fine under
> OpenGL.  However, Direct3D caused it to break given the identical Lua
> code.  After his night-of-debugging (NOD), making the Direct3D device
> use consistent floating point instead of fast floating points (doubles
> instead of floats) fixed it.  I have no clue how this issue resulted
> in "invalid key to 'next'" O_o
>
> On Sun, May 24, 2009 at 12:43 PM, Jerome Vuarand
> <[hidden email]> wrote:
>> 2009/5/24 Agi Shi <[hidden email]>:
>>> Hi all!  I'm nullsquared, new to the mailing list, with a bit of a
>>> complicated situation.
>>> This code: http://lua.pastebin.com/f7b33bcca
>>> Works 100% under Lua 5.0.x (paired with any recent version of  
>>> luabind), but
>>> fails under Lua 5.1.4 with the runtime error message: invalid key  
>>> to 'next'
>>> When sheet.update() is called, it iterates over the passed in  
>>> table and
>>> creates a GUI; the table itself is only read, not modified, and it  
>>> is
>>> iterated over via standard luabind table iterators.
>>> I cannot quite figure out why Lua 5.1.4 breaks my code, any ideas?
>>
>> You should reduce your code to something shorter showing the problem.
>> What you pasted is just too long to find the bug visually, and it's
>> incomplete so we cannot run it.
>>

Reply | Threaded
Open this post in threaded view
|

Re: invalid key to 'next'

Adrian Sietsma
In reply to this post by Matthew Wild
Matthew Wild wrote:
> Are you sure? Read again, it isn't val2 being iterated over.
>
oops. sorry for the noise.
Adrian