At the very end, while running around in the game world, the demonstrator changes some of the source code in Visual Studio. While he continues to run around the code is recompiled, and suddenly the changes take effect in the game world - without even restarting the simulation.

This struck me as pretty amazing (more so than the fancy graphics ) and I have no idea how they do it. Somehow they are able to replace running binary code in-memory, without the machine exploding. If anyone is interested, it starts around 9:45.

It's far beyond me to try and make anything like this but I'm fascinated - does anyone have an inkling how it works?

If you pull the rug from under a DLL like that surely you'll invalidate any pointers to objects within it, the state of those objects, etc. They must have designed the DLL very carefully, and/or serialise all the objects to another part of memory and then deserialise them back to the new library when it's loaded. It sounds terribly complicated to me.

N.B. visual studio has contained an "edit and continue" mode built into it for a long time. Edit your project properties to include "edit and continue" debugging information (on top of the regular debug info), and when you hit a breakpoint in the debugger, you can make some changes and press continue.

If you pull the rug from under a DLL like that surely you'll invalidate any pointers to objects within it, the state of those objects, etc.

Most objects aren't allocated "in a DLL", they're allocated within the address space of your program.As long as you don't change the layout of those object's classes when reloading the code, they'll continue to be valid.

If you pare back all the abstractions, all our game code is, is a bunch of data-structure definitions, and procedures that can transform those data-structures. There's no reason why you shouldn't be able to make your transforms re-loadable (and it's a huge productivity boost if you do so!).

Making run-time changes to your structures is more complicated, and VS "edit and continue" simply doesn't support this. Radikalizm's awesome link seems to serialize objects who's structures have changed, so they can be re-created after re-loading the code. I'm definitely going to have a good look at how that project works!

I stumbled upon this blog a while back which might be of interest: http://runtimecompil...us.blogspot.be/They even mention the similarities between their technique and the technique used by UE4

Amazing!

...

Helpful explanation, thanks.

That library does look identical to Epic's implementation - they might be one and the same. I've just given their test code a run through and it works as advertised, I'll definitely be having a closer look into how exactly they're doing it. They've even geared the sample code up for integrating into an existing project.

Making run-time changes to your structures is more complicated, and VS "edit and continue" simply doesn't support this. Radikalizm's awesome link seems to serialize objects who's structures have changed, so they can be re-created after re-loading the code. I'm definitely going to have a good look at how that project works!

When I first read about their technique I was quite skeptical about it and I assumed they weren't telling the entire truth, but right now this seems to be the real deal.By design the technique itself is quite elegant too, and I can see a massive productivity boost in a lot of programming fields once this gets more widespread

I still have to make some time to play with their demo code myself though, but if this works without any major issues I'll probably be integrating this into my own development code - if possible.

We don't know if the Unreal implementation is related to ours - it's possible that after our presentation in 2011 at the AI GameDev conference in Paris they found out about it but it's also possible they came up with a similar solution themselves.

On the subject of modules and memory, you do need to ensure you either have virtual destructors or something similar as objects are allocated on each modules heap.

We don't know if the Unreal implementation is related to ours - it's possible that after our presentation in 2011 at the AI GameDev conference in Paris they found out about it but it's also possible they came up with a similar solution themselves.

On the subject of modules and memory, you do need to ensure you either have virtual destructors or something similar as objects are allocated on each modules heap.

Ahh perfect, now I can say this in person: Awesome work!

If I can get this to work nicely with my development code you might have saved me quite some production time Needless to say I'll be following your project closely

N.B. Not trying to put a damper on these awesome ideas here, just pointing out some pitfalls to be aware of:Two issues with supporting changes to data-structures (which implies serialization/deserializaiton) is that many game engines are (1) very specific about how their utilize their RAM, and (2) also very limited in the amount of RAM they can use.

(2) isn't an issue on PCs, and console dev-kits usually have double the retail-version's amount of RAM, so it's likely only a minor problem affecting some of your SKUs.

(1) complicates matters though. Even with a general-purpose allocator, when freeing 10,000 objects and then allocating 10,000 slightly larger objects, it's possible that the original allocations aren't contiguous (so they become little bubbles in your address space), and the new allocations are too big to fit in those "bubbles". This fragmentation of RAM can have the same effect as if you'd simply leaked the original allocations (until you free the used-space around them, probably at the end of the level), which can make it much more likely to hit the RAM limits from (2).

Further, optimised engines don't use global, general-purpose global allocators (i.e. new/malloc) for everything. To construct a certain kind of object, you might need to specify which allocation area to construct it in, and you might not be able to free that allocation at a random time (e.g. perhaps bulk-deallocation of the whole area is used).

For example, when allocating an object in our renderer, depending on which systems are likely to access it and it's required lifetime, the user will specify 1 allocator out of a possible 4 different stacks and 4 different heaps that could be used. i.e. the same object could be constructed within 8 different areas of RAM, but choosing the right one is important based on usage.If the object is allocated in one of the stack areas, it's can't be freed at will; it's lifetime is bound to the lifetime of the stack. Reallocating with a larger size means 'leaking' the original and adding a new object on the top of the stack (which there might not be space for). Alternatively, it means serializing the entire stack and re-allocating the whole thing from the bottom-up to avoid these holes (and then patching any other objects that held pointers into this stack).

These aren't un-solvable problems, but a class-layout-patching solution that's applicable for every engine would have to be very flexible in regards to allocations, and may end up having to serialize/deserialze hundreds of megs of data per 'reload'.

That said, gameplay code is usually less performance-critical than engine code, so maybe you just don't support this feature on your critical engine systems ;)

You hit the nail right on the head, this is exactly the thing I wanted to experiment with as I too am using specialized allocation schemes in my engine code which may not work too well with this system, and I really don't want to give them up to implement this feature.I can see the destroying and reallocating resources in memory becoming a problem since I mostly use a contiguous allocation scheme so I can easily group resources of one type into one contiguous chunk of memory (no fragmentation + data-oriented design = happy cache + happy programmer). Cleanup is done in chunks too as it pretty much comes down to rolling back to a base point in memory and calling the appropriate destructors in order, so selective destruction of data is not really recommended - I'm not sure whether this will actually pose a problem, but it's definitely something I need to keep in mind

I would be interested to see this run on consoles, I can imagine it being a major productivity boost if developers can make on-the-fly changes to code running on a console.

I would be interested to see this run on consoles, I can imagine it being a major productivity boost if developers can make on-the-fly changes to code running on a console.

Lots of companies do this already, but only for procedures, not class-layouts. The PS3 encourages a "job based" programming model, where your procedures are more separate from your data-layouts than in traditional OOP, so it's not too hard to shoe-horn in code-reloading to systems written this way.Reloading a DLL (equivalent) and changing some function-pointers is simple. It's only the reloading of class-layouts (and the implied serialization/deserialization/pointer-patching) that complicates matters.

As far as I'm concerned, every engine should already be doing this for their (HLSL or equivalent) shader code and any "script" code (e.g. Lua) too ;)

I would be interested to see this run on consoles, I can imagine it being a major productivity boost if developers can make on-the-fly changes to code running on a console.

Lots of companies do this already, but only for procedures, not class-layouts. The PS3 encourages a "job based" programming model, where your procedures are more separate from your data-layouts than in traditional OOP, so it's not too hard to shoe-horn in code-reloading to systems written this way.Reloading a DLL (equivalent) and changing some function-pointers is simple. It's only the reloading of class-layouts (and the implied serialization/deserialization/pointer-patching) that complicates matters.

As far as I'm concerned, every engine should already be doing this for their (HLSL or equivalent) shader code and any "script" code (e.g. Lua) too ;)

I see, interesting. I don't have any experience whatsoever with console development, unless you count XNA + X360 development as console experience, so this is new to me Sadly console development is one of those things you can't experiment with on your own...

As for shader and script code my system does in fact allow for runtime editing and recompilation in development builds, just like it allows for on-the-fly editing and reloading of any other type of resource, and you're absolutely right about it being a crucial technique if you ever want to get anything major done.

I would be interested to see this run on consoles, I can imagine it being a major productivity boost if developers can make on-the-fly changes to code running on a console.

Lots of companies do this already, but only for procedures, not class-layouts. The PS3 encourages a "job based" programming model, where your procedures are more separate from your data-layouts than in traditional OOP, so it's not too hard to shoe-horn in code-reloading to systems written this way.Reloading a DLL (equivalent) and changing some function-pointers is simple. It's only the reloading of class-layouts (and the implied serialization/deserialization/pointer-patching) that complicates matters.

As far as I'm concerned, every engine should already be doing this for their (HLSL or equivalent) shader code and any "script" code (e.g. Lua) too ;)

I see, interesting. I don't have any experience whatsoever with console development, unless you count XNA + X360 development as console experience, so this is new to me Sadly console development is one of those things you can't experiment with on your own...

As for shader and script code my system does in fact allow for runtime editing and recompilation in development builds, just like it allows for on-the-fly editing and reloading of any other type of resource, and you're absolutely right about it being a crucial technique if you ever want to get anything major done.

I have not really used XNA for 360 but I think there will be a few features the runtime might not expose to keep the writing of game code simple. I am thinking of manually setting which tiles to clear on the backbuffer and setting up tiled based rendering in particular, but I don't know this for sure to be honest.

I think this feature has nothing to do with visual studio. VS is only here bound to their system to allow for nice editor features. but compilation/link/relaunch is handled by them.
Surely, it cannot work for everything, you cannot modify core code, it must be within precise "plugin" architecture, and surely, like android, there must be a lot of constraints. You mentioned before something about serialization, this is exactly what android requires of all application because they can be killed at any time.
it is easier to rebuild a game logic that says "when space hit then jump" which requires no data, than rebuild the code of the deferred pipeline because it would require rebinding all uniforms, rebuild all render targets etc etc.
But of course, it is still amazing.

I think this feature has nothing to do with visual studio. VS is only here bound to their system to allow for nice editor features. but compilation/link/relaunch is handled by them.Surely, it cannot work for everything, you cannot modify core code, it must be within precise "plugin" architecture, and surely, like android, there must be a lot of constraints. You mentioned before something about serialization, this is exactly what android requires of all application because they can be killed at any time.it is easier to rebuild a game logic that says "when space hit then jump" which requires no data, than rebuild the code of the deferred pipeline because it would require rebinding all uniforms, rebuild all render targets etc etc.But of course, it is still amazing.

You might want to read the slides of their presentation (it's posted at the link I provided), it'll clear some things up about the inner workings ;)

Some great commentary and questions here, here's some responses which I hope clarify things:

@Lightness1024 and Radikalizm:

We're using Visual Studio as our compiler, since that's the most common compiler used for games, and there's a freely available Express version which we also support. Other compilers and OSes could be supported but would require a little extra work. We don't use any specific features of VS for the base implementation, though the pragma comment library feature is an easy way to get libraries added - but we intend to supply a cross platform version eventually. In particular I'll likely port to Mac OS X and Linux at some point, though that may not be for a few months due to other work.

@Hodgman

Myself and the other authors are all professional game developers with console experience, and a similar implementation at Crytek is working on the XBox 360 (see our develop conference slides linked from the blog). Memory is certainly an issue for console development in general and this technique would add some overhead, though there are development consoles with more memory to aid with this.

Many changes could be done with in-place serialization or even serialize to disk/network etc. and back so as to be able to free up memory prior to recreating the objects and thus also handle fragmentation issues. Additionally, though in principal all data types could be runtime changed (for example I've used the technique for graphics coding), most of the larger asset types are likely to have a very stable memory format and so not need runtime serialization.

We may make a client/server style runtime compiler for systems like iOS, Android and consoles at some point, but we'd not be able to open source the console work due to licensing conditions.

Hope this helps, I'll try and monitor this thread and try to answer questions that come up.

thanks for replies.
but all that seems to me a little scary. trying to maintain heap while rebuilding code in a non-managed/non-interpreted language :s
what happens if a plugin creates a bunch of instances of structure S and we change the content of structure S to a new layout of data we will name S2, then after rebuild, if the runtime tries to access those old instances the code will think to see S2 structures but actually those are S structures in memory. This will corrupt the content and crash if it involves pointers.
how would that be handled ?

It's actually a lot easier than you'd think to use, and we have an error handling mechanism to enable you to correct these problems and keep working. Even if the game crashes in a completely fatal way, you're no worse off than if you'd made an error in your code, compiled and ran it as normal. If data gets corrupted, you could re-load a save point (currently our demo doesn't create save points when loading new code, but it would be trivial to add).

Best way to find out if it works for you is to give the demo a try.

Note that our primary target is programmers - who are used to dealing with bugs and crashes and the state they create is code which doesn't get lost when the program crashes. If you want to use this for designers (and we believe it can be, see latest post on the console for one example), further error protection methods such as the above mentioned save points should be used.