Handmade Hero»Forums»Code
4 posts
[SOLVED] Live code editing
Edited by Peter on
Casey, thanks for all your hard work. Cant believe Ive only just now found your guides. Keep up the awesome work!

Anyway, Im following along with Casey, but implementing it as a side scrolling game to kind of learn more by experimenting instead of copying everything Casey is doing. So my code base is quite different, as Im sorting different functions into different files. For someone whos never used unity builds with VS, it was quite confusing to even get started. And then throwing in dlls. Ive learned a lot about the debugger just by watching him, so thanks for that Casey.

Now, Ive got the game working as expected, however the live code editing is not working, and Im not sure how long ago it stopped working. Im not sure exactly why, obviously, and I cant seem to find a guide about what is required for it to work. Ive found a few things, like no global variables and dont edit the platform layer and such. I dont have any of those issues. Can someone post a guide or rules to make this work? Id appreciate it.

Im going to keep playing around with it myself, and if I find the reason for it breaking, Ill post back for others. Thanks!

-On a side note, Im not nearly as proficient with the debugger as Casey is, and perhaps I could find the problem if I was. Any good in depth guides for the VS debugger anywhere? What Ive found is ridiculously basic for what I want to know. Thanks!
Mārtiņš Možeiko
2383 posts / 2 projects
[SOLVED] Live code editing
Edited by Mārtiņš Možeiko on
As you said - you cannot use global variables in DLL across reloads.

You cannot use static variables in functions inside DLL.

You cannot use function pointers to functions defined in DLL. If you are doing C++ then this includes virtual functions - you cannot have them in classes defined in DLL.

Do not change memory layout of structs used in platform layer, meaning - don't add new members in middle of existing ones, don't erase existing members (unless it is last one), don't reorder members. In some cases it is OK to do that, but be careful and aware of what data is in memory.

What exactly does not work for you?
You should debugger to understand what is wrong. Put a breakpoint, write down memory addresses for variables and/or values before reload, then do the reload again, and check in debugger if everything is the same.
504 posts
[SOLVED] Live code editing
Edited by ratchetfreak on
If a struct survives a code reload (it's stored in of the persistent memory) don't change it.

The struct layout is the most restrictive of the requirement when doing live code reloading, the function pointers and globals/static locals can be worked around using a level of abstraction on them.

For example instead of globals you create a Globals *gl; global and on every entry you set that pointer to the a chunk of memory allocated for the globals and passed in from the platform layer.

Function pointers can be replaced by an index into a global function pointer array.

In both cases you can use macro magic to turn them both into using proper globals and function pointers in release mode.
4 posts
[SOLVED] Live code editing
Edited by Peter on Reason: Found the answer by searching!

So, partly from some late night stupidity, and partly from having a static variable in my jumping code, Ive found the answer. Thanks for the help!

So, what happened was when I was changing the file names, I had forgotten to update the builddll.bat I had to point at the new name. Between that and the static variable, the problem is fixed.

I appreciate the quick responses. Thanks ratchetfreak for the ideas on having globals and such. Ill take that into account if I decide to throw those in there some other time.

Thanks mmozeiko for the list. On that though, one thing I was having trouble with was when I edited the code, then tried a hot reload, the debugger no longer worked because the code had changed. But, because it never compiled correctly to begin with, I suppose the function and variable addresses would not have changed anyways. So that wouldve been a bust I guess.

But now that I got the reload to work, the debugger still stops working. Im pretty sure Casey had that fixed in one of his videos, anyone know which one to look into for that?

Know what? After a search (like maybe I shouldve done first) I found the video. #39 @ 52:38 is what...actually, mmozeiko posted. Thanks again mmozeiko!