Skip to main content
63 votes

How do C++ games handle memory allocation failure?

Same as all average programs: They don't.* For most applications there is no customer expectation that they continue working once memory runs out. All games fall under these "most applications". ...
Peter's user avatar
  • 9,945
22 votes

How do C++ games handle memory allocation failure?

Typically this kind of scenario never happens. Firstly, virtual memory on modern operating systems means that it's highly unlikely to happen in normal operation anyway; unless you have a runaway ...
Maximus Minimus's user avatar
3 votes
Accepted

C++ Wrapper class for raw pointer to an SDL_Texture

Shared pointers make sense when you have unclear ownership and unclear lifespan; otherwise they're just a dead weight you're dragging around. For most games you want to have a defined build-up and ...
Jack Aidley's user avatar
  • 2,126
2 votes

C++ exensible resource manager class with dynamic registration of factories

Some better idea based on your approach: You have template<typename T> bool addFactory( std::unique_ptr<ResourceFactory<T>> factory ) so every ...
Flamefire's user avatar
  • 216
2 votes
Accepted

How can I manage resources in memory, and dispose of them at appropriate time with the Ashley framework?

The Ashley ECS framework typically does not control the loading or management of resources as this would usually be done separately by something like an asset manager or in a bespoke loader. If ...
dfour's user avatar
  • 768
2 votes
Accepted

Unity "static" references

Although this question is fairly old, it popped up in the feed recently and I thought it might be worth un updated answer. Basically, does it make more sense to create a singleton script that holds ...
DMGregory's user avatar
  • 135k
2 votes

Implementing reference counting from scratch or using shared_ptr for resource?

There is generally nothing wrong with using shared_ptr for that purpose. You would RAII the OpenGL handle (to the shader/buffer/texture) in a typical way, and let <...
Damon's user avatar
  • 1,384
2 votes

How can I find out where a particular texture is being used in my Unity project?

If you're comfortable with using the command line, you could look through every file in the project for the texture's guid. On my Mac, I have added these functions to my ...
Ed Marty's user avatar
  • 5,229
2 votes
Accepted

TextAsset thinks file is ~6856 bytes when it is 120123 bytes

When you want Unity to load a non-text file as a text asset properly, you need to give it the file extension .bytes. Otherwise it is possible that Unity interprets ...
Philipp's user avatar
  • 120k
2 votes

How do C++ games handle memory allocation failure?

Well, mainly, the same way we did it before exceptions existed - the old "check the return value approach". If an allocator doesn't use exceptions, it will usually return ...
Luaan's user avatar
  • 890
2 votes
Accepted

What aspect of performance should I be optimizing my code towards? (asynchronous chunk modification)

As your initial question is based on just one factor - "Where does my bottleneck lie?" - only you can get at the answers, by profiling your code (now and later as features develop and bottlenecks ...
Engineer's user avatar
  • 30k
2 votes

How to update the value of all owners of shared_ptr?

Update Object in place. *cache["foo"] = Object(stuff); Or add a method that will reload the entire object. ...
ratchet freak's user avatar
2 votes

Do multiple small script files use more RAM than one bigger script file?

Scripts themselves take almost no RAM. You pretty much only have the cost of storing the CPU instructions (a few kilobytes at most, if your script is massive) and that's only once, it doesn't matter ...
Omegastick's user avatar
1 vote

Do multiple small script files use more RAM than one bigger script file?

When your game is compiled into bytecode, then all the script files disappear and are mixed into one giant mush of instructions (gross oversimplification, but it helps to get the idea). So it rarely ...
Philipp's user avatar
  • 120k
1 vote
Accepted

How to manage UI sound effects?

AUDIO MANAGER The best solution in my opinion would be to have an AudioManager in your scene. You can give it an AudioSource and and some sort of 'AudioManager' script. The script can just contain a ...
Pow's user avatar
  • 404
1 vote
Accepted

Using Game Engine (or parts of it) In Commercial Application?

The resource (or "unit") properties and behaviours you describe are not things usually provided by game engines. A game engine provides the core foundation to build a game on top of, things ...
DMGregory's user avatar
  • 135k
1 vote

What is the typical way of authoring and implementing dynamic asset loading via blocks, in Unity?

The currently (2022) recommended way of doing this would be Addressable Assets. The addressables system allows to organize assets in asset bundles by assigning them to "Groups". Asset ...
Philipp's user avatar
  • 120k
1 vote
Accepted

Reference counting with resource handles

Before answering your other questions one thing that could break your design. If you delete an asset in the middle of the vector all other asset indices will move and effectively ruin your cache ids ...
Exaila's user avatar
  • 687
1 vote

Centralized ResourceManager Class for every type of Asset in an Game Engine

You could always use a variadic template for your arguments. I wrote a similar system for fun a while back and it had something like this: ...
Mikael's user avatar
  • 444
1 vote

Do I need a rendering system in my engine?

Sprites If I decide to go with the rendering system, what would be the best way to store and send sprites? I suppose that I need to make a sprite resource manager. If so, how is the best way to ...
Theraot's user avatar
  • 27.3k
1 vote

How do C++ games handle memory allocation failure?

Catching an exception and Deciding to do what when and exception is raised are two different things. You need to have complex logic to free up memory which is not needed by your program. Worse, if ...
Daksh Gupta's user avatar
1 vote
Accepted

Should I compress the game data files?

Why don't you grab the best part of both sides and compress files to download, then extract them on installation? This way you will have less data to transfer during download (so faster download), ...
jjimenezg93's user avatar
1 vote

Unity "static" references

Keep it simple. As zcabjro said, the conventional method is to add prefab references to the scripts that need them. If you have a GameObject with a script attached called 'Boy' and he wants access to ...
DavidC's user avatar
  • 281
1 vote
Accepted

How should I manage meshes for the streets of a 3D city map in Unity?

Using many small meshes (option 1) will likely be favorable in this scenario for the following reasons: You can make heavy use of instancing. Loading the map will likely be faster since you only ...
aces's user avatar
  • 136
1 vote

Instantiating without the use of Resource Folder in Unity?

The Resources folder is only needed instead of an asset bundle, not in addition to. If something is going in an asset bundle, then you load it from the bundle and it doesn't need to be in Resources.
jhocking's user avatar
  • 15.8k

Only top scored, non community-wiki answers of a minimum length are eligible