android
  #1  
Old 12-14-2011, 09:58 PM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Exclamation Table assigning-Bug

After many tries to fix a bug I have encountered, and much research, I am no closer to solving this bug then when I started. So I was wondering if anyone had any ideas on how to fix it.

In Pingus, we use two tables, to map our the penguins actions ( one for left movement, and one for right movement). What we do is, compute the penguin's action at a certian pixel ( falling, moving, climbing a hill, turning, ect) and save that result to a table with a indices of the x and y coordinate ( we have tried several ways to write the indices, ranging from strings to numbers). Then if a penguin reaches a coordinates that has already been encountered, we just grab the end result from the table.

The problem starts when we attempt to use abilities such as the digger or miner(we have also re-routed the ability's code to use the walker's code which has not crashed yet, but it still crashes). If we try to assign a value to a table (ie: record_table[tostring(p.x) .. "_xpos" .. tostring(p.y) .. "_ypos"] = "falling") or reading from the table (ie: if record_table[corrdiante_string] == nil) then the player will crash, with the error: "attempt to call a nil value". The game also doesnt crash for every coordinate, so the digger will work for a random amount of time, then that error occurs.

here is a basic sample of the code we use:
Code:
function memoize_collision_right(x,y,p,ability_effect_value)
    local new_value = tostring(x) .. "00" .. tostring(y)
    new_value = tonumber(new_value)
    if memoize_collision_right_dat[new_value] == nil and p.state ~= "climbing" and p.type ~= "builder" then
        if ability_effect_value ~= nil then
            table.insert(memoize_collision_right_dat,new_value,ability_effect_value)
        else
            table.insert(memoize_collision_right_dat,new_value,engine.collision(p))
        end
    elseif p.state == "climbing" then
        engine.collision(p)
    end
    return memoize_collision_right_dat[new_value]
end
Note: our first try was to use table.insert instead of just writing memoize_collision_right_dat[new_value] = "falling" , but that did not help either. And this bug does not exist on the simulator.

Does anyone have a solution or know why this would happen, our entire project hangs on this bug.

Thanks,

Jbob & Redwolfhome
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 12-15-2011, 05:34 AM
Kalle Kula Kalle Kula is offline
Junior Member
 
Join Date: May 2010
Posts: 39
Default

Maybe you can rewrite the function for debugging purpose by replace the and's with full-cached if's to check that there are no uncached state. If you use elseif also do a last else. Even if you think there are states that newer could be reached maybe there is, use simple print("bug.....") for that states. Also check for nil or empty on strings.

Last edited by Kalle Kula; 12-15-2011 at 05:57 AM.
Reply With Quote

  #3  
Old 12-15-2011, 07:39 AM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

The hardest part about this though, is that it only occurs on the Player, so I will just write those variables to a text file.
Reply With Quote

  #4  
Old 12-15-2011, 11:13 AM
Kalle Kula Kalle Kula is offline
Junior Member
 
Join Date: May 2010
Posts: 39
Default

If it's only happens on the player, when I guess the trouble is somewhere else in your code. Maybe there you set the p.state. The only reason for "the only player bug thing" I can think out right now, is some dependency on os.time() or os.clock()
Reply With Quote

  #5  
Old 12-15-2011, 05:39 PM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

It is in fact editing the table, because if I were to use the original setup ( just assign the table with the line: table[index] = "falling" ) it would crash, and if i removed it, it would not crash. Our engine would not be disrupted with os.time or os.sleep because we have coded our program in such a way, that we just call engine.time() and it will return the same format on the player and adk.

Furthermore, there are no nil values when it crashes, I have outputed every value it uses besides the table, and they all produce good values.

Last edited by jbob182; 12-15-2011 at 06:11 PM.
Reply With Quote

  #6  
Old 12-18-2011, 11:50 AM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

After days of theorizing, I have found the issue! There is an maximum table index limit. This limit is 1024 (you can not have anyone more then 1024 entries into a table). Which is very surprising; our penguins are 32x32 AND if you multiply 32 by 32, you get 1024!
Reply With Quote

  #7  
Old 12-18-2011, 03:08 PM
Kalle Kula Kalle Kula is offline
Junior Member
 
Join Date: May 2010
Posts: 39
Default

If I understand you right, there is a 1024 limit on the table indexies. Isn't what a limit on number index by 2^(1024 *8), and that's a big one, Well then mybee I can suggest some kind of remapping.
Reply With Quote

  #8  
Old 12-18-2011, 03:10 PM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

I do not follow you, could you re-word it? I have just made a tile-table setup, but it causes a sever ram overload with not even 1/8 of the tables made even if i remove sound and plenty of pictures, it still overloads. After some calculations, the only way to support levels, is to push everything outside of ram, and only have the bare necessitates run in ram, and swap space for memory to handle everything else.

Last edited by jbob182; 12-18-2011 at 03:19 PM.
Reply With Quote

  #9  
Old 12-18-2011, 03:41 PM
Kalle Kula Kalle Kula is offline
Junior Member
 
Join Date: May 2010
Posts: 39
Default

maybe I missunderstand you but you want to do something like
sometable = { }
sometable["here goes some 1024 character it's about a A4 paper size or more.."]
Reply With Quote

  #10  
Old 12-18-2011, 03:59 PM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

Nope, it is more like this:

sometable[1022] = "falling" --- No crash!
sometable[1024] = "falling" --- crash!


It doesnt matter if it is numbers or strings for indicies
Reply With Quote

  #11  
Old 01-02-2012, 08:22 AM
Kalle Kula Kalle Kula is offline
Junior Member
 
Join Date: May 2010
Posts: 39
Default

This had been laying for some time and maybe you already solved it. Anyway I think user Jan_DK already have investigated the limit of the player max tablesize.
Quote:
we get 32768*4-128K usable bytes out of a
single dim array
in http://www.anythingbutipod.com/forum...t=50811&page=2
And that's far beyone sometable[1024]
looking at your function igain I see that you do:

local new_value = tostring(x) .. "00" .. tostring(y)
new_value = tonumber(new_value)
and if I get it right, x and y has max of 32, and new_value gets a max of 320032.
memoize_collision_right_dat[320032] ?!

maybe you wanted:
local new_value = string.format("%2d%02d", x,y)

Last edited by Kalle Kula; 01-02-2012 at 08:33 AM.
Reply With Quote

  #12  
Old 01-02-2012, 10:44 AM
jbob182's Avatar
jbob182 jbob182 is offline
X-Fi2 Development Moderator
 
Join Date: Feb 2010
Location: The U.S.A.
Posts: 554
Default

Quote:
local new_value = tostring(x) .. "00" .. tostring(y)
new_value = tonumber(new_value)
and if I get it right, x and y has max of 32, and new_value gets a max of 320032.
memoize_collision_right_dat[320032] ?!

maybe you wanted:
local new_value = string.format("%2d%02d", x,y)

We did manage to fix it by using sub tables, ie: tablefoo[1019][1019]

As for your suggestion, we have tried basically every format possible for the indicies, ie: numbers, strings like 33_xpos44_ypos.

x and y does not have a max of 32 either, they are the penguins position on the map, so x and y can be any number.
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:58 AM.