• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker (SOLVED) "Trying to set texture that is also bound as depth buffer"

R

RenderedWorld

Guest
I have been using the same surface system over the past couple months. As recently as two or so days ago, my project hasn't been drawing the surface to the screen as it did before.

Here is the relevant chunk of the surface code:

Code:
if(surface_exists(global.light)) {

        surface_set_target(global.light);
        draw_clear(c_black);
        gpu_set_blendmode(bm_src_color);
        //Draws a lantern-light sprite
      
...
      
        gpu_set_blendmode(bm_normal);
      
        surface_reset_target();
        draw_surface_ext(global.light,0,0,1,1,0,c_white,global.light_lvl); // global.light_lvl sets the alpha to darken the environment
      

...
}
So now, as I'm going through trying to debug, the console has started printing this message out every step:

"Trying to set texture that is also bound as depth buffer - bailing..."

I can only assume this is associated with the surface that is supposed to be drawing. I have never seen this error before. Does anyone have a clue as to why my surface isn't drawing and if this message is connected to it? I have tried many different things to try to get it to work and I'm out of ideas.

Any insight into this problem is appreciated.
 
Last edited by a moderator:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, first thing to do is make sure that the error is indeed related to the code you posted, so I'd run the game again with that code commented out and see if you still get the error. Second thing to do is to clean the compiler cache (if you haven't already) because I've seen a similar issue related to having a stale cache (use hte "broom" button at the top of the IDE). Third, roll back the runtime to 2.1.5.246 and see if it's a bug in the latest runtime (in which case you should file a bug report and include a link to the project YYZ).

PS: Do you draw to the application surface anywhere? So like:

Code:
surface_set_target(application_surface);
// Draw stuff
surface_reset_target();
If you're doing that in a Draw Event, then you can also get this error as you can't draw to the app surface while it's drawing...
 
R

RenderedWorld

Guest
Thank you for your reply, Nocturne. I appreciate the response and suggestions.

I am not in front of my computer at the moment, but I can tell you a couple things from here.

From my memory, the printed message didn't occur when I'd commented out the surface code from the object, but just in case I will try it again once I'm able and give an update.

I haven't tried clearing the cache yet, so that will be the first thing I will try.

As far as the runtime, I will have to double check, but I might actually be behind by several versions, which is actually something I have been concerned about. I haven't seen a runtime update in Preferences in several months. I will have to get back to you about the runtime version.

And finally, regarding your PS, I do not draw the Application Surface anywhere.
 
R

RenderedWorld

Guest
I have figured out what the problem is.

I ran through your troubleshooting steps and confirmed that none of them were the problem.

I rolled the runtime back to the previous version, v2.1.5.246 (I had my runtime versions confused which is why i said I was on an old version, turns out I'm not).

The surface is now drawing correctly while on the previous runtime.

I will submit a bug report. Thanks again for your assistance, Nocturne.
 

Slyddar

Member
Old topic, but I ran into this problem recently, and found the solution, so thought it worth posting. I had declared the surface variable in the create event like this, intending to create the surface later:
Code:
surf = 0;
I had forgot to go back and change it correctly, so it generated the error "Trying to set texture that is also bound as depth buffer", as above. Changing the declaration as below solved it:
Code:
surf = surface_create(room_width, room_height);
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
In this case, your error is caused by setting the surf variable to 0. This will probably refer to the application_surface and so give errors... you should always set uninitialised surface vars to -1, not 0, to avoid such issues.
 
  • Like
Reactions: Flo

Slyddar

Member
Yeh I should of just set it to -1 as per the manual. Google led me here, so it was more just letting others know what caused the error, as the solution above to rollback to a previous runtime/clean cache were not actually the answers.

Thanks for clarifying though.
 

NastyMonk

Member
Okay, first thing to do is make sure that the error is indeed related to the code you posted, so I'd run the game again with that code commented out and see if you still get the error. Second thing to do is to clean the compiler cache (if you haven't already) because I've seen a similar issue related to having a stale cache (use hte "broom" button at the top of the IDE). Third, roll back the runtime to 2.1.5.246 and see if it's a bug in the latest runtime (in which case you should file a bug report and include a link to the project YYZ).

PS: Do you draw to the application surface anywhere? So like:

Code:
surface_set_target(application_surface);
// Draw stuff
surface_reset_target();
If you're doing that in a Draw Event, then you can also get this error as you can't draw to the app surface while it's drawing...
I've also run into this error today.

Here is my code in the draw end event:
GML:
/// @description Insert description here
// You can write your code in this editor
if (paused) {
    // code here
    if (!surface_exists(pause_surf)) {
        // code here
        // State switch from running to pause
        instance_deactivate_all(true);
        pause_surf=surface_create(camera_get_view_width(view_camera[0]),camera_get_view_height(view_camera[0]));
        view_surface_id[0]=pause_surf;

        
    }
    
    surface_set_target(pause_surf);
    draw_clear_alpha(c_black,0.5);
    surface_reset_target();
    
    draw_surface(pause_surf,camera_get_view_x(view_camera[0]),camera_get_view_y(view_camera[0]));
    
    draw_set_color(c_white);
    draw_set_font(fnt_Game);
    draw_set_halign(fa_middle);
    draw_set_valign(fa_center);
    draw_text_transformed(camera_get_view_x(view_camera[0])+camera_get_view_width(view_camera[0])/2,camera_get_view_y(view_camera[0])+camera_get_view_height(view_camera[0])/2,"Pause",0.5,0.5,0);
    
    
        
}
What is does is that it draws the view assigned to the viewport 0 to a surface and then draws this surface to the application surface to create a pause screen that has all the instance sprite on it. I put it in the draw end event so that when I deactivate all the instances I can be sure that they are already on the application surface.

Frankly, I don't know how view_surface_id works under the hood. If I assign it to a surface in the Draw End event, will it draw what's on the view one in the current event loop to the surface or will it start to draw what's on the view one from the next event loop?

If I comment out this line:
Code:
view_surface_id[0]=pause_surf;
The error will go away and it won't give me the result I want.

Also can you explain about what you mean by this "If you're doing that in a Draw Event, then you can also get this error as you can't draw to the app surface while it's drawing... "

Do you mean you can't draw to the app surface when it is being drawn to or what? I'm a bit confused.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
When you enter the draw event, basically surface data is "fixed" by that point, so it will be the next step that is required before something would be drawn. For the app surface, this means that after the PRE draw event, but before the draw BEGIN event, it is set as the main draw target, so until you get to POST draw event, you can't target it to draw on using surface_set_target(). See the Draw Order here in the manual: https://docs2.yoyogames.com/index.h...2_interface/1_editors/events/draw_events.html

As for your code, I think a simple "else" in there should prevent errors... eg:


GML:
if (paused) {
    // code here
    if (!surface_exists(pause_surf)) {
        // code here       
        }
    else {
        surface_set_target(pause_surf);
        draw_clear_alpha(c_black,0.5);
        surface_reset_target();
       //etc...
        }
    }
 

NastyMonk

Member
When you enter the draw event, basically surface data is "fixed" by that point, so it will be the next step that is required before something would be drawn. For the app surface, this means that after the PRE draw event, but before the draw BEGIN event, it is set as the main draw target, so until you get to POST draw event, you can't target it to draw on using surface_set_target(). See the Draw Order here in the manual: https://docs2.yoyogames.com/index.html?page=source/_build/2_interface/1_editors/events/draw_events.html

As for your code, I think a simple "else" in there should prevent errors... eg:


GML:
if (paused) {
    // code here
    if (!surface_exists(pause_surf)) {
        // code here     
        }
    else {
        surface_set_target(pause_surf);
        draw_clear_alpha(c_black,0.5);
        surface_reset_target();
       //etc...
        }
    }
Thank you. After lots of research and trial and error, I found that the problem lies in how view_surface_id works. After you assign an surface to one of the view_surface_id, it actually will not set the surface as the render target and draws to it in the current event loop. Instead, it will start from the next loop. In my case,this will cause two pause_surf in the render target stack. And When I pop out one, I thought I would be drawing to the application surface at that time. However, I was still drawing to the pause_surf itself, which causes the situation that I am drawing pause_surf to pause_surf. I think the error means this.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
@Flamaxius952 : Please make your own topic, and don't bump other peoples. Outline clearly what the issue is and give as much information as possible about the events involved, the objects being used and the error you are getting. Thanks!
 
I mean, I posted this here because I was having the same issue, but I'll repost it under another topic that I created
 
Last edited:

Welvex

Member
Thank you. After lots of research and trial and error, I found that the problem lies in how view_surface_id works. After you assign an surface to one of the view_surface_id, it actually will not set the surface as the render target and draws to it in the current event loop. Instead, it will start from the next loop. In my case,this will cause two pause_surf in the render target stack. And When I pop out one, I thought I would be drawing to the application surface at that time. However, I was still drawing to the pause_surf itself, which causes the situation that I am drawing pause_surf to pause_surf. I think the error means this.
omg i had the same problem and i left it in the background as it sometimes worked for me, however now i realize that my current problem has everything to do with that, it turns out that putting it twice in one of those times doesn't there are textures and the super random sprites are seen, but the background is cut off, as if there were a second layer underneath with what I just want to accommodate, but it only lets me edit the layer in front, that is, the one that does not have textures, no I had understood it until I read your comment, how can I solve it?
 
Top