Mod troubleshooting

本页面讲述的内容长期有效

排除故障是mod开发中重要的一部分,包括对崩溃、bug和其他问题的排除。

概述

有两种错误——致命性错误与非致命性的。

致命性错误发生于游戏无法加载一个关键数据,并且在缺乏此数据时就无法运行的情况下。这会导致闪退(Crash To Desktop)。当致命性错误发生时,文件exceptions.log将会增添一行记录. 通常它们会发生于游戏加载过程中,或者进行某项特定操作时。

非致命性错误发生于游戏在运行时遭遇到了无效数据或者错误的语法。这些错误被记录于error.log.。

测试

在Debug流程中可以使用如下的控制台代码:eventobserverun

The run command is very useful for testing effects without having to reload the game. It also makes it very easy to setup test scenarios without introducing wayward code within the mod itself.

The observe is useful when you want to test the stability of your mod during gameplay. By becoming an observer, you can let the game run without your input, making it easier to detect issues that occur irregularly.

加载

在加载游戏时会先后进入以下过程,这些描述出现于加载界面顶端。本地化文件位于:/Europa Universalis IV/localisation/text_l_english.yml/Europa Universalis IV/localisation/EU4_l_english.yml

Step 步骤
Loading Databases 读取数据库
Initializing Maplogic 初始化地图逻辑……
Loading Databases... 读取数据库……
Loading History Files... 载入历史文件……
Loading Sounds... 载入音乐……
Loading Events... 载入事件……
Loading GUI Definitions... 读取用户界面……
Loads Flags... 载入旗帜……
Creating Checksum... 创建校验和……
Loading Graphics... 载入图像……
Creating Province # 创建省份 #
Creating Shaders... 载入地图中(创建阴影)……
Creating Terrain... 载入地图中(创建地形)……
Creating Borders... 载入地图中(创建国界)……
Creating Straits... 载入地图中(创建海峡)……
Creating Textures... 载入地图中(创建纹理)……
Creating Trees... 载入地图中(创建树木)……
Creating Rivers... 载入地图中(创建河流)……
Creating objects... 载入地图中(创建物件)……
Initializing Game... 初始化游戏……

Log 文件

游戏将各种日志文件存储在您的EU4用户文件夹中:(\\documents\paradox interactive\europa universalis iv\logs\.)。每次游戏开始时都会覆盖这些内容。

要启用完整的错误日志记录,请通过STEAM中的“设置启动选项”添加-debug命令。

File Description Usefulness
ai.log Prints the country selection of the player and then the Starting AI line. Low
error.log Prints the various non-fatal errors. Many errors can be ignored, although almost all errors relating to files in the common folder should be fixed. High
error_old.log The error.log from the previous game launch. Low
error_old_old.log The error.log from the second previous game launch. Low
exceptions.log Prints the stacktrace when the game crashes to desktop. Currently only prints the hexadecimal address, making this file fairly useless. Low
executedcommands.log Prints the internal commands uses by the player and AI. Low
game.log Prints the actions taken by countries in game. Useful when the crash is due to a specific action. High
graphics.log Prints the graphical errors relating to positions. Low
local_temp.log Low
memory.log Prints the memory used during setup. Useful for crashes during the loading process, to see when the game crashed. High
message.log Prints the session info for the current session. Low
profiling.log Prints the profiling output if using the profiling .exe file. High
random.log Low
random02.log Low
receivedcommands.log Prints the internal commands received by the player in multiplayer. Low
sentcommands.log Prints the internal commands sent by the player in multiplayer. Low
setup.log Prints the completion of setup loading for each part of the process. Very useful for discovering which file may be causing a crash. High
setup_error.log Prints errors in the /Europa Universalis IV/common/countries files. Typically errors are of low importance. Low
system.log Prints the system information EU4 is loaded on. Low
system_interface.log Prints interface errors. Low
text.log Prints asserts on localization keys. Low
time.log Prints the time it takes for the various loading steps to complete, and the tick interval. Very useful for crashes during the loading process, to see when the game crashed. High

除错

Generally, when debugging you want to narrow down the possible causes for a crash. This is why it is best to run your mod after every change, so any issues become immediately apparent, and you can find the cause easily since it'll be the last file you edited.

If this is not possible, then you want to isolate the potential causes. This is done by moving the suspected files and folders out of your mod folder and into a temporary folder, and then launching the mod without them. This requires a good amount of knowledge of how each file works together, so you can safely isolate files and folders without introducing broken dependencies.

Typically you can easily isolate the events, decisions, missions and interface folders without too much worry. Then in the common folder, remove files or folders one-by-one, re-launching the game each time to determine which is causing the issue. If none, then it is likely the issue is in the history or map folder. Repeat this process throughout them.

崩溃

Most fatal errors that cause crashes to desktop can be very difficult to debug without extensive knowledge of modding. The following list is of known crashes to help modders debug:

Crash Fix
当 "读取数据库" (Loading Database) If you are using the defines.lua, check you have included all the entries that vanilla includes.

Check that there are no references to non-existing files.

  • A tag in country_tags must not reference a file that does not exist.
  • Make sure that all defined colonial regions have at least one province assigned.
  • Scripted Effect / Meta Script with wrongly coded (leads to stack overflow exception) -> conditional input not used correctly, [] used for something thats not an conditional input e.g. localisation, non closed $input$ like $input
During "Initializing Maplogic" Check that the gamelogic map images have been saved in the correct formats. Make sure the map files used follows the guidelines listed in Map modding.
  • default.map province limit isn't higher than the last province ID in definition.csv.
  • A province ID in default.map no longer exists in the definition.csv.
  • A province ID in adjacencies.txt no longer exists in the definition.csv.
  • A province ID in area.txt no longer exists in the definition.csv.
  • A province ID in climate.txt no longer exists in the definition.csv.
  • A province ID in continent.txt no longer exists in the definition.csv.
  • A province ID in terrain.txt no longer exists in the definition.csv.
  • A province ID in trade_winds.txt no longer exists in the definition.csv.
  • A province ID in area.txt no longer exists in the definition.csv.
  • terrain.bmp has a missing or corrupted color table.
  • rivers.bmp has a missing or corrupted color table.
  • trees.bmp has a missing or corrupted color table.
  • Map dimensions are not a product of 128.
  • The provinces.bmp exceeds 52 megabytes.
  • The provinces.bmp contains provinces that are too large.
During "Loading History Files..." Check that the history files do not reference any missing country tags or provinces IDs.
During "Loads Flags..." Check that the history files do not reference any missing country tags (specifically the diplomacy folder).
During "Loading Graphics..." Check that the graphical map images have been saved in the correct formats. Make sure the map files used follows the guidelines listed in Map modding.
During "Loading Map (Creating Straits)..." Check that the adjacencies.txt file lists valid straits.
当点击单人游戏时 这一问题是因为可能增加了省份,但未添加新增的省份代码到map/area.txt、map/continent.txt与common/tradenodes所导致
Clicking Play in the lobby The issue can lie within the common files:
  • Missing entries in required files such as static_modifiers
  • Missing entries for modifiers used in effects or triggers.

History files:

  • A country capital defined in history/countries references a province id that has no pixels in map/provinces.bmp.
Clicking a Province * Make sure the province belongs to a continent in continent.txt.
  • Make sure the province belongs to an area in area.txt.
Nation Designer Government Tab when using more than 3 Government Ranks The nationadesignerview.gui file needs to be edited to have additional icon_gov_desc_* and gov_desc_* for each new level of government rank.
Crash on Hover in an Interface Typically caused by a clause missing from the relevant files, i.e. the army professionalism static modifiers when hovering over the Hire General button.
Trying to Move a Capital Often caused by missing or misnumbered provinces in continent.txt.
Hovering over a country in the Great Powers list Also often caused by missing or misnumbered provinces in continent.txt.

This process will almost always allow you to discover the cause of a crash, although it is tedious.

Profiling

Since patch 1.23, Europa Universalis IV includes a performance profiler alongside the normal game. This tool is useful for modders that want to measure and diagnose poor performance within their mods.

To use the profiler, you need to launch the game launcher by click eu4_profiling.exe within the game installation folder. This will launch the game launcher, which you can then use to select your mod and launch the game.

Once in game, allow the game to run until you have reached a suitable duration, and then open the console and type dump_script_profiling to write to the profiling.log in the logs folder.

The profiling.log should be viewed in a mono-spaced font for best readability.