#Cannot load runtime value in comptime block
1 messages · Page 1 of 1 (latest)
To me it looks like you are calling playdate_allocate_memory in a comptime context but I can't tell for sure without the callsite
call site is in the zigbin: https://zigbin.io/27c937
The call site of playdate_allocate_memory, not playdate_realloc
I don't know why the compiler would think that line is happening at comptime otherwise
ah sorry. its on line 17 here: https://zigbin.io/cd666e
Hmm, that does seem weird
ah sorry: this is where playdate_allocate_memory is used
const platform_allocate_memory = switch (toolbox.THIS_PLATFORM) {
//.MacOS => unix_allocate_memory,
//.MacOS => posix_allocate_memory,
.MacOS => macos_allocate_memory,
.BoksOS => boksos_allocate_memory,
.Playdate => playdate_allocate_memory,
};
and THIS_PLATFORM is a comptime value
that's fine, that just means the switch gets evaluated at comptime
but how do we get from platform_allocate_memory to toolbox.os_allocate_object?
got it:
pub fn os_allocate_object(comptime T: type) *T {
var memory = platform_allocate_memory(@sizeOf(T));
return @ptrCast(*T, @alignCast(@alignOf(T), memory.ptr));
}
so is the issue the T parameter?
no it shouldn't be...
btw platform_allocate_memory should probably take alignment as an argument
unless it's already guaranteed to have maximum alignment
but I have no idea what causes the error tho
unless... could you try .Playdate => &playdate_allocate_memory,?
but that shouldn't actually matter, nvm
yea assuming maximum alignment for now since i rarely use the system allocator (but of course that may change in the future)
yea same exact compile error
last thing I can think of is if it's something in the definition of toolbox but I doubt it
oooor, it could be that GlobalState is a comptime only type
that's more likely
oooh, let me check
so how would i check if GlobalState is comptime only? it'd have function pointers that haven't been converted yet?
that's one option, can I see it?
that was it! there was function field i forgot to convert
really need better error messages with this comptime function pointer feature lol
in general better errors, but good that you found it 👍