OpenGL Cube Map removes Model Outline

Hello! I’m following a tutorial on rendering a cube map in OpenGL (https://learnopengl.com/Advanced-OpenGL/Cubemaps), but I’m having some trouble getting to work an outline effect from a previous tutorial (LearnOpenGL - Stencil testing). The problem is that the cube map is covering the outline completely, but not the model, and I don’t know how to make them work together.

This is the code that is running (I edited it quite a bit for brevity):

// ... Set view and projection matrices and other uniforms

// Render the cube map before everything else
glDepthMask(GL_FALSE);  // disable depth writing

cube_map_shader.bind();

cube_map.vertex_array->bind();
cube_map.texture->bind(0);
cube_map_shader.load_uniform_int1("u_skybox", 0);
glDrawArrays(GL_TRIANGLES, 0, 36);

glDepthMask(GL_TRUE);

// Now render the model with an outline
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 255);
glStencilMask(255);

basic_shader.bind();

// ... Set model matrix and textures
mesh->vertex_array->bind();  // mesh is just a container for the vertex array and the textures
glDrawElements(GL_TRIANGLES, mesh->vertex_array->element_buffer->index_count, GL_UNSIGNED_INT, 0);

glStencilFunc(GL_NOTEQUAL, 1, 255);
glStencilMask(0);
glDisable(GL_DEPTH_TEST);

outline_shader.bind();

// ... Set model matrix with larger scale
mesh->vertex_array->bind();
glDrawElements(GL_TRIANGLES, mesh->vertex_array->element_buffer->index_count, GL_UNSIGNED_INT, 0);

glStencilMask(255);
glStencilFunc(GL_ALWAYS, 1, 255);
glEnable(GL_DEPTH_TEST);

I confess that I don’t understand completely how the algorithm for the outline works (I’m sorry for this), but if someone knows this algorithm, they might know why the cube map is drawn on top of the outline. I tried drawing the cube map both before and after everything else and also used a little different technique for drawing the cube map and it’s the same, the outline is covered.

My question is:
How can I make them both the outline effect and the cube map happy together?

Thank you!

Never mind. I solved it by temporarily disabling stencil testing when rendering the skybox.
So the code then becomes this:

// ... Set view and projection matrices and other uniforms

// Render the cube map before everything else
glDepthMask(GL_FALSE);  // disable depth writing
**glDisable(GL_STENCIL_TEST);**

cube_map_shader.bind();

cube_map.vertex_array->bind();
cube_map.texture->bind(0);
cube_map_shader.load_uniform_int1("u_skybox", 0);
glDrawArrays(GL_TRIANGLES, 0, 36);

glDepthMask(GL_TRUE);
**glEnable(GL_STENCIL_TEST);**

// Now render the model with an outline
...

The only problem that still remains is that if I draw the skybox last, it still overwrites the outline. But at least it works, if I render it first.