For some time I’ve been watching the Castle Game Engine development. This is a game engine written in ObjectPascal language. I have worked many years in this language so I have a certain sentiment. Object Pascal has simple, clear syntax and very short compile times. This features should be very helpful in game development.
Unfortunately I ran into a minor problem. Closing a window of each example stops execution and throws exception. It was weird so I decided to investigate. I tested on many computers with different operating systems.
Linux problem (Nvidia)
It turned out that the problem only occurs on Linux computers with Nvidia graphics cards (I tested GTX 1060, GTX 650, GT 710). On the Intel or AMD cards, everything was fine. Changing the drivers from version 390 to 396 or 430 did not help.
Subsequent tests showed that the problem also concerns examples of using OpenGL in Lazarus (eg openglcontrol_demo) which meant that the error is not in the engine!
The problem was in used Free Pascal compiler version. For testing, I used the compiler in version 3.0.4. As of 18/05/2019, the compilation from the fixes_3_0 branch did not work. The problem disappeared after updating the compiler to the version from the fixes_3_2 branch. So if you plan to write a game or application for Linux that uses OpenGL. Use the unpublished version 3.2. You can read more about fixes_3_2 branch here.
How to update the compiler
It’s best to use the fpcupdeluxe program, which automates the process to a few clicks.
Dependencies
Your operating system must have subversion installed, and GTK2, GtkGLExt libraries with developer packages (-dev). In debian/ubuntu based systems, you can do this:
sudo apt install subversion libgtk2.0-dev libgtkglext1-dev
No pascal compiler is needed in your OS, fpcupdeluxe will download all needed files. If you already have the fpc compiler installed, you can safely remove it (including the Lazarus).
Folders
After using the fpcupdeluxe utility, it will create several configuration files next to the executable file, so it is worth copying it to a folder. Personally, I prefer the fpc folder in the home directory. The fpcupdeluxe program allows you to install many different compiler/lazarus versions side by side. Each such version is installed as a separate subfolder. We can easily have a stable version and fixes next to each other, eg:
- ~/fpc/stable – stable versions of FPC and Lazarus
- ~/fpc/fixes32 – FPC from fixes_3_2 branch and stable version of Lazarus
Installing FPC and Lazarus
After running fpcupdeluxe, the following window will appear:
In the window, select the installation folder (eg /home/user/fpc/fixes32), the version of the compiler (fixes3.2) and lazarus (stable). Next click “Install/update FPC + Laz”.
After installation, the Lazarus_name_of_folder icon will appear on the desktop (in our case it’s Lazarus_fixes32). From this link you should run Lazarus.
Access to the compiler from the console
To access the compiler from the console, add the executable files folders to the PATH variable and the compiler configuration folder to the PPC_CONFIG_PATH variable:
export PATH="/home/user/fpc/fixes32/fpc/bin/x86_64-linux:${PATH}" export PPC_CONFIG_PATH="/home/user/fpc/fixes32/fpc/bin/x86_64-linux"
The above lines can be added to the .profile file. Changes will be available after user’s relogin.
If you want to use many versions of the compiler, you can write a bash script:
#!/bin/sh export PATH="/home/user/fpc/fixes32/fpc/bin/x86_64-linux:${PATH}" export PPC_CONFIG_PATH="/home/user/fpc/fixes32/fpc/bin/x86_64-linux"
That’s all, examples compiled with this version of the compiler (fixes3.2) will work correctly on all linux machines.