• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Aqua Costa

What to do when creation of a resource fails?

5 posts in this topic

I never had problems creating textures, buffers, render targets, etc, but I only have a simple if(FAILED(...)) to check if it was successful, if not, the game shuts down with an error message.

The thing is I'm not even sure why it would fail (apart from trying to create a resource using invalid flags in the DESC) I'm guessing it might fail if there isn't enough memory available...

How should I handle fails like this?
1

Share this post


Link to post
Share on other sites
For a texture, just return a pointer to a default texture instead.
For a render surface, keep trying in half resolution increments.
Only quit as a last resort.

Log the errors. Make sure to log if it was a file not found, invalid flag, or lack of memory.
1

Share this post


Link to post
Share on other sites
Possibly call a function that has something like this to pre-format the text for you log. Also get the error codes off of DirectX on MSDN

switch(hr)
{
...
case E_INVALIDARG:
...
case E_OUTOFMEMORY:
...
case S_OK:
...
}

Maybe use a big red X texture as default for debugging to visually see what texture is not loading.
0

Share this post


Link to post
Share on other sites
I'm not too sure that I agree with the idea of failing gracefully here. You should be budgeting your resource requirements and have a reasonable idea of what you'll need for minimal/typical/maximum content loads, so a failed-to-create scenario is most likely an indicator that something else has gone wrong. Typically you want to be aware of this as quickly as possible (can't beat a nice big dirty error message for doing that) so you can take appropriate remedial steps.

Halving the size of render targets until you get a success sounds like a good approach, but what if you need to create a vertex buffer sometime after? That's very likely going to fail as well and how do you gracefully recover from that? Worse yet, the failure diagnosis will be pointing to a problem with the vertex buffer creation, when it was really happening at the render target, so you're already at a disadvantage when it comes to determining the cause.

On the other hand there are cases that you can more gracefully recover from, e.g. by selecting a lower-precision format if the user's hardware doesn't support the high-precision one you tried with first (in the real world that would be something you'd check for before even trying to create; this is just an example for the purposes of discussion), so it's safe to say that there is no one-size-fits-all approach. You need to know the appropriate recovery procedure for each type of resource you create, and sometimes a big dirty error is the best thing to do.
2

Share this post


Link to post
Share on other sites
[quote]I'm not too sure that I agree with the idea of failing gracefully here.[/quote] 15 years ago when I was modding levels into other people's engines, I was glad that the game's texture manager would return the default white texture with a bug ugly orange D on it, instead of crashing to the desktop.

I could say to myself "oops, I forgot to pack my new curb texture", and move on with the 150 other things I needed to test out during that execution run, like triggers, item placement, etc... The alternative would be to get nothing done, and spend the afternoon digging through everything, and recompiling the level (took hours sometimes), over and over again, until I found the issue. Even if there was a log pointing it out, I'd rather not have to recompile the whole level just to fix a trivial issue. A misplaced texture was the least important thing.

If the large render target creation fails, and you create a half resolution one, you still log all the failures. A log should tell the entire story of execution from init to shutdown. When something goes wrong, it's nice to have as much info as possible!
1

Share this post


Link to post
Share on other sites
[quote name='Daaark' timestamp='1343235384' post='4962985']<snip>good stuff</snip>[/quote]

I deliberately didn't -1 you for your original because I knew you wouldn't say that without good reason. I guess we're talking about two different usage scenarios here, with different failure cases being more appropriate for each. More for the communal wisdom pot! :)
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0