Repository: libsdl-org/SDL
File: src/haptic/windows/SDL_dinputhaptic.c (C)

Code before:
    if (!type) {
        return SDL_SetError("Haptic: Unknown effect type.");
    }

    // Get the effect.
    if (!SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base)) {
        goto err_effectdone;
    }

    // Create the actual effect.
    ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
                                           &effect->hweffect->effect,
                                           &effect->hweffect->ref, NULL);
    if (FAILED(ret)) {
        DI_SetError("Unable to create effect", ret);
        goto err_effectdone;
    }

    return true;

err_effectdone:
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
    return false;
}

BOOL DIGetDirectionUpdateFlag(DIEFFECT* before, DIEFFECT* after)
{
    if (before->cAxes != after->cAxes) {
        return true;
    }
    // rglDirection must be non-null for DIEP_DIRECTION to be a valid flag
    if (after->rglDirection == NULL) {
        return false;
    }
    if (before->rglDirection == NULL) {
        return true;
    }

    return SDL_memcmp(before->rglDirection, after->rglDirection, sizeof(LONG) * before->cAxes) != 0;
}

BOOL DIGetEnvelopeUpdateFlag(DIEFFECT* before, DIEFFECT* after) {
    if (before->lpEnvelope == NULL && after->lpEnvelope == NULL) {
        return false;
    }
    // A null lpEnvelope is valid for DIEP_ENVELOPE (clears the envelope from the effect)
    if (before->lpEnvelope == NULL || after->lpEnvelope == NULL) {
        return true;
    }
    return SDL_memcmp(before->lpEnvelope, after->lpEnvelope, sizeof(DIENVELOPE)) != 0;
}

Review comment (suggestion):
```suggestion
BOOL DIGetDirectionUpdateFlag(DIEFFECT *before, DIEFFECT *after)
```

Code after:
    if (!type) {
        return SDL_SetError("Haptic: Unknown effect type.");
    }

    // Get the effect.
    if (!SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base)) {
        goto err_effectdone;
    }

    // Create the actual effect.
    ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
                                           &effect->hweffect->effect,
                                           &effect->hweffect->ref, NULL);
    if (FAILED(ret)) {
        DI_SetError("Unable to create effect", ret);
        goto err_effectdone;
    }

    return true;

err_effectdone:
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
    return false;
}

BOOL DIGetDirectionUpdateFlag(DIEFFECT *before, DIEFFECT *after)
{
    if (before->cAxes != after->cAxes) {
        return true;
    }
    // rglDirection must be non-null for DIEP_DIRECTION to be a valid flag
    if (after->rglDirection == NULL) {
        return false;
    }
    if (before->rglDirection == NULL) {
        return true;
    }
    return SDL_memcmp(before->rglDirection, after->rglDirection, sizeof(LONG) * before->cAxes) != 0;
}

BOOL DIGetEnvelopeUpdateFlag(DIEFFECT* before, DIEFFECT* after)
{
    if (before->lpEnvelope == NULL && after->lpEnvelope == NULL) {
        return false;
    }
    // A null lpEnvelope is valid for DIEP_ENVELOPE (clears the envelope from the effect)
    if (before->lpEnvelope == NULL || after->lpEnvelope == NULL) {
        return true;
    }
    return SDL_memcmp(before->lpEnvelope, after->lpEnvelope, sizeof(DIENVELOPE)) != 0;
}