Sign in to follow this  
pnt1614

Pure virtual function error as using the geometry shader

Recommended Posts

I want to render silhouettes edges using the geometry shader. First I create an index buffer (with adjacent indices) and a vertex buffer then render. For testing, the geometry shader just pass an input triangle to the pixel shader. The input triangle is at 0, 2, 4 indices.

struct VS_OUTPUT
{
   float4 posH: SV_POSITION;
};

struct GS_OUTPUT
{
   float4 posH: SV_POSITION;
};

void Silhouette_Edges_GS(triangleadj VS_OUTPUT input[6], inout TriangleStream<GS_OUTPUT> output)
{
	GSOutput v[3];
	for (uint i = 0; i < 3; i++)
	{
		v[i].posH = input[i].posH;
		output.Append(v[i]);
	}

	output.RestartStrip();
}

I got an "pure virtual function call" error message as running. Please, help me. 

Share this post


Link to post
Share on other sites

Use your debugger.

That is a C++ error and has nothing to do with your shader.

 

To elaborate a bit more, a "pure virtual function call" occurs when there's something wrong with the vtable of an object. This can happen if you have a pointer to a class with virtual functions, but that pointer doesn't actually point to an instance of that class. It can also happen when somebody accidentally stomps the pointer to the vtable. (The vtable pointer is typically the first N bytes of a class instance that has virtual functions, where "N" is usually either 4 or 8 depending on whether you're running on a 32-bit OS or a 64-bit OS). I would guess that in your case it's probably the former, not the latter. I would make sure that you're not calling a function on an uninitialized COM pointer.

Share this post


Link to post
Share on other sites

Thank Crossbones and MJP for the reply.

 

If I am using the same index buffer and vertex buffer to render without using the geometry shader, it works perfectly. The vertex shader just perform the transformation and the pixel shader outputs a color. It means that there is nothing wrong with the index buffer and the vertex buffer. So I guess that there is something wrong with the geometry shader but I do not know exactly how the geometry shader is invoked to process input vertices. Because my program has no response and it turns to black then backs to normal, sometimes I got an "pure virtual function" error message.

 

To debug the shader, I try to use a query to check the number of shader invocations as rendering a cube. the query data look like this:

 

// Using adjacent indices doubles the index buffer size so the input vertices is 72 instead of 36?

IAVertices          72

IAPrimitive         12

VSInvocations    26  // There are totally 24 vertices in the vertex buffer so why is there  26 vertex shader invocation?

GSInvocations   12  // The number of invoked geometry shader, this value sometimes is 0 and I do not know the reason

GSPrimitives      12 //  When GSInvocations = 0 the number of output primitives in the geometry shader is still 12. Why?

....

 

  

 

In C++, I am using an instance a class (Model_Loader) for loading a model and creating buffers (index buffer and vertex buffer). In the main source code I get these two buffers for binding to GPU as rendering. I am newbie at debugging C++ at low level so I do not know where to begin. It looks like this:

// Load model
class Model_Loader
{
public:
    void LoadModel(....);
    void CreateBuffers();

private:
    ID3D11Buffer* m_pVB;
    ID3D11Buffer* m_pIB;
}


// Main C++ code
Model_Loader* g_pModelLoader = new Model_Loader();

g_pModelLoader.LoadModel(...);
g_pModelLoader.CreateBuffers();

and I check the ID3D11Buffer class and see that this class have a pure virtual function. So is this the cause for the "pure virtual function" call? and how to test it?

Edited by steven166

Share this post


Link to post
Share on other sites
As mentioned above, you have some C++ code that is either corrupting memory, or is using invalid pointers, and need to use your C++ debugger to inspect the crash.
When the crash occurs, what ia the exact, full error message? What is the full call-stack? What line of code does it halt on? Are there any pointers used on that line or immediately before? What are their values?

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