#struggling to understand struct initialization

1 messages · Page 1 of 1 (latest)

bold dragon
#

this should work, I've done that previously too, when playing with Raylib so the problem must be elsewhere in your code 🙂

fervent moss
bold dragon
#

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 = .{....};

fervent moss
bold dragon
#

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.

mossy fog
#

I dont know why, but font loading will not work until you have called open_window in raylib.

#

So I suspect the first time you call it before rl.open_window, and the second time, you called it after rl.open_window.