Re: osgText::Text heap corruption when using setText()
Hi Joshua,
> So, all user input is considered before the frame() function is called including the call to change text. I
guess this is what is confusing me; if I call setText(std::string) before I call frame() shouldn't the
osgText::Text object have all of its data primed and ready before the drawing update occurs?
Actually, it's the other way around. If you're running your viewer
multithreaded, the draw for frame n-1 might still be running when the
update for frame n starts. So you might be calling setText() right
before the frame() for frame n, but the draw for frame n-1 is still
running and so still trying to access the text object.
This is what setting the data variance to DYNAMIC prevents. Essentially,
it holds back starting the next update (actually returning from the
frame() function, indirectly) until all drawables flagged DYNAMIC have
been dispatched, which means that once you get to updating your text
object in frame n, frame n-1 will already have drawn your text, so it
won't be trying to access the same object you're updating.
That's one problem, which you can fix by updating in your frame loop or
having a mutex there, or by using an update callback as I described in
my previous message. But the fact of trying to update your text from
another thread (without any control over when that update happens) can't
ever work, and using a mutex between that and the frame loop is IMHO a
bad idea, which is why I suggesting using an intermediate data hold
between your thread and an update callback that would do the actual
updating. But that's up to you as to how you want to design your code...
Once I've given you the technical reasons for why you were getting a
crash, it's up to you to decide how to do things to avoid it.
(Continue reading)