sdlSetPointerPropertyWithCleanup function
- int props,
- String? name,
- Pointer<
NativeType> value, - Pointer<
NativeFunction< cleanup,SdlCleanupPropertyCallback> > - Pointer<
NativeType> userdata,
Set a pointer property in a group of properties with a cleanup function that is called when the property is deleted.
The cleanup function is also called if setting the property fails for any reason.
For simply setting basic data types, like numbers, bools, or strings, use SDL_SetNumberProperty, SDL_SetBooleanProperty, or SDL_SetStringProperty instead, as those functions will handle cleanup on your behalf. This function is only for more complex, custom data.
\param props the properties to modify. \param name the name of the property to modify. \param value the new value of the property, or NULL to delete the property. \param cleanup the function to call when this property is deleted, or NULL if no cleanup is necessary. \param userdata a pointer that is passed to the cleanup function. \returns true on success or false on failure; call SDL_GetError() for more information.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
\sa SDL_GetPointerProperty \sa SDL_SetPointerProperty \sa SDL_CleanupPropertyCallback
extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata)
Implementation
bool sdlSetPointerPropertyWithCleanup(
int props,
String? name,
Pointer<NativeType> value,
Pointer<NativeFunction<SdlCleanupPropertyCallback>> cleanup,
Pointer<NativeType> userdata) {
final sdlSetPointerPropertyWithCleanupLookupFunction = libSdl3.lookupFunction<
Uint8 Function(
Uint32 props,
Pointer<Utf8> name,
Pointer<NativeType> value,
Pointer<NativeFunction<SdlCleanupPropertyCallback>> cleanup,
Pointer<NativeType> userdata),
int Function(
int props,
Pointer<Utf8> name,
Pointer<NativeType> value,
Pointer<NativeFunction<SdlCleanupPropertyCallback>> cleanup,
Pointer<NativeType> userdata)>('SDL_SetPointerPropertyWithCleanup');
final namePointer = name != null ? name.toNativeUtf8() : nullptr;
final result = sdlSetPointerPropertyWithCleanupLookupFunction(
props, namePointer, value, cleanup, userdata) ==
1;
calloc.free(namePointer);
return result;
}