Various crashes

Putmalk

Deity
Joined
Sep 26, 2010
Messages
2,652
Location
New York
Okay, so my mod has recently hit some snags with crashes.

Apparently it can be prone to randomly crashing, unrelated to any asset I put in (I even tested this out by placing every asset on the map, the game can load them and play with them fine).

Also, it is impossible to load a saved game in my mod, for any reason.

My two questions are:
- What might cause a random crash?
- Why can't I load any saved games?

Any help or guidance really appreciated. Thank you.
 
- What might cause a random crash?

The most common cause of this is if you clicked "Reload Landmark System" in your mod's properties. If you did, then go turn that off; it does nothing except cause lots of crashes. They're not really "random" crashes; the game will crash whenever it tries to load the graphics for a large number of hexes at once. This can happen if you tell a naval unit to move a long distance along the shore of an enemy's empire, but it'll also happen during AI turns depending on what orders they give their units.

If that's not it, then there are a lot of Lua errors that can cause a freeze/crash effect instead of gracefully failing. You pretty much have to debug by bisection (or brute-force print debugging); put a print statement at the start and end of each Lua function you modify, and once you know which function it's crashing inside, you can put print statements every few lines and see which is the last one printed before the crash. Unfortunately, this game does have some rudimentary multithreading capability, so it'll sometimes be running two processes in parallel. But this method will give you a good idea of where the offending statement is, which allows you to focus a bit more.

The most common Lua crash-causing error, in my experience, is unsanitized inputs. If you try to use an illegal value (like a null) in an sort of routine that expected valid inputs, then it'll often crash.
That is, if you have a loop like
Code:
for index,pPlayer in pairs(Players) do
  (stuff)
end
then you really need to put an if check inside it to make sure the entity is valid, like
Code:
for index,pPlayer in pairs(Players) do
  if( pPlayer ~= nil and pPlayer:IsAlive() and not (pPlayer:IsMinorCiv() or pPlayer:IsBarbarian() ) ) then
    (stuff)
  end
end

Likewise, if you've created a function like
Code:
function MyStuff(iPlayer, iCity, iUnit)
  (stuff)
end
then you need to make it look like
Code:
function MyStuff(iPlayer, iCity, iUnit)
  if( iPlayer ~= nil and iCity ~= nil and iUnit ~= nil ) then
    (stuff)
  end
end
to ensure that it never tries to do anything with illegal values.

- Why can't I load any saved games?

If it refuses to load at all, then it usually means that there was a Lua error while it was trying to re-initialize the interface. Yes, there are quite a few of these that can happen when you load a saved game but that won't crash a game that starts from scratch; it's a slightly different set of Lua functions. Same basic debugging method as described above.
 
Okay, well I'm pretty sure the first "random" crash was caused by the user not having the proper DLCs installed when playing the DLC version. And no, random landmarks wasn't checked.

But for question two...

I modified the LUA for AssignStartingPlots and for the VictoryProgressScreen. VictoryProgress received a ton of changes and I did them a while a go, so that's most likely the problem. But I didn't add anything to the file, I just deleted, and deleted, and deleted. The results work perfectly in game, but I guess it's causing errors in loading. I'm at a loss here. :(

So you're saying that because I have a ton of null values (stuff that I've deleted but not cleaned out of every table) that may cause a crash?

I can easily set deletes on all the stuff that I've removed from the main game throughout every table...Database.log has been quick to point out how many errors my mod has. XD
 
So you're saying that because I have a ton of null values (stuff that I've deleted but not cleaned out of every table) that may cause a crash?

It depends on exactly what you did. Removing entries from some tables (like Units or Technologies) won't cause crashes any more, but others (like UnitPromotions) WILL crash the game if there are any gaps in the IDs. You just can't do Delete commands in those cases, you'll also need to re-index the IDs to make sure there are no gaps left. And yes, that's as painful as it sounds, so unless you really NEED those gone (to fit in a hundred or so custom promotions of your own), I wouldn't recommend using Deletes on those.

As for your changes to VictoryProgress, that could also cause problems depending on exactly what you did. Adding new features to a UI element isn't too bad, but if you're deleting existing stuff from it, then it might cause problems because of how the VFS enables. (That is, it might be trying to build the "old" UI and then replacing it with your changes, but it's crashing on the first part because it thinks it needs something you've removed.)

Quick question: is this happening for QuickSave games, auto-saved games, AND normal savegames? QuickSave and AutoSave games reload differently than normal savegames when mods are involved, which has been killing me in my own mod. So if it works for one type but not the others, then that really narrows it down.

Database.log has been quick to point out how many errors my mod has.

Yes, if it's appearing in the logfile, then you should really clean up the tables; they're probably not causing the crashes, but how would you know until they're fixed? There's a command (DeleteMissingReferences? Something like that.) that lets you do those second-order fixes, to where you just say "remove all entries that reference Type=UNIT_MECH in the Units table" and it cleans up all of the Flavor, resource requirement, promotion, etc. entries that key off that; I don't use it myself, because I prefer to do things explicitly.
 
All types of saves are crashing...well, I haven't tested out Auto-Save.

Yes I did deletes to promotions but so far it doesn't seem to be crashing anything. How would one reindex things? <ID></ID>? Seems highly unnecessary if the promotions aren't crashing at the moment.

And I'll be cleaning up the logfiles soon...with DeleteMissingReferences, since that seems easier to me. And Firaxis uses it.
 
Yes I did deletes to promotions but so far it doesn't seem to be crashing anything. How would one reindex things? <ID></ID>? Seems highly unnecessary if the promotions aren't crashing at the moment.

It'll crash the moment it tries to use the missing ID. Like, if you open the Civilopedia and go to the promotion page. Possibly the tech tree would crash as well; I'm not sure, and it might depend on exactly which promotions you're deleting. In my mod I deleted the Accuracy and Barrage promotion lines (ID #7-12), rolled their effects into Drill and Shock, and altered the prerequisites of any promotions that keyed off Accuracy or Barrage. It crashed right away as a result, and wouldn't stop crashing until I explicitly stuck six of my new promotions into those ID numbers.

And yes, you explicitly set the IDs like that. The less stressful way to handle it is, instead of Deleting the promotion to add one of your own, you simply use an Update command to replace every effect, text key, etc. for the old promotion with the ones for the new one. That way, the ID number is never vacant; the downside is that if you use it in conjunction with another mod that altered those particular promotions, you might get strange effects depending on load order. (If another mod adds some extra bonus in one of the other tables to an existing promotion, and you then use that Update method in your own, it'll get both effects if the other mod loads first.)
 
Naw, it's not crashing when I open up the civilopedia or tech tree.
 
How would one reindex things? <ID></ID>? Seems highly unnecessary if the promotions aren't crashing at the moment.

In the early days of Civ5 modding, missing (non-continuous) IDs would crash the game outright for very many tables, or cause other bizarre non-traceable problems. We didn't really know what was going on until lemmy101 figured it out and provided the Deletion Fixinator. The basic code to reindex a table goes like this (re-write for each table you delete/add to):

Code:
CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
INSERT INTO IDRemapper (Type) SELECT Type FROM Buildings;
UPDATE Buildings SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Buildings.Type = IDRemapper.Type);
DROP TABLE IDRemapper;

What happened is that some patch later made missing IDs less bad, not crashing the game instantly. However, I've seen several cases in developer Lua code where missing IDs will still do bad things, and I assume there are many more such cases in the dll (likely with very unpredictable consequences). As a general practice, I run the code above after I modify any indexed table. (Until recently, I was still using lenny101's original code that reindexes everything. But now I just do it for indexed tables that I modify.)
 
In the early days of Civ5 modding, missing (non-continuous) IDs would crash the game outright for very many tables, or cause other bizarre non-traceable problems. We didn't really know what was going on until lemmy101 figured it out and provided the Deletion Fixinator. The basic code to reindex a table goes like this (re-write for each table you delete/add to):

Code:
CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
INSERT INTO IDRemapper (Type) SELECT Type FROM Buildings;
UPDATE Buildings SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE Buildings.Type = IDRemapper.Type);
DROP TABLE IDRemapper;

What happened is that some patch later made missing IDs less bad, not crashing the game instantly. However, I've seen several cases in developer Lua code where missing IDs will still do bad things, and I assume there are many more such cases in the dll (likely with very unpredictable consequences). As a general practice, I run the code above after I modify any indexed table. (Until recently, I was still using lenny101's original code that reindexes everything. But now I just do it for indexed tables that I modify.)

Okay I'll keep this in mind. Thanks!
 
Alright, so I'm actively trying to fix this now...

Runtime error on load. There are no additional details given. Sigh...

I tried the DeleteFixator.sql thing. Still not working. :/

I just wish the game would give me some sort of...hint....something.
 
Just posting to say the crash on load game is fixed. It was because I was deleting Unit Promotions. I removed the deletes and the game can load again properly. Thanks, Spatz!
 
Top Bottom