dispose method

void dispose()

Decrements the reference count of this texture. If the reference count reaches zero, the texture is deleted, and any onDispose callbacks are triggered. Logs an error if the reference count is already zero or less.

Implementation

void dispose() {
  if (_refCount < 1) {
    die("Refcount of Texture cannot be less than zero.");
  }

  _refCount--;

  if (_refCount == 0) {
    if (handle != null) {
      _renderer.destroyTexture(handle!);
    }
    handle = null;
    for (var func in _onDispose) {
      func(this);
    }
    _onDispose.clear();
  }
}