disposeStructWithOpFreed<D extends RaylibStruct<D>> method

void disposeStructWithOpFreed<D extends RaylibStruct<D>>(
  1. D struct,
  2. void fn(
    1. StructPointer<D> ptr
    )
)
inherited

Disposes struct, invokes fn with its underlying pointer, and then frees the temporary allocation backing the pointer, if any.

The allocation is freed after fn completes, including when fn throws. This is intended for APIs where the external call does not take ownership of the underlying memory.

Implementation

void disposeStructWithOpFreed<D extends RaylibStruct<D>>(
  D struct,
  void Function(StructPointer<D> ptr) fn,
) {
  final ptr = struct.getOpAndDispose();

  try {
    fn(ptr);
  } finally {
    if (ptr.allocationKey case final key?) {
      $.structAlloc<D>()!.Free(key);
    }
  }
}