Variable at construction not always updating
Variable at construction not always updating
Hello guys!
this is my first post here after half a year of watching chillies videos.
I made a Space Invaders clone and it's working pretty well i think. But when I added a background sprite and realigned my invader starting position I found a wired behaviour.
I do set the invader starting position inside game.h and forward it to my alien.h with a rect.
The rect however that arrives in alien is not updating every time I make adjustments to the rect in game.h or in game.cpp. I varied the generation and the point of generation of the rect various times but still the same problem. I do get it updated with a full recompile of the solution. Maybe thats how it is but I think it's more likely that I fucked up some compiler variable generating things or whatever.
Here is my Github: https://github.com/Neithari/Space-Invaders
I mostly use the dev branch but both are the same and up to date after I finish my work.
I hope you guys can help me
Thanks in advance
so far
Neithari
this is my first post here after half a year of watching chillies videos.
I made a Space Invaders clone and it's working pretty well i think. But when I added a background sprite and realigned my invader starting position I found a wired behaviour.
I do set the invader starting position inside game.h and forward it to my alien.h with a rect.
The rect however that arrives in alien is not updating every time I make adjustments to the rect in game.h or in game.cpp. I varied the generation and the point of generation of the rect various times but still the same problem. I do get it updated with a full recompile of the solution. Maybe thats how it is but I think it's more likely that I fucked up some compiler variable generating things or whatever.
Here is my Github: https://github.com/Neithari/Space-Invaders
I mostly use the dev branch but both are the same and up to date after I finish my work.
I hope you guys can help me
Thanks in advance
so far
Neithari
Re: Variable at construction not always updating
in Alien.h you have this
const Rect<float> playSpace;
This should be a reference or a pointer
const Rect<float> playSpace;
This should be a reference or a pointer
Re: Variable at construction not always updating
thats a good idea. I changed it but still the same behaviour. The variable does change only with rebuild solution and not with a normal compile.
Could it be me sending the variable before it's initialization?
Repo is updated to pointer now.
Edit: I was in release, behavior is normal in debug. So that is at least fixed, but why is it occuring?
Could it be me sending the variable before it's initialization?
Repo is updated to pointer now.
Edit: I was in release, behavior is normal in debug. So that is at least fixed, but why is it occuring?
Re: Variable at construction not always updating
Do you have DirectX SDK installed ?. I can't complie because of directx errors ->
Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'd3d10sdklayers.h': No such file or directory (compiling source file Alien.cpp) Engine c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\d3d10.h 6773
must be because of i am using Windows 10
Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'd3d10sdklayers.h': No such file or directory (compiling source file Alien.cpp) Engine c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\d3d10.h 6773
must be because of i am using Windows 10
Curiosity killed the cat, satisfaction brought him back
Re: Variable at construction not always updating
in game.cpp constructor
pAlien( new Alien( gfx, alienShotMax, alienShotChance, &alienSpace ) )
move this to the body of the constructor.
or init alienSpace before in the constructor instead of the h file.
pAlien( new Alien( gfx, alienShotMax, alienShotChance, &alienSpace ) )
move this to the body of the constructor.
or init alienSpace before in the constructor instead of the h file.
Re: Variable at construction not always updating
Sorry I haven't downloaded you game. Maybe I' not understanding your problem or something.
I don't see you ever changing alienSpace in gampe.cpp? it's also a const so you can't change it. So what do you mean it's not getting updated?
I don't see you ever changing alienSpace in gampe.cpp? it's also a const so you can't change it. So what do you mean it's not getting updated?
Re: Variable at construction not always updating
When I am in release mode and I want to make chages to the alienSpace (now called playSpace) to realigne it for example I change a value and compile it but it is not changed in the game. Only if I rebuild everything or use Debug mode. And I don't know why this is happening. I get it aligned now so I don't have to tough that variable again but I am curious why it does behave like this.Yumtard wrote:I don't see you ever changing alienSpace in gampe.cpp? it's also a const so you can't change it. So what do you mean it's not getting updated?
Not that I remember installing it or can find it right now. I am on win 10 too. Maybe because my solution is for VS 2017?MrGodin wrote:Do you have DirectX SDK installed ?. I can't complie because of directx errors ->
Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'd3d10sdklayers.h': No such file or directory (compiling source file Alien.cpp) Engine c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\d3d10.h 6773
must be because of i am using Windows 10
Edit: I checkt my VS install and the only thing I have directX related is
Graphics debugger and GPU profiler for DirectX under Games and Graphics
Found a solution in google. Do you have Windows 10 SDK installed? I have Windows 10 SDK (10.0.15063.0) for Desktop
Should I use 16299 or is that fine?
Last edited by Neithari on January 4th, 2018, 1:34 am, edited 2 times in total.
Re: Variable at construction not always updating
I tried moving it to the body before it was a pointer.Yumtard wrote:in game.cpp constructor
pAlien( new Alien( gfx, alienShotMax, alienShotChance, &alienSpace ) )
move this to the body of the constructor.
or init alienSpace before in the constructor instead of the h file.
However now everything is working as expected. I init alienSpace/playSpace before in the constructor and now everything is working fine. Maybe I had it double init once in .h and once in .cpp I am not sure.
But anyway thank you for your help
-
- Posts: 27
- Joined: February 12th, 2017, 1:50 pm
Re: Variable at construction not always updating
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?!
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?!
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Variable at construction not always updating
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.
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