Register
handmade.network»Forums»Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
2 posts
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago
Hey guys,

This is an awesome project that I had never heard about until recently so I started following along and seeing what I could learn from it (Which so far has been a huge amount) I'm only on day 17 of HMH and am having a peculiar issue.

When I compile, I get warning C4505 which is "unreferenced local function has been removed"
The error is in reference to the GameUpdateAndRender function. However, I have check several times that it was being called and even when stepping through the code after compilation(If I ignore the error), it shows the function being called and even stepping through the code as the program continues.

I generally would ignore it but it is causing my controller code to not work. My keyboard code works fine but the game won't accept input from the Xbox Controller I use. It did work before but it has since stopped and I have spent a good amount of time debugging it myself without any success.

If there is anything you need(code snippets, screenshots, etc) to help solve the issue let me know.

Thanks much,
NightxAngel16

PS: Each day I copy the code from the zipped archives so it is exactly what Casey has provided and that way I'm not getting drastically off track with my own code

Also sidenote: Had to change the internal(static) keyword to extern for the HANDMADE_INTERNAL debug section of the code in handmade.h
will this affect anything later on in the development process?
Mārtiņš Možeiko
1983 posts / 1 project
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago Edited by Mārtiņš Možeiko on July 14, 2016, 10:18 p.m.
Let me first say that later (~day 21) GameUpdateAndRender will be changed to extern function and will be put in separate dll. So you might want to wait until that day to see if it fixes this error.

Anyway - are you using build.bat to build? Or did you create VS solution?
I just now tried to run build.bat from day 17 with VS2015. And everything was build fine without any errors or warnings without changing anything in code. Are you sure you are not changing win32_handmade.cpp file? What do you have on line 877? It should have call to GameUpdateAndRender.

What does "controller code to not work" mean? Are you not getting Controllers[0].Buttons/StickAverageX/Y variables in game_input structure set incorrectly in win32_handmade.cpp code? Are these variables not read correctly in handmade.cpp? Use a debugger and step over both places in code - writing to buttons and stick value, and reading from it. Be specific what doesn't work.

Changing static to extern for internal shouldn't be a big deal - everything will work, but that is really very wrong solution to this problem. It is always better to understand what is happening and fix it properly. Sometimes there is a bigger problem and this kind of "fix" only hides it, and not fixes it. And later same problem will come back with much bigger issues.
2 posts
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago
I do apologize for the late response but here is an update on the situation.

The controller portion of the code was not working at all when I posted this so I went to work on some other things. Incidentally, these other things involved controllers(yay for video games, right?) and I found that My controller was not reading for any of my games either. So I rebooted which involved a nice system update(Thanks windows 10) and my computer crashed during the update with a BSOD about a driver failure. I'm not sure if it was related, I didn't really dig down into it since I plan on rebuilding my system soon anyways but magically my controller worked again(at least for video games. I didn't test on HMH until today). So today I read your response and went back to debug the sections you told me to check and the controller code worked fine. The BlueOffset was being adjust accordingly, the controllers were initialized correctly, etc. Everything was all good and dandy and the variables were set correctly.

I went ahead and turned on the 'treat warnings as errors' option and the build failed again.
I am building a VS Solution. This is what I am more familiar with and since I was using VS as my text editor it made sense for me to use it(at least in my mind).

Yes, line 877 does have a call to GameUpdateAndRender.

1
warning C4505: 'GameUpdateAndRender': unreferenced local function has been removed


I went ahead and set up the build.bat compiling setup that Casey uses and it compiles with no issues, including the static/extern type swap.
So I imagine that the way VS builds the program and links it together is what is really causing the mismatch for C4505 as well as the static(internal)/extern variable situation
Mārtiņš Možeiko
1983 posts / 1 project
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago
Can you post your vcxproj file somewhere? I cannot imagine this function being removed if it is called on line 877. There is probably something else wrong with project or source files.
Andre
15 posts
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago
Are you perhaps compiling all of the .cpp files as separate translation units? If you look at Casey's build.bat, you'll notice he only compiles win32_handmade.cpp. All the other files get pulled in with #includes. If I had to guess, I'd say that the warning you're getting about GameUpdateAndRender is from a separate compilation of handmade.cpp. In the context of that particular translation unit, GameUpdateAndRender is indeed unused code. That would also explain your issue with the code inside the #if HANDMADE_INTERNAL block. You're forward-declaring static functions that the separate compilation of handmade.cpp never sees.
Mārtiņš Možeiko
1983 posts / 1 project
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago Edited by Mārtiņš Možeiko on July 18, 2016, noon
Hmm, I think that in case both .cpp files are compiled independently then they would not link together, because GameUpdateRender is a static function. So there would be no way to step into this function using debugger.
Andre
15 posts
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago
Ah, but that's assuming OP didn't #include handmade.cpp inside win32_handmade.cpp, which coincidently is what Casey's Day 17 code does. So both translation units would get their own version of GameUpdateAndRender.

You got me curious, so I actually unzipped and compiled Day 17's code. If you just move all the typedefs and standard library includes from win32_handmade.cpp into a shared header, then win32_handmade.cpp will compile just fine while handmade.cpp will produce the errors that OP is describing. So that's gotta be it.
Mārtiņš Možeiko
1983 posts / 1 project
Visual Studio 2015 Compile Error C4505: Unreferenced local function has been removed
3 years, 4 months ago
Ah, yes. That makes sense.