i'm working on game using opengl es 2.0 on android (in c++ using ndk).
i have class called "drawable" base class drawing objects using opengl. in destructor of class have clean buffers :
drawable::~drawable() { loge("release"); releasebuffers(); }
but destructor called endlessly (as in every loop of thread), messes drawing.
i'm kind of lost here , not find similar problems, welcome!
edit: loop code here : link
edit2: found 1 of evil calls:
in player class have call:
currentweapon->draw(this);
to
void weapon::draw(player* p)
if comment this, spam gone.
there few ways destructor gets called:
1) create instance of drawable
on stack, , falls out of scope. if done in tight loop, object fall out of scope , destroyed @ each iteration of loop. example:
for (size_t = 0; < 100; ++i) { drawable d; }
here, 100 instances of drawable
created , destroyed, @ beginning , end of every loop.
2) delete
dynamically-allocated drawable
:
for (size_t = 0; < 100; ++i) { drawable* d = new drawable; delete drawable; }
3) call destructor explicitly:
drawable* b = new (buffer) drawable; b->~drawable()
note #3 uses "placement new" , highly unlikely.
objects can destroyed @ suprising times when in container such vector
. consider:
vector <drawable> drawables; (size_t = 0; < 10000; ++i) { drawable d; drawables.push_back (d); }
you notice potentially many destructor calls when run code. when push_back
, copy potentially made , original (d
here) destroyed. also, when vector
reaches capacity has reallocate, results in every item being copied again, , originals destroyed.
objects can destroyed @ suprising time in face of temporaries , unexpected copies. consider:
void dosomething (drawable d) { } int main() { drawable d; (size_t = 0; < 1000; ++i) { dosomething (d); } }
this naive example because compiler elide temporaries in case. since dosomething()
takes drawable
by-value copy of original made. depending on other code, compiler might not able elide copy.
Comments
Post a Comment