Error if compile from castle Editor

I followed the manual with first steps. I’m using Lazarus Trunk (2.3.0) and FPC Trunk (3.3.1)

if i compile the example from within castleeditor then it compiles fine but after start i get an exception Arithmetic overflow

if i load the project in Lazarus and run with F9 it runs without problems.

Hm, this is weird. The problem is inside TRectangle.AlignCore, at line

hpMiddle: Result := Result - Width div 2;

It happens from TCastleWindowBase.OpenCore, which is something that almost all normal CGE applications do. So, it works for me.

What application do you run?

  1. If it’s your own application, please first check one of our examples, or a “New Project” done with template “Empty” without any modifications. If the problem is specific to your project (and doesn’t occur with our examples) then please show us a simplified version of your project to reproduce the problem.

    • In particular, I’m interested do you adjust Theme.ImagesPersistent[tiLoading] or Theme.LoadingImageForWindowHeight.
  2. If the error occurs with all CGE applications, including our sample examples/templates, then something specific to your system must cause it.

    • Please send the log of your application execution. The location of the log file is specified in Logging | Manual | Castle Game Engine ,

    • Put some additional logs. Before line 2982 of src/window/castlewindow.pas, i.e. right before the call

      TextRect := Theme.ImagesPersistent[tiLoading].Image.Rect.
        Align(hpMiddle, WindowRect, hpMiddle).
        Align(vpMiddle, WindowRect, vpMiddle);

      add additional lines to log revelant info:

      WritelnLog('UIScale %f', [UIScale]);
      WritelnLog('WindowRect %s', [WindowRect.ToString]);
      WritelnLog('Theme.ImagesPersistent[tiLoading].Image.Rect %s', [Theme.ImagesPersistent[tiLoading].Image.Rect.ToString]);

      Add them, and generate log file again. The expected result is that similar log appears, with additonal lines like this:

      UIScale 1.00
      WindowRect TRectangle: 0x0 1920x1080
      Theme.ImagesPersistent[tiLoading].Image.Rect TRectangle: 0x0 624x426

To be clear, it is OK that you get this error only when compiling from CGE editor, and not from Lazarus, because they do use a bit different compilation flags. In CGE editor, F9 runs build tool with --mode=debug, and it runs with overflow checking enabled. In Lazarus the default compilation setting is something between debug and release – it doesn’t enable overflow checking, but also has no special optimizations.

If you’re interested in what is “overflow error” – see
What are range and overflow checks (and errors) in Pascal · michaliskambi/modern-pascal-introduction Wiki · GitHub .

Of course, in neither compilation mode (debug or release, CGE editor or Lazarus) should this error be reported.