Oceanel51 / FoodIndustry

Original mod by Villfuk02
https://mods.factorio.com/mod/FoodIndustry
7 stars 4 forks source link

Crash onTick when the seedlings get destroyed by environment. #40

Open hanakocz opened 4 years ago

hanakocz commented 4 years ago
Error while running event FoodIndustry::on_tick (ID 0)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
    __FoodIndustry__/prototypes/scripts/trees_control.lua:93: in function 'v'
    __FoodIndustry__/control.lua:110: in function <__FoodIndustry__/control.lua:107>
stack traceback:
    [C]: in function '__index'
    __FoodIndustry__/prototypes/scripts/trees_control.lua:93: in function 'v'
    __FoodIndustry__/control.lua:110: in function <__FoodIndustry__/control.lua:107>

while running quite small modpack. It is possible that the seedlings get destroyed by environment.

Oceanel51 commented 4 years ago

Thanks! I reproduced the error and it seems to have fixed it on 1.8.139 commit.

hanakocz commented 4 years ago

Thanks! I have few more crashes from other stuff, will post them as separate issues.

Just a thought...You are checking if fruitSeedling is not null, and then directly are checking if fruitSeedling.seedling.valid. From my experience with lua, sometimes can happen that fruitSeedling.seedling is null, thus then .valid can't be checked and things do crash(can't check if null is valid). I guess this can be skipped as you do it if you are 100% sure that seedling is never null, but on the other hand, you are working there with global table, that can be in theory altered by scripts outside of your mod workspace.

I have personally only scripting experience so don't know if this is really like that in mods, it is just what my immediate feeling was after the crash happened and I checked the code. Feel free to ignore my question :)

hanakocz commented 4 years ago

Oh, and one more note. We actually managed to pinpoint what exactly caused the removal of the seedlings that made this crash. It was https://mods.factorio.com/mod/Mining_Drones mod, our solution was to remove all recipes from food industry so players couldn't make drones to harvest your things (wood harvesting goes after your trees in this case). Don't know if it needs some special treatment more than the crash fix, but just wanted to let you know.

Oceanel51 commented 4 years ago

Just a thought...

I check record from global.foodi.fruitSeedlings table {entity, grow_time}, {entity, grow_time}... then, check is valid a entity from record of table, if it is not there, then delete the tree entry.

It was https://mods.factorio.com/mod/Mining_Drones mod

Before that, tree removal was checked only if the player did it. Now it doesn’t matter how the tree disappeared, if it is not there (check if entity is valid), then it is deleted from the mod table.

Oceanel51 commented 4 years ago

But in general I want to redo trees/plants control. In a first approximation, it looks like this FI Real Trees concept

But it's still a dream :)