#struggling to understand struct initialization
1 messages · Page 1 of 1 (latest)
i dont think so, I just tested it
are you sure that when this code is called, it's called at a point that everything is already init with Raylib ? because technically if I remember correctly, this isn't really on the stack, when you do a return like this, during compilation, your struct gets forwarded to where it's going to be thanks to result location semantic, at least that's my understanding so I don't even think that this is a problem of something being on the stack or not. And I remember using such init way to configure my whole windows and stuff and it worked for me, even the font part, so there must be something else. Sorry I cannot gives you a better answer 🙂 wish I could help more.
Yeah as you can read, they explain that during compilation, the result location basically forwards directly into memory so the init function is just the same (again my understanding) as doing just const gui : Gui = .{....};
thanks for the detailed explanation, really appreciate it.
I didnt know rl has to be init before loading a font from memory, seems a bit strange to me but when I do that, it works.
For my use case, I think having it in setup aligns better in this example
No worries, happy to help, The reaon rl needs to be initialized beforehand is that rl is (again my understanding could be wrong) a singleton living in the .h file, so things like font and stuff are stored in that singleton context, when you call something like rl.LoadFontFromMemory the reason you don't have to pass as an argument something like rl_instance_handle or something similar is because it's basically a global in the .h file if that make sense.