Quick answer: The GameMaker runner asked Direct3D 11 to do something, usually create a texture, and Windows refused. The HRESULT says why: 0x8007000e is out of memory, 0x80070057 is an invalid argument such as an impossible texture size, and 0x887a0005 or 0x887a0006 mean the graphics device was removed or stopped responding. For the first two, look at surfaces, sprites added at runtime and texture pages in your game. For the last two, look at the player’s driver and GPU.
This dialog is different from GameMaker’s normal crash box. There is no object name, no event and no line of your code in it, because the failure happened inside the runner’s own graphics code. That makes it look like something you cannot fix, and for some codes that is true. For out of memory while creating a texture, the cause is usually in the project: surfaces that are created and never freed, sprites loaded from files and never deleted, or more texture pages in video memory than a weaker GPU can hold. This guide explains how to read the dialog, what each code means in a GameMaker game, how to find the leak, and what to tell a player when the problem is on their machine.
- The exact error
- How to read the dialog
- What each HRESULT means
- What leads to it
- Narrow it down
- Fix 1: create surfaces once, check them, free them
- Fix 2: delete sprites you add at runtime
- Fix 3: keep fewer and smaller texture pages in video memory
- When it is the player’s machine
- What Bugnet can and cannot report here
- Related guides
- Frequently asked questions
The exact error
The runner shows a message box with two lines. A commonly reported form is:
Win32 function failed: HRESULT: 0x8007000e
Call: GR_D3D_Device->CreateTexture2D at line 472 in file \TexturesM.cpp
The line number belongs to the runner’s source and differs between runtime versions, so reports of the same failure show 453, 465, 472 and other values. The same call with a different code:
Win32 function failed: HRESULT: 0x80070057
Call: GR_D3D_Device->CreateTexture2D at line 453 in file \TexturesM.cpp
And a failure while the game window’s swap chain is being created, typically at startup:
Win32 function failed: HRESULT: 0x887a0005
Call: pDXGIFactory->CreateSwapChain at line 464 in file \Graphics_DisplayM.cpp
Some reports show an empty Call: followed only by the line and file. The file name is still a useful hint: TexturesM.cpp is about textures and surfaces, Graphics_DisplayM.cpp is about the window and the display.
How to read the dialog
On Windows the runner draws with Direct3D 11. Each part of the message maps to something concrete:
- HRESULT is the standard Windows result code returned by the failed call. The values are documented by Microsoft and are not specific to GameMaker.
- Call is the Direct3D or DXGI function the runner was calling.
CreateTexture2Dcreates a texture in video memory. In a GameMaker game the things that need a new texture are texture pages being loaded into video memory, surfaces, and sprites added at runtime. - line and file point into the runner’s C++ source. They never refer to your GML.
Because this is not a GML runtime error, the usual tools do not apply. There is no stack of scripts and events to read, and you should not expect try / catch around a draw call to intercept it. What you can do is work out which of your game’s actions leads the runner to that call with a request the GPU cannot satisfy.
What each HRESULT means
| Code | Windows name | Meaning | Usual cause in a GameMaker game |
|---|---|---|---|
0x8007000e | E_OUTOFMEMORY | Not enough memory to complete the call | Video memory is full: leaked surfaces, runtime sprites that were never deleted, too many or too large texture pages loaded at once, one very large surface |
0x80070057 | E_INVALIDARG | An argument was not valid | A texture size the device cannot create: typically a width or height that is zero or larger than the GPU’s maximum texture dimension |
0x887a0005 | DXGI_ERROR_DEVICE_REMOVED | The video card was removed, or its driver was updated or reset | A driver crash or update while the game runs, a laptop switching between integrated and dedicated graphics, a dock or external GPU unplugged |
0x887a0006 | DXGI_ERROR_DEVICE_HUNG | The device stopped responding to the commands it was sent | On one player’s machine, a driver problem. If it happens at the same point for many players, something drawn there (a shader, a very large surface) is the trigger |
0x887a0007 | DXGI_ERROR_DEVICE_RESET | The device failed because of a badly formed command and has to be recreated | Same family as the two above. GML has no way to rebuild a lost device, so the game has to be restarted |
0x887a0020 | DXGI_ERROR_DRIVER_INTERNAL_ERROR | The driver hit an internal problem and put the device into the removed state | A driver bug. Updating or cleanly reinstalling the driver is the only fix |
0x887a0001 | DXGI_ERROR_INVALID_CALL | The call was made with invalid parameters | Reported from Graphics_DisplayM.cpp, the window and display code. Not something GML controls directly |
The split that matters is between the first two rows and the rest. 0x8007000e and 0x80070057 from CreateTexture2D are about what your game asked for. The 0x887a codes are about the state of the graphics device on that machine, and the game is mostly a bystander.
What leads to it
- Surfaces created repeatedly and never freed. A
surface_create()in a Draw or Step event with nosurface_exists()check and nosurface_free()allocates new video memory every frame. On a desktop GPU with plenty of memory this can run for minutes before failing, which is why it passes a short test. - Sprites added at runtime and never deleted.
sprite_add(),sprite_duplicate()andsprite_create_from_surface()each create a sprite with its own texture. They stay in memory until you callsprite_delete(). - Too many texture pages in video memory. Every sprite, font and tile set in a regular texture group is loaded into RAM when the game starts and moved into video memory the first time something from its page is drawn. A game with everything in the Default group and a long play session ends up with every page in video memory.
- Texture pages or surfaces that are too large. A 4096 x 4096 page takes 64 MB of video memory uncompressed, and an 8192 x 8192 page takes 256 MB. The manual’s own warning on the texture page setting is that larger pages make the game less compatible with lower-spec PCs.
- A surface size that came out wrong. A size calculated from a variable that is still zero, or one that grows with the room or a zoom level until it passes the GPU’s limit. Direct3D 11 hardware supports textures up to 16384 pixels per side, and older Direct3D 10 class hardware up to 8192.
- The device was lost. A driver crash, a driver update installed while the game was open, a switch between graphics adapters. None of this is in your project.
Narrow it down
Start with three questions for whoever saw the dialog: what the code was, whether it appeared at launch or after playing for a while, and what GPU they have. A failure at launch on one machine points at the device or the driver. A failure after twenty minutes on several machines points at a leak.
Then measure. GameMaker can tell you how many surfaces and sprites exist. Put this in a controller object’s Step event during development:
if (current_time - last_count_time > 5000)
{
last_count_time = current_time;
var _counts = debug_event("ResourceCounts", true);
show_debug_message($"surfaces: {_counts.surfaceCount} sprites: {_counts.spriteCount}");
}
Set last_count_time = 0; in the Create event. Play normally and watch the Output window. Counts that settle are fine. A count that only ever climbs is the leak, and the action that makes it climb (opening a menu, entering a room, firing a weapon) tells you which code to read.
For texture pages, call texture_debug_messages(true); once at game start. The runner then writes information about texture page use to the output as pages are loaded, so you can see how many pages a room pulls in. To know what the game is running on, log the adapter at startup:
var _info = os_get_info();
if (ds_exists(_info, ds_type_map))
{
show_debug_message("GPU: " + string(_info[? "video_adapter_description"]));
show_debug_message("Dedicated video memory: " + string(_info[? "video_adapter_dedicatedvideomemory"]));
ds_map_destroy(_info);
}
Test on the weakest machine you can find, ideally a laptop with integrated graphics. Integrated GPUs share system memory and have small budgets, so a leak that takes an hour to matter on a desktop card shows up there in minutes.
Fix 1: create surfaces once, check them, free them
// Draw event, broken: a new surface every frame
var _surf = surface_create(room_width, room_height);
surface_set_target(_surf);
draw_clear_alpha(c_black, 0);
// draw the lights here
surface_reset_target();
draw_surface(_surf, 0, 0);
Nothing frees _surf. The local variable disappears at the end of the event and the surface stays in video memory. Keep the surface in an instance variable, create it only when it does not exist, and free it when the instance goes away:
// Create event
light_surf = -1;
// Draw event
var _cam = view_camera[0];
var _w = camera_get_view_width(_cam);
var _h = camera_get_view_height(_cam);
if (!surface_exists(light_surf))
{
light_surf = surface_create(_w, _h);
}
surface_set_target(light_surf);
draw_clear_alpha(c_black, 0);
// draw the lights here
surface_reset_target();
draw_surface(light_surf, camera_get_view_x(_cam), camera_get_view_y(_cam));
// Clean Up event
if (surface_exists(light_surf))
{
surface_free(light_surf);
}
Two changes are in there besides the check. The surface is the size of the view, not the room: a surface the size of a 6000 x 4000 room is 96 MB, and one the size of a 1920 x 1080 view is about 8 MB. And the surface is freed in the Clean Up event, which runs when the instance is destroyed and when the room ends.
By default each surface also gets a depth and stencil buffer. For 2D effects that do not need one, call surface_depth_disable(true); before creating the surface to save that memory.
The surface_exists() check is required in any case. Surfaces live only in video memory and the system can discard them, for example when the game loses focus, which is the subject of How to Fix “Trying to draw non-existent surface” in GameMaker.
Where a size is calculated, clamp it before it reaches surface_create():
#macro MAX_SURFACE_SIZE 4096
function surface_create_clamped(_w, _h)
{
_w = clamp(ceil(_w), 1, MAX_SURFACE_SIZE);
_h = clamp(ceil(_h), 1, MAX_SURFACE_SIZE);
return surface_create(_w, _h);
}
That removes the zero-size and oversize requests behind 0x80070057. The manual says surface_create() returns an invalid handle when something goes wrong, so a surface_exists() test on the result is worth having, but do not rely on it to catch an out-of-memory failure: that is the situation in which the runner shows this dialog.
Fix 2: delete sprites you add at runtime
// Broken: runs every time the profile screen opens
avatar = sprite_add("avatar.png", 1, false, false, 0, 0);
Each call makes a new sprite and a new texture. The old one stays in memory with no variable pointing at it. Delete before you reassign, and delete when you are done:
// Create event
avatar = -1;
// When the profile screen opens
if (sprite_exists(avatar))
{
sprite_delete(avatar);
}
avatar = sprite_add("avatar.png", 1, false, false, 0, 0);
// Clean Up event
if (sprite_exists(avatar))
{
sprite_delete(avatar);
}
The same applies to sprite_duplicate() and sprite_create_from_surface(). A screenshot-style effect that calls sprite_create_from_surface(application_surface, ...) on every room transition leaks a full-screen texture each time. One caution from the manual: deleting a sprite in the same event that just drew it can stop it from drawing that frame, so delete in a later event. General leak hunting for surfaces and data structures is covered in How to Fix a Memory Leak from Surfaces and Data Structures in GameMaker.
Fix 3: keep fewer and smaller texture pages in video memory
Open Tools > Texture Groups. If everything is in the Default group, the game has no way to load less than everything. Create groups that match how the game is played (one for the menus, one per world or tile set, one for bosses) and assign sprites, tile sets and fonts to them. Then use the functions that manage video memory:
| Function | What it does |
|---|---|
texture_flush("tg_forest") | Removes that group’s pages from video memory. They stay in RAM and are loaded again on next use |
draw_texture_flush() | Removes all textures from video memory. Call it at the start of a room so that only pages the new room draws are loaded again |
texture_prefetch("tg_forest") | Loads a group’s pages into video memory ahead of time, to avoid a hitch on first draw |
texturegroup_load("tg_forest") and texturegroup_unload("tg_forest") | For groups whose Texture Group Type is Dynamic: load the group from disk and remove it from memory entirely. Dynamic groups are not loaded at game start |
// Room Start event of a controller in each forest room
draw_texture_flush();
texture_prefetch("tg_forest");
texture_prefetch("tg_player");
Page size is set in Game Options > Windows > Graphics. The default is 2048 x 2048 and the manual calls it the most compatible. If you raised it to 4096 or 8192 to reduce texture swaps, go back to 2048 and use the Preview button there to see how the pages are packed. Check large images afterwards: a sprite bigger than the page size is scaled down by half until it fits, so a 4000-pixel background needs to be cut into pieces before you lower the setting.
Sprites flagged Separate Texture Page each get a page of their own. A few are fine. A hundred of them is a hundred textures.
To confirm a fix for the memory codes, run the resource counter from the diagnosis section through a long session on the weakest test machine, visit every room, open and close every menu several times, and check that the counts return to where they started.
When it is the player’s machine
For the 0x887a codes, and for any failure in Graphics_DisplayM.cpp at launch, there is usually no change to make in the project. GML has no way to rebuild a lost Direct3D device, so once the dialog appears the game has to be restarted. What helps the player:
- Update the graphics driver from the GPU vendor’s site (NVIDIA, AMD or Intel), not through Device Manager. If the error began right after a driver update, a clean reinstall of the driver is the next step.
- On a laptop with two graphics adapters, open Settings > System > Display > Graphics in Windows, add the game’s executable and choose the high performance GPU. Try the other option if that one fails.
- As a test, switch off software that draws on top of the game or records it, then start the game again.
- Restart the PC after a driver or Windows update before trying again.
If one player gets 0x887a0006 at the same point in the game every time, that is worth a closer look on your side: a particular shader or a very large draw in that scene may be more than their driver handles. Background on this family of failures is in What Does “GPU has crashed or D3D device removed” Mean? (and How to Fix It).
What Bugnet can and cannot report here
Bugnet’s GameMaker SDK captures crashes through exception_unhandled_handler, which GameMaker calls for runtime exceptions in GML. This dialog is raised by the runner’s native graphics code, and nothing in the SDK hooks it, so do not count on an automatic report when a player hits it. The handler and its limits are described in GameMaker exception_unhandled_handler: Catch Crashes and Save the Error Before the Game Closes.
Two things still work. First, report the warning signs from GML while the game is alive: when your resource counter passes a threshold you never expect to reach, or a surface fails its surface_exists() test straight after creation, call bugnet_report_bug() with the numbers in the description. The SDK’s device string holds the OS version and display size, so pass the GPU name from os_get_info() yourself in the function’s metadata argument. Reports with the same title stack into one entry with an occurrence count, which shows whether one machine or many are affected. Second, for failures at launch, where the game never gets far enough to report anything, publish a known-issue entry on the project’s public tracker titled with the dialog text and containing the player steps above. People search for the exact code, and that entry is what they will find.
Related guides
- How to Fix a Memory Leak from Surfaces and Data Structures in GameMaker
- How to Fix “Trying to draw non-existent surface” in GameMaker
- How to Handle Out-of-memory errors in GameMaker
- Why Does My GameMaker Game Crash on some players’ PCs but not others?
- What Does “GPU has crashed or D3D device removed” Mean? (and How to Fix It)
Frequently asked questions
What does Win32 function failed: HRESULT mean in a GameMaker game?
The GameMaker runner called a Direct3D 11 function on Windows and the call failed. The HRESULT is the Windows result code that says why, and the Call line names the function, most often CreateTexture2D, which creates a texture in video memory.
What is HRESULT 0x8007000e in GameMaker?
It is E_OUTOFMEMORY: there was not enough memory to create the texture. In a GameMaker game the usual causes are surfaces created every frame and never freed, sprites added at runtime and never deleted, or too many large texture pages in video memory.
What is HRESULT 0x887a0005 in GameMaker?
It is DXGI_ERROR_DEVICE_REMOVED: the graphics device was removed, or its driver was updated or reset while the game was using it. It is usually a problem on that machine, and updating or cleanly reinstalling the graphics driver is the first thing to try.
Can I catch this error with try and catch or exception_unhandled_handler?
Do not rely on it. The dialog is raised by the runner's native graphics code and is not a GML runtime exception with a script and line. Prevent the cause by managing surfaces, runtime sprites and texture groups.
Why does it only happen on some players' computers?
Video memory and maximum texture size differ between GPUs. A leak or a large texture page that a desktop card absorbs for an hour can exhaust an integrated GPU in minutes. Device removed and device hung codes depend on that machine's driver.
Read the code before anything else. 0x8007000e and 0x80070057 from CreateTexture2D point at surfaces, runtime sprites and texture pages in your project. The 0x887a codes point at the graphics driver on that machine.