I’m trying to assign to a void * handed to me from sdl. Assigning to the dereferenced pointer is a type mismatch. @memset expects dest to be a slice. Is there an idiomatic way to do this kind of assignment? Can I cast *anyopaque to a slice with a runtime-known size? Thanks in advance
const mappedTransferBuffer = sdl.SDL_MapGPUTransferBuffer(device, vertexTransferBuffer, false);
if(mappedTransferBuffer == null) sdl_err();
//@memset(mappedTransferBuffer.?, vertexData);
mappedTransferBuffer.?.* = vertexData;
If you want to cast mappedTransferBuffer you can do it as follows:
const ptr : [*]type_of_element = @ptrCast(@alignCast(mappedTransferBuffer));
const slice = ptr[0..len_of_buffer];
Many thanks! new code is compiling:
const mappedTransferBuffer = sdl.SDL_MapGPUTransferBuffer(device, vertexTransferBuffer, false);
if(mappedTransferBuffer == null) sdl_err();
const mappedPtr: [*]@TypeOf(vertexData[0]) = @ptrCast(@alignCast(mappedTransferBuffer));
const mappedSlice = mappedPtr[0..vertexData.len];
mappedSlice.* = vertexData;
Is there a reason you don’t return for the null situation?
sdl_err() panics so there’s no need
I would still do an explicit return or unreachable there.