Hi,
I'm following the series and coding everything at the same time I watch it. I make my own changes but the code is basically the same. In day 022 I found something that works very differently to what Casey has and I assume it is because of my HDD writing speed, but I would like to confirm it. I checked the forums but couldn't find something similar to my problem. If it exists, I must have missed at a reference would be appreciated.
What happens is that in this episode, for every frame, we use the CompareFileTime WINAPI function to check the last writing time when the dll was loaded with the actual dll last write time, so when it's different we reload the dll.
The problem is that when that happens, the game would actually not load at all. But if I stopped in the debugger, the hot reload would work. After some fiddling, I discovered if I waited around 20 frames to reload since detecting the change, the hot reloading would almost always work.
I naturally assumed that the problem would be in the CopyFile call. I checked with GetLastError and effectively the error code is 0x20 (ERROR_SHARING_VIOLATION), which means that the file is locked by another process, which I assume is the compiler outputting the library.
Now, I have 2 questions:
- Why is it that the Last Write Time changed even though the file was not freed? Not only that, but it changed a lot before the file was actually free. What file meta-data do I have to check to see if the file is actually done being written or it's just flat out polling the CopyFile call until it succeeds?
- (much less important) Why did Casey's code work? Is it because much faster HDD, probably SSD?
Thanks for reading and (hopefully) answering such an archaic answer.
Casey, if you happen to read this, I love the series and have learned a lot from it. Keep up the good work.