grid.valid_for_read and item.has_grid Freeze

This subforum contains all the issues which we already resolved.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

Both of these functions cause the game to freeze if you call them, instead of showing a script error. Neither exist anymore according to the API.
This has made debugging rather frustrating, since I had to restart the game each time an error occured.


There appears to be something similar in this function, but I haven't gotten to investigating yet.

Code: Select all

function tickDummies(id,iSurface,iPosition) -- This and kill dummies need to use a factory. I have no idea what that is. Need research

    --GlobalPrint("2")
    if not id.units then
        id.units = {}
    else
        -- Already exists.
    end
    if not id.units.accumulator then
        id.units.accumulator = iSurface.create_entity{name = "laser-turret-dummy", position = iPosition, force=game.forces.player}
        id.units.accumulator.energy = RanaMods.ModularArmor.config.accumulatorEnergyCap -- initialize energy levels
        id.previousEnergy = id.units.accumulator.energy -- and previous energy level from last tick
        id.units.accumulator.destructible = false -- Make dummy invulnerable.
    else
        id.units.accumulator.teleport(iPosition) -- Ensure that the power drain dummy is always at the player's position.
    end
   
end
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 16000
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Rseding91 »

Can you upload your code? I suspect there's an infinite loop in what ever code you're written. When I test it, it simply errors as expected and says they don't exist - no freeze at all.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

That's only a code fragment. Give me a few minutes

More importantly, the code was exactly the same as it was for v0.14.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

Here.

Control.lua

Code: Select all

                local armor = thisPlayer.get_inventory(defines.inventory.player_armor)[1] -- Check for armour presence.
                
                if (armor.valid_for_read) then
                    
                    if (armor.has_grid) then -- Check for grid existence.
                        local grid = armor.grid
This is the first part that I had to fix, because apperently those functions were removed without telling the script-error-displayer.

The other part is the

Code: Select all

                        --tickDummies(modularArmor,thisPlayer.character.surface,thisPlayer.character.position)-- validate, create, and move dummy units.
                        
Function, which I commented out the call for. Also commented out a bunch of stuff in that main loop, until I found the offending part.

It all worked fine in v0.14, just when I tried to update to V0.15 that the freeze occurred.
Attachments
Modular-Armor_15.0.1.zip
(1.43 MiB) Downloaded 58 times
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Nexela »

On a side note all that code can be replaced with

Code: Select all

if player.character.grid
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

I wish. Unfortunately they added a bunch of validation functions, which makes it all more complex than it needs to be, Used to be, each of those would return nil.

Also, if character is nil, that would fail.

You had to use isvalid functions, ever since those were added. Believe me, I was irritated, because I didn't have to use them before.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Nexela »

Ranakastrasz wrote:I wish. Unfortunately they added a bunch of validation functions, which makes it all more complex than it needs to be, Used to be, each of those would return nil.
Also, if character is nil, that would fail.
You had to use isvalid functions, ever since those were added. Believe me, I was irritated, because I didn't have to use them before.
It would not fail, you are already checking if the character has a player. and .15 allows us to get the grid directly

replace

Code: Select all

 local thisPlayer = nil
    local players = game.players
for x=1, #players do
        thisPlayer = players[x]
        if (thisPlayer.connected) then
            if (thisPlayer.character) then
WITH

Code: Select all

for x, thisPlayer in pairs(game.connected_players)
if thisPlayer.character then
replace

Code: Select all

                local armor = thisPlayer.get_inventory(defines.inventory.player_armor)[1] -- Check for armour presence.
                
                if (armor.valid_for_read) then
                    
                    if (armor.has_grid) then -- Check for grid existence.
                        local grid = armor.grid
WITH

Code: Select all

local grid = thisPlayer.character.grid
if grid then
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

huh. Nifty.

Good to know.

Still doesn't stop the game from freezing instead of giving an error report tho.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 16000
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Rseding91 »

How can I reproduce the freezing? Do you have a save file and mod with steps I can do to make it happen?
If you want to get ahold of me I'm almost always on Discord.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

Add the mod I attached to one of the posts. Use console commands to enable cheat mode and all tech. Craft a modular armor.


Or load any game with modular armor researched and/or crafted.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 16000
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Rseding91 »

Ahhhhhh I see what's happening.

If you look closely you can see it errored but the message is stuck behind the character GUI.

I've fixed it for the next version of 0.15 so the error message is always on top.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: grid.valid_for_read and item.has_grid Freeze

Post by Ranakastrasz »

....
Ohhhhhh.
That makes sense
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Post Reply

Return to “Resolved Problems and Bugs”