module Docs::G_CAVEATS_AND_INTERNALS

Overview

G. Engine Caveats, Memory & Internals

When building high-performance games with LibGodot, developers should be aware of several critical architectural nuances spanning garbage collection, memory ownership, and threading.


1. Memory Ownership: Boehm GC vs. Godot Reference Counting

LibGodot bridges two distinct memory models:

Critical Rules:

  1. Never store raw pointers to freed Godot nodes: When a node is destroyed in Godot (e.g. via queue_free), its underlying C++ memory is deallocated. A Crystal wrapper object (Godot::Node) holding that pointer will become invalid. Check is_queued_for_deletion or null pointers before dereferencing cached node references.
  2. GC Roots in Shared Libraries: On Windows, when game.dll is dynamically loaded by Godot, static Crystal variables and method bindings are registered as GC roots. Always ensure large static data structures are cleared during crystal_godot_cleanup.

2. Thread Safety & Thread Affinity

Godot executes rendering, physics, and main loop processing on different threads:


3. Method Bind Pointer Caching (@@mb_*)

Invoking Godot methods through Variant reflection (Object.call) involves string hash lookups and boxing/unboxing overhead.

To achieve near-native C++ performance:


4. Windows Toolchain & Runtime Nuances

Defined in:

libgodot/docs.cr

Class Method Summary

Class Method Detail

def self.caveats : Array(String) #

Dummy method for documentation visibility


[View source]