Skip to content

Change sources of our project (Castle Game Engine) very often needs full recompilation or ends with internal errors or compiler raises exceptions

Summary

Hi,

I'm one of Castle Game Engine developer and we have problem with fpc compiler. Any change in some files like src/x3d/x3dnodes.pas (for example TX3DNode class) or src/x3d/x3dfields.pas (for example TX3DEvent class) need full recompilation to successfully compile the engine. So we need use Run->Clean up and build after almost every change of sources. Just hitting F9 ends with internal error (in fpc fixes, fpc trunk in some cases) or compiler raises exception (fpc trunk). CGE is a large project with thousands of files, so it slows down the engine development process.

To help fix this bug, I've been cuting the source of the engine over the last few weeks to find the smallest possible snippet that compiles and contains the above problem. I managed to cut 99.99% of the sources. The smallest part are in the github repository: https://github.com/and3md/cge-fpc-internalerror. Only five small files.

System Information

  • Operating system: Windows 10 64bit, Linux (Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy)
  • Processor architecture: x86-64
  • Compiler version: 3.2 fixes (3.2.3-703-gcd83438c [2023/01/22], 3.2.3-705-g0c525630 [2023/02/20]), trunk (3.3.1-12496-g586a7d30 [2023/02/20], 3.3.1-12495-g090e4fea [2023/02/19])
  • Device: Computer

Steps to reproduce

  1. Clone https://github.com/and3md/cge-fpc-internalerror
  2. Open the project
  3. Make clean build by Run->Clean up and build
  4. Uncomment one of ATest variable in sources (TX3DNode class or TX3DEvent class).
  5. Hit F9 to compile
  6. FPC returns Internal error or exception

Example Project

Clone https://github.com/and3md/cge-fpc-internalerror - the smallest part of engine I found that has the issue. Only five small files. Some modules are not used but present in this example to get internal error. They are used in full sources so I can't simply remove them to fix issue.

Of course sources from https://github.com/and3md/cge-fpc-internalerror are cut very strong (but compiles) if you want full working sources get Castle Game Engine sources from github: https://github.com/castle-engine/castle-engine

What is the current bug behavior?

The error returned by compiler depends on fpc version.

  1. Current FPC 3.2 fixes:

The compiler ends with Internal error 200611031.

Verbose: Compiling ./src/x3d/castlematerialproperties.pas
castlematerialproperties.pas(34,3) Hint: Unit "X3DNodes" not used in CastleMaterialProperties
Verbose: Compiling ./src/x3d/x3dfields.pas
Fatal: Internal error 200611031
Verbose: Compilation aborted
  1. FPC trunk (2023-02-20):

The result depends on what ATest variable you uncomment.

ATest - from TX3DEvent - the compiler raises exception:

Verbose: Compiling ./src/x3d/castleinternalnodeinterpolator.pas
castleinternalnodeinterpolator.pas(42,26) Hint: Parameter "A" not used
castleinternalnodeinterpolator.pas(54,7) Error: Compilation raised exception internally
Error: An unhandled exception occurred at $000000000050E7A1:
Error: EAccessViolation: Access violation
Debug:   $000000000050E7A1
Debug: 

ATest - from TX3DNode - the compiler ends with internal error 200204212:

Verbose: Compiling ./src/x3d/castlematerialproperties.pas
castlematerialproperties.pas(34,3) Hint: Unit "X3DNodes" not used in CastleMaterialProperties
Verbose: Compiling ./src/x3d/x3dfields.pas
x3dfields.pas(51,14) Error: Internal error 200204212
Verbose: Compilation aborted

The second test with ATest from TX3DNode has sometimes another result - an exception. To get it check commit a428441a39fd1d01bef73b5e22d31e688d5d426c - "Removed TX3DField EventIn and EventOut" from example project

The exception is:

Verbose: Compiling ./src/x3d/x3dfields.pas
x3dfields.pas(90,14) Error: Compilation raised exception internally
Error: An unhandled exception occurred at $000000000046A004:
Error: EAccessViolation: Access violation
Debug:   $000000000046A004
Debug: 
Verbose: Compilation aborted

What is the expected (correct) behavior?

FPC should compile project without need to cleaning all sources.

Possible fixes

My suspicions: Removing helper TSFNodeEventHelper fixes error in this small code base maybe it is a good suspect. Also removing some modules from uses section helps. But we can't do that in full sources in Castle Game Engine. They are used in full sources.

Edited by Andrzej Kilijański
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information