Ok, that sucked. I got timed out while writing my reply and lost the entire
post. Lets try again.
Anyhow, got around to trying the code with the DYNAMIC enum and still had a
crash. It still looks like it is a threading issue when updating the osgText
object in a thread. I can't give all of the code but it should be easy enough
to reproduce with the following snippet of code. Please pretend I did a very
excellent job initializing everything.
Code:
class foo : public OpenThreads::Thread
{
public:
void addText(std::string text);
void run();
private:
OpenThreads::Mutex mMutex;
std::queue{osg::Geode*} mOutputHistoryQueue;
};
void foo::addText(std::string text)
{
static unsigned int horizTextOffset = 20;
static unsigned int lineSpacing = 5;
static unsigned int vertTextOffset = 20;
OpenThreads::ScopedLock<OpenThreads::Mutex>
lock(mRenderMutex);
// Get the first geode from the queue
osg::Geode* textGeode = mOutputHistoryQueue.front();
mOutputHistoryQueue.pop();
// These geodes should only have the one text entry; get it;
osgText::Text* textLine = (osgText::Text*)textGeode->getDrawable(0);
// Change the text on the entry, no need to put it back
textLine->setText(aText);
// Now, push the geode onto the end of the queue
mOutputHistoryQueue.push(textGeode);
// Loop through each geode and calculate their position on the screen
for(unsigned int index = 0;
index < mOutputHistoryQueue.size();
index ++)
{
// Get the text from the queue
textGeode = mOutputHistoryQueue.front();
textLine = (osgText::Text*)textGeode->getDrawable(0);
mOutputHistoryQueue.pop();
// calculate the position of the text
int size = mOutputHistoryQueue.size();
unsigned int yPos = (mOutputHistoryQueue.size() - index) *
(lineSpacing + textLine->getCharacterHeight()) +
vertTextOffset;
textLine->setPosition(osg::Vec3(horizTextOffset, yPos, 0));
// Push the text back onto the queue
mOutputHistoryQueue.push(textGeode);
}
}
void foo::run()
{
bool isRunning = true;
std::string text;
unsigned int counter = 0;
while(isRunning)
{
counter++;
text = *super cool algorithm to turn digits to text*
this->addText(text);
OpenThreads::ScopedLock<OpenThreads::Mutex>
lock(mRenderMutex);
mpViewer->frame();
}
}
This should print the last N frames in the bottom left corner of the screen
where N is the size of the queue. I've monitored memory usage and the
reference count for each of the osgText objects and have no memory leaks and
none of the reference counters are dropping below 1. I hacked a fix into the
code and found that it works quite well if there is a mutex locker blocking
anything that might change the text in osgText.cpp.
Just as an upfront, if this is a bug and not a horrible abuse of things on my
side then I apologize for the fact that I won't be able to find a fix for this.
All other factors aside, by the time legal clears me to submit a patch I'll
probably be staring in awe as Hell freezes over; yes, this includes my "own"
time as well which I don't seem to own anymore.[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43155#43155
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org