I'm working on extending the bsp plugin to support the .dif (Dynamix Interior
Format) used by Torque Game Engine and its successors. I am attempting to read
the png lightmaps from the file stream, using the following code:
Code:
osg::ref_ptr<osgDB::ReaderWriter> reader =
osgDB::Registry::instance()->getReaderWriterForExtension("png");
osgDB::ReaderWriter::ReadResult rr;
mapFile->read((S8*)&j, sizeof(U32));
convertLEndianToHost(&j);
curLevel.lightmaps.reserve(j);
curLevel.lightDirMaps.reserve(j);
curLevel.lightmapKeep.reserve(j);
std::cout << "reading " << j << " lightmaps and lightDirMaps and
lightmapkeeps" << std::endl;
for(i = 0; i < curLevel.lightmaps.capacity(); i++){
rr = reader->readImage(*mapFile);
std::cout << "read lm " << i << std::endl;
if(rr.success()){
curLevel.lightmaps.push_back(rr.takeImage());
std::cout << "took lm " << i << std::endl;
} else{
std::cout << "\t- Sorry, we screwed this one up" << std::endl;
return false;
}
if(curLevel.iFV == 1 || curLevel.iFV >= 12){
rr = reader->readImage(*mapFile);
std::cout << "read lmd " << i << std::endl;
if(rr.success()){
osg::ref_ptr<osg::Image> tmp = rr.takeImage(); // Should be
autocleaned up by ref_ptr
std::cout << "took lmd " << i << std::endl;
curLevel.lightDirMaps.push_back(NULL); // Keep our place in the
stream, but don't save the result of this
std::cout << "pushed back empty" << std::endl;
} else{
std::cout << "\t- Sorry, we screwed this one up" << std::endl;
return false;
}
}
mapFile->read((S8*)&flag,sizeof(U8));
curLevel.lightmapKeep.push_back(flag);
std::cout << "took flag " << i << " : " << U32(flag) << std::endl;
}
Immediately after seeing "reading 20 lightmaps and lightDirmaps and
lightmapkeeps" in the console, the plugin throws a bus error. I know the the
png data in the stream is good, since the reference implementation from TGE
manages to read it fine, and my debugging has shown that up until this point my
plugin modifications have read the exact same information that that the
reference implementation has. By process of elimination the hiccup is happening
during the reading of the png itself, but since the reference implementation
(whose readPNG method makes use of libpng) does okay, there must be some
difference in the way the two are reading it. Am I doing something obviously
wrong here? Are there subtleties in the behavior of the png reader/writers when
reading from stream that I should be aware of? Any other comments?
Thanks,
Thomas
------------------------
Vermont Sustainable Heating Initiative (http://www.sustainableheatingvt.org) ||
Village2Village Project (http://www.village2villageproject.org)
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32601#32601
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org