UmbraSpaceIndustries / CommunityResourcePack

The KSP Community Resource Pack
Other
50 stars 54 forks source link

[Loading hang][Regression] CommunityResourcePack caused loading hang #213

Open adam900710 opened 7 years ago

adam900710 commented 7 years ago

Version: 0.8.0.0 OS: Archlinux KSP version: 1.3.1 KSP.log:

[LOG 17:51:29.835] Config(TUTORIAL) Squad/Tutorials/FromMun/FromMun
[LOG 17:51:29.835] Config(TUTORIAL) Squad/Tutorials/GoForOrbit/GoForOrbit
[LOG 17:51:29.835] Config(ScienceChecklist) [x] Science!/science/ScienceChecklist
[LOG 17:51:29.837] Resource RESOURCE_DEFINITION added to database
[LOG 17:51:29.837] Resource RESOURCE_DEFINITION added to database
[LOG 17:51:29.837] Resource RESOURCE_DEFINITION added to database
[LOG 17:51:29.837] Resource RESOURCE_DEFINITION added to database
[EXC 17:51:29.840] ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
    System.String.Substring (Int32 startIndex, Int32 length)
    PartResourceDefinition.GetShortName (Int32 length)
    PartResourceDefinition.Load (.ConfigNode node)
    PartResourceDefinitionList.Add (.ConfigNode node)
    PartResourceLibrary.LoadDefinitions ()
    GameDatabase+
    .MoveNext ()
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress)
[LOG 17:51:29.858] CodeAssetLoader: Compiling all code assets

Yes, I have some other small mods, but with only CommunityResourcePack mod, it will cause loading hang. Other mods are: [x] Science MechJeb Kerbal Alarm Clock

adam900710 commented 7 years ago

It's a regression, version 0.7.2.0 works fine.

adam900710 commented 7 years ago

236c3f05b1270145a0f18314fa6b1caca1937b7d is the first bad commit

Well, I forgot to mention I'm also using Chinese localisation, so I wonder other language is not affected and no tester exposed it yet.

adam900710 commented 7 years ago

difftool shows me some different in lines and whitespace difference (4 spaces vs 1 tab), but even after I manually modified them, it's still triggering the hang.

While copying en-us.cfg to overwrite zh-cn.cfg definitely fixed the problem, it's definitely the problem of zh-cn.cfg. Very strange here.

BobPalmer commented 7 years ago

@sswelm - you need to sort this please, as it was introduced in your commit.

adam900710 commented 7 years ago

Extra info, I verified the dict from Squad in GameData/Squad/Localization/dictionary.cfg, which has UTF-8 BOM, with CRLF as change line.

However the en-us.cfg is without BOM, with LF only. I'll try to convert the translation to the same format as Squad to see if it helps

xiaoqianWX commented 7 years ago

Hi, this file is translated by me, well, in my mind, I think this is because you didn't have KSPFileLocalizer in your GameData.

adam900710 commented 7 years ago

Is that a mod or something else? At least I can't find such mod.

adam900710 commented 7 years ago

@EthanWang706 Any extra info about how to fix it?

xiaoqianWX commented 7 years ago

screen shot 2017-10-29 at 1 08 44 pm Here, it's included inside KPBS or Feline Rover

adam900710 commented 7 years ago

Get from https://github.com/Nils277/KSPModFileLocalizer

Tried, no help. Still loading hang.

Also tried KSPModFileLocalizer from KPBS, still no help.

xiaoqianWX commented 7 years ago

It feels like I can't fix it, I tried any way that I could think about, if I change it to English, the game will crash, maybe @sswelm @BobPalmer could fix it

BobPalmer commented 7 years ago

We will very likely have to just remove the file if @sswelm cannot do a fix, since as noted, this was a file he introduced (and I had assumed tested).

sswelm commented 7 years ago

I still have a few ideas I would like to test to see if we can identify the problem

sswelm commented 7 years ago

Alright, there appears to be some translation in the USI and RealFuels section that are causing a crash. I suspect some illegal Chinese character were used, its hard to tell which one, but I will narrow it down

sswelm commented 7 years ago

I figured out which Chinese localization were causing problems, I made a pull request of a localisation where I commented out the illigal chinese characters that were causing KSP to crash. I kope to fix the missing localisation later on

xiaoqianWX commented 7 years ago

I just contact Squad for fixing this issue, it could be found here: https://forum.kerbalspaceprogram.com/index.php?/topic/167052-simple-translations-illegal/

xiaoqianWX commented 7 years ago

This is pretty much being fixed, for ones that is hard to translate to Chinese, I replaced them with English

xiaoqianWX commented 7 years ago

Submitted in SQUAD BugTracker #16477

tinygrox commented 1 month ago

It's been 7 years, and now there's finally a solution to this! the problem was actually the missing abbreviation field! not because of some illegal Chinese characters being used. When the abbreviation is absent, the game will call a method GetShortName(2), which returns displayName.Substring(0, 2). Since the length of displayName is less than 2(the lead's displayName is "铅"), Substring throws an exception! So, the fix is simply adding the abbreviation field within the RESOURCE_DEFINITION!

For "Lead" example:

RESOURCE_DEFINITION
{
    name = Lead
    displayName = #LOC_CRP_Lead_DisplayName
    abbreviation = #LOC_CRP_Lead_abbreviation   // <== HERE!
    density = 0.01134
    unitCost = 0.067392
    hsp = 128
    flowMode = ALL_VESSEL
    transfer = PUMP
    isTweakable = True
    isVisible = true
    volume = 1
    ksparpicon = RealFuels/Resources/ARPIcons/LeadBallast
}

unfortunately, this happens during the ConfigNode loading phase, so I believe it's not possible to use ModuleManager (MM) to apply a patch.