Jump to content
  • Advertisement
Sign in to follow this  
Super Llama

Access Violation when releasing vertex buffer

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to dispose of a mesh class in my game engine. When I run and exit the program, I get an Access Violation. This is the deconstruction code:
if(this->myVB)
   this->myVB->Release();
if(this->myTexture)
   this->myTexture->Release();

The Vertex Buffer has been assigned data via Lock, memcpy, and Unlock. There seems to be nothing wrong with the loading, creation, or rendering process, only the deconstruction. What could be causing this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Well that did something :)

I changed it, then the error came back but this time it was for the texture. Then I did the same for the texture, and now its coming for something else. The Debugger can't find it this time though <_<

Share this post


Link to post
Share on other sites
This may be a sign that you should start using smart COM pointers. [smile]

Share this post


Link to post
Share on other sites
this is getting called multiple times i think this is your problem. from pure logic point of view this should be called only once...

maybe you call this piece of code manually and from the destructor of some class?

Share this post


Link to post
Share on other sites
Saying "deconstruction" instead of "destruction" is like saying "anti-sympathy" instead of "antipathy" (example courtesy of girlfriend :)).

This can have thousands of reasons. More sourcecode could help. Verify those:


  • The constructor that gets called should initialise everything with 0 or NULL

  • Destructors get only called once, and that implicitly for objects that run out of scope.

  • Do not call the destructor explicitly (except in the case you placement new'd memory)! (Hence, you don't have to set the members to 0 in the destructor.)

  • If you created the object with new, delete it at the end of intended lifetime and make sure the delete is called in every case, even after a throw



Example:

class Foo {
public:
Foo () { ::std::cout << "constructed" << ::std::endl; }
virtual ~Foo () { ::std::cout << "destructed" << ::std::endl; }
};

int main () {
Foo *foo = new Foo ();
...
delete foo; // never (!) do "foo->~Foo()";
}


Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
This may be a sign that you should start using smart COM pointers. [smile]


I would suggest smart pointers instead (I prefer the boost ones). COM (which is a model, not a kind of pointer; but I think you intended to say "COM-like classes" ;)) can get very ugly even in small projects of only 50 classes. "delete this" is simply not that fine, and it doesn't actually prevent bugs like this:


int foo (IFoo *foo) {
foo->AddRef();
// Forget to release.
return 0;
}






or, even worse,

int foo (IFoo *foo) {
// Forget to AddRef(). A caller higher in the call-tree will have a pointer != 0, but which is invalid.
foo->Release();
return 0;
}






Again, try real smart pointers (e.g. boost).


edit:
Quote:
Original post by wavetable
@phresnel + girlfriend: HAHAHA

What do you guess is our guess on your age now?


edit2:
Quote:
Original post by Super Llama
Lol never heard of those

I ignore the Lol. Of what exactly did you never hear?

Share this post


Link to post
Share on other sites
Well now my problem is that I can't FIND the current error. It only happens when I compile and run, but when I debug, it just hangs. Stupid debugger...

all the classes were created with their respective constructors, and are being destroyed by their destructors.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!