Variable at construction not always updating

The Partridge Family were neither partridges nor a family. Discuss.
MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Variable at construction not always updating

Post by MrGodin » January 4th, 2018, 11:03 pm

Personally I think it's a bug that has been with VS for a while now. Sometimes I can make changes in headers and every .cpp file that includes that header is recompiled as it should. After a while of using VS or for some random reason, this behavior stops and I have to choose Rebuild instead of Build.
I get that problem as well.
Curiosity killed the cat, satisfaction brought him back

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Variable at construction not always updating

Post by albinopapa » January 5th, 2018, 1:09 am

Yeah, this is the main reason I like to use the CPP files, though I have been working on my SIMD and SIMD math library all in headers and so far only had that issue once.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Variable at construction not always updating

Post by LuisR14 » January 5th, 2018, 2:17 am

That problem just has to do with the compiler seeing changes from the standpoint of the source files. If any source file that includes the header file is able to see the changes in it, then it would be recompiled properly.
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Variable at construction not always updating

Post by albinopapa » January 5th, 2018, 5:06 am

Right, that's what should happen, but it doesn't always happen that way is what we're saying.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Neithari
Posts: 7
Joined: January 3rd, 2018, 7:44 pm

Re: Variable at construction not always updating

Post by Neithari » January 5th, 2018, 11:13 pm

Florian3321 wrote:Hi there!
If I understand your problem, I think it happend due to that you only changed the values in the h file. If you then just build the project, because noting changed in the cpp file, the compiler does not make a new obj and does not link in a new exe, so the changes do not get into the game. If you rebuild, then the "new" h file gets it into the game, and the values are updated. On the one hand you can rebuild the solution or init the variable in the cpp file, not the h file. You can verify what I said if you compile your project, run it in the debugger and step into the constructor of game. If you get to the lines where the construction happens in the h file, Visual Studio tells you that the h file is different form the last build... I had the same problem and found that out, maybe it helps you:) What I do not unterstand is that it works if you build in release mode, maybe because VS rebuilds the project with optimizations?!
Thank you for that explanation. That clarified a lot. Actually it didn't work in release but did in debug. A implementation in the .cpp file worked. :-)

I did some work the last days and I am satisfied with my Invader clone. So thats my first game done :mrgreen: :mrgreen:
I realy learned a lot writing it! And I will take a leap of faith now and start a simple tower defence tomorrow. I think I will use SDL2 for that and hope that I am ready for that. If not I will do it with the ChiliFramework.
Anyway 1 done and so more to do :-) :!: :mrgreen:

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Variable at construction not always updating

Post by albinopapa » January 6th, 2018, 7:21 am

If you aren't fully commited to SDL2, I would suggest SFML. I found it easier to use and it's in C++ instead of C.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Neithari
Posts: 7
Joined: January 3rd, 2018, 7:44 pm

Re: Variable at construction not always updating

Post by Neithari » January 6th, 2018, 9:24 pm

albinopapa wrote:If you aren't fully commited to SDL2, I would suggest SFML. I found it easier to use and it's in C++ instead of C.
Most discussions I read have a general sdl2>sfml mentality. I saw a good presentation for sdl2 on YouTube and with all the good comments about it I made the decision for it. But maybe it is worth to have a look at sfml too.

After I showed my space invaders to a friend I noticed that I forgot the ufo and I found a bug. So 1 extra day working on that one and then I'll start with the new.

Neithari
Posts: 7
Joined: January 3rd, 2018, 7:44 pm

Re: Variable at construction not always updating

Post by Neithari » January 7th, 2018, 2:07 pm

So UFO is added bugs are fixed and my game is like I want it :-) So I am finished with my first game :mrgreen: :mrgreen: :mrgreen:
You can get the compiled Version here:
https://www.dropbox.com/s/auct23b0rofvo ... s.rar?dl=0
And here is my code:
https://github.com/Neithari/Space-Invaders

Florian3321
Posts: 27
Joined: February 12th, 2017, 1:50 pm

Re: Variable at construction not always updating

Post by Florian3321 » January 7th, 2018, 6:18 pm

Congratulations! Looks really cool!

Post Reply