Random crashes in my .NET code using SWI-Prolog

I’ve encountered weird crashes while using SWI Prlog through my .NET wrapper.

Console prouces following text:

[PROLOG SYSTEM ERROR:  Thread 1 (main) at Sat Oct 05 15:24:50 2024
	relocation cells = 8864; relocated_cells = 8864, needs_relocation = 8863
	
[While in 7-th garbage collection]

/home/swipl/src/swipl-devel/src/os/pl-cstack.c:1047 C-stack dumps are not supported on this platform
2

PROLOG STACK:
  [15] system:$collect_findall_bag/2 [PC=1 in supervisor]
  [13] $bags:cleanup_bag/2 [PC=4 in clause 1]
  [10] expandRule/2 [PC=19 in clause 1]
  [7] expandBody/2 [PC=14 in clause 3]
  [6] expandBody/2 [PC=20 in clause 3]
  [5] expandBody/2 [PC=14 in clause 3]
  [4] expandBody/2 [PC=20 in clause 3]
  [3] expandBody/2 [PC=20 in clause 3]
  [2] expandRule/2 [PC=119 in clause 1]
  [1] text/2 [PC=28 in clause 3]
]

Interestingly enough, I get this errors only when run this particular Prolog calls from Godot.
Running simpler prolog code or running from console testbed application seems to work.

I need hints on that goes wrong.

Hmm… looks like it is caused by accessing terms bound by query after closing it.

To help debugging this, use the development series, which gives runtime errors on a good deal of invalid usage of the API, notably involving term_t handles. Quite a few people make mistakes here as the rules are quite subtle :frowning: A lot of broken code seems to work fine but it causes subtle corruptions in Prolog’s data structures that lead to the crashes you observe when the garbage collector runs.

Another hint is to compile SWI-Prolog using -DCMAKE_BUILD_TYPE=Debug. That adds a bunch more sanity checks to the code. Next, you can run your code using swipl -d chk_secure ... to enable many more consistency checks (and make the system really slow). The -d option is only available when compiled in debug mode.

1 Like

How can I get development series?
Are they prebuilt and available for download somewhere, or I need to build it myself from source?

I refer to the 9.3.x (9.3.12 is the latest). This is available for download through all channels. If you want the debug version you need to build from source. When doing what you try to do it might be wise to install from source :slight_smile:

1 Like