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

NastyMonk

Member
I keep getting this error. I'm trying to create a pause screen that captured the previous frame of the game and use it as an overlay for the pause screen. Here is my code:

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]));
 }
  
    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);
  
  
      
}
if I comment out
GML:
  view_surface_id[0]=pause_surf;
The error will be gone but I don't understand why this causes the error.
What exactly does "Trying to set texture that is also bound as depth buffer - bailing..." mean? I know what depth buffer is and also the texture. But I can't make sense of this error.
 

NastyMonk

Member
After lots of trial and error and reading, I figured out the problem. The problem is related to how view_surface_id works and the render target stack. In my case, when I assign a surface to view_surface_id, it doesn't set the surface as the render target and draw to it until the next event loop. So coupled with how render target stack works, I ended up pushing two pause_surf into the stack and only popping out one. So when I thought I was drawing pause_surf to the application surface I was still drawing pause_surf to pause_surf, which gives me the error. Feel free to ask me if you run into the same issue.
 
Top