making the function virtual..crashes..why?

Started by
3 comments, last by circlesoft 18 years, 1 month ago
i am trying to make work on my engine to make it hybrid OGl and DirectX so..i am trying to abstract vertex buffer over both APIs i made a class called cMeshCompiler, which is a base class for cDXMeshCompiler and cGLMeshCompiler i made a pure virtual function called DestroyVertexBuffer which takes a void pointer, catsts it internally into LPDIRECT3DVERTEXBUFFER9 and releases it.. here is the function..i was still testing void ReleaseVBuffer(void* pBuffer) { LPDIRECT3DVERTEXBUFFER9 pVBuffer=(LPDIRECT3DVERTEXBUFFER9)pBuffer; pVBuffer->Release(); } this is very simple any..when i make this a virtual function... as i wanna do inside the engine.. it crashes, and its working normally while it isnt a virtual function any hints?
Advertisement
Perhaps the pointer to the virtual function table is incorrect, which could be possible if the object hasn't been constructed properly, such as if you try to allocate one with malloc. Other than that, it could be memory corruption in another part of the program. Do any other virtual functions fail? Are you able to reproduce the behaviour in a smaller program?
Hey flutey,

What crashes exactly in your program ? The call to the function, or the execution of the function itself ?
What I can see right now, is that if your pBuffer parameter is NULL, or corrupted, or of another type than LPDIRECT3DVERTEXBUFFER9, it has a good chance to crash during the execution of the program.
Regarding the virtual part of it, well, I would say that when you change the declaration of DestroyVertexBuffer or ReleaseVBuffer (or whatever name you gave it), maybe the (bad_pointer)->Release() does not crash --even though it is an error.
So your first question should be : What makes it crash ? The call or the execution ? Once you start narrowing down the problem, it becomes easier to tackle it.
Good luck.
StratBoy61
Assuming the problem is not related to uninitialized vars,
My guess, seeing your class structure:

If i remember correctly, calling virtual functions from the destructor of a base class is bad...

Just put the destroy functions in the derived class anc call them from their respective classes.
visit my website at www.kalmiya.com
Quote:Original post by Kitt3n
If i remember correctly, calling virtual functions from the destructor of a base class is bad...

Just put the destroy functions in the derived class anc call them from their respective classes.

The same thing goes for calling virtual functions from the constructor of a base class, I believe. Like you said, the easiest way to do it is to just call it from the inherited class.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement