#Same Function don't work the same when renamed

35 messages · Page 1 of 1 (latest)

jade monolith
#

I really don't understand why DrawableHandler works but UpdatableHandler doen't. They are THE SAME CODE, but renamed. Any help? I know that the UpdatableHandler gets the classes registered with it but when it runs it, the vector is EMPTY. I CANT GET MY HEAD AROUND IT. Oh And did I say, DrawableHandler works, AND IT IS THE SAME CODE BUT RENAMED

The project uses cmake so you should beable to compile it easily
https://github.com/Revilo0509/Raylib-Game-Engine

GitHub

Contribute to Revilo0509/Raylib-Game-Engine development by creating an account on GitHub.

urban cliffBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

frigid lagoon
#

What's exactly is the issue when you DO change the name

#

Does it not compile?
Does it compile but not do the right thing?

#

Also how are you changing the name? Silly question but still worth asking

jade monolith
#
class DrawableHandler {
  private:
    std::vector<Drawable *> drawables;

  public:
    void add(Drawable *obj) { drawables.push_back(obj); }

    void run() {
        for (auto obj : drawables)
            obj->draw();
    }
};

this is how it looks, basically when i copy and change the name for "DrawableHandler" to "UpdatableHandler" and add duplicates of the supporing code, it doen't loop over the vector anymore. Everything compiles but none of the classes get updated

jade monolith
frigid lagoon
#

You say it doesn't loop over the vector. Can you confirm if the vector has any elements to loop over?

#

Could be an issue with the add method

jade monolith
#

Yea i did, i added logging to the add function and it did add. but then when i checked the size of the vector in the run function it said it was 0

frigid lagoon
#

If you, from the main function, just create the handler obj, add something to it, then check, does it result in the same issue?

#

Basically I'm asking if you can create the most minimal main function that would cause the issue

jade monolith
frigid lagoon
#

I know the issue

jade monolith
#

what, tell me please

frigid lagoon
#

At least I think I do

jade monolith
#

i have wasted enough of my day on this bs

frigid lagoon
#

Okay so I'm only 50% sure, but I suspect having a static variable in an inline function feels suspect

#

As an experiment, what happens if you move that inline function to a source file as a non inline function

#

Wait,

#

Hold on, let me ponder

jade monolith
#

WHAT IS THIS FOR LANGUAGE

#

ty btw

frigid lagoon
#

So my logic is...

#

static is used in global variables to specify that the variable is just for that translation unit.
Issue with static globals is that in header files is that including a header file in a source file just copies the contents into that source file, meaning each source file is getting its own copy of the static global.
That being said, I don't know how static local variables in inline functions work :P

#

inline functions just tells the linker "I know there are multiple definitions of this function, just pick one and discard the rest"

jade monolith
#

makes sens when you say it, i still don't have a clue about how inline, static and those keywords work/mean. I just google it and try stuff until something works.

#

But now i gotta figure out why

class FPS : public Drawable {
  public:
    void draw() override { DrawFPS(100, 10); }
};

Doesn't work 😢

frigid lagoon
#

Fun :(

#

In regards to static and inline, it's fine not knowing the specifics as understanding the behind the scenes of compilation takes time. My only suggestion is to not do anything fancy. Keep things simple :)

jade monolith
#

!solved

urban cliffBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

frigid lagoon
#

If you do want a peak behind the curtains, this I found is an interesting video, but it's also a very technical video. Took my like 5 rewatches before feeling like I understood what was being said
https://youtu.be/dOfucXtyEsU?si=QhR7o6sZf0xcIXH9

http://CppCon.org
—
Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2018
—
When you run your C++ code, have you ever considered how the linker, loader, operating system, C and C++ runtime all work so hard to get everything set up for you to start running your code in main...

â–¶ Play video