- finally foudn and fixed color picking crash!

This commit is contained in:
SoftCoder 2016-01-18 23:25:31 -08:00
parent ded8df97d6
commit 1f8096ff81
6 changed files with 31 additions and 16 deletions

View File

@ -15,7 +15,7 @@
#include "graphics_interface.h"
#include "config.h"
#include "platform_common.h"
#include <memory>
//#include <memory>
using namespace Shared::Graphics;
using namespace Shared::Graphics::Gl;

View File

@ -37,7 +37,7 @@
#include "ImageReaders.h"
#include "renderer.h"
#include "simple_threads.h"
#include <memory>
//#include <memory>
#include "font.h"
#include <curl/curl.h>
#include "menu_state_masterserver.h"

View File

@ -22,7 +22,7 @@
#include <errno.h>
#endif
#include "common_scoped_ptr.h"
#include <memory>
//#include <memory>
using namespace Shared::Util;
using namespace Shared::PlatformCommon;

View File

@ -316,6 +316,7 @@ private:
static vector<vector<unsigned char> > nextColorIDReuseList;
static auto_ptr<PixelBufferWrapper> pbo;
//static auto_ptr<Pixmap2D> cachedPixels;
void assign_color();

View File

@ -21,7 +21,7 @@
#include "platform_common.h"
#include "opengl.h"
#include "platform_util.h"
#include <memory>
//#include <memory>
#include <map>
#include <vector>
#include "leak_dumper.h"
@ -1806,7 +1806,7 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col
Pixmap2D *pixmapScreenShot = NULL;
if(PixelBufferWrapper::isPBOEnabled == true) {
string codeSection = "A";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
try {
// increment current index first then get the next index
// "index" is used to read pixels from a framebuffer to a PBO
@ -1814,23 +1814,24 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col
index = (index + 1) % 2;
codeSection = "B";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// Check for out of range
if(index >= (int)pboIds.size()) {
char szBuf[8096]="";
snprintf(szBuf,8096,"Error / Warning in [%s::%s] on line: %d pixel buffer out of range, index: %d size: %d, attempting to expand buffer...\n",__FILE__,__FUNCTION__,__LINE__,index, (int)pboIds.size());
//throw megaglest_runtime_error(szBuf);
SystemFlags::OutputDebug(SystemFlags::debugError,"%s",szBuf);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] szBuf: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szBuf);
codeSection = "C";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
addBuffersToPixelBuf((index - pboIds.size()) + 1);
}
// pbo index used for next frame
//int nextIndex = (index + 1) % 2;
codeSection = "D";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// read framebuffer ///////////////////////////////
// copy pixels from framebuffer to PBO
// Use offset instead of pointer.
@ -1839,7 +1840,7 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col
//glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
codeSection = "E";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@ -1852,34 +1853,36 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col
//t1.start();
codeSection = "F";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// map the PBO that contain framebuffer pixels before processing it
//glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
codeSection = "G";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
if(src) {
codeSection = "H";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
pixmapScreenShot = new Pixmap2D(w, h, colorComponents);
codeSection = "I";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
memcpy(pixmapScreenShot->getPixels(),src,pixmapScreenShot->getPixelByteCount());
codeSection = "J";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); // release pointer to the mapped buffer
//pixmapScreenShot->save("debugPBO.png");
}
codeSection = "K";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// measure the time reading framebuffer
//t1.stop();
//processTime = t1.getElapsedTimeInMilliSec();
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
catch(megaglest_runtime_error& ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] codeSection [%s] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,codeSection.c_str(),ex.what());
@ -1893,6 +1896,7 @@ Pixmap2D *PixelBufferWrapper::getPixelBufferFor(int x,int y,int w,int h, int col
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] codeSection [%s] UNKNOWN Error!",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,codeSection.c_str());
throw megaglest_runtime_error("UNKNOWN Exception caught in getPixelBufferFor codeSection: " + codeSection +"\n");
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
return pixmapScreenShot;
@ -1938,6 +1942,7 @@ unsigned int BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k;
unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1, 0 };
auto_ptr<PixelBufferWrapper> BaseColorPickEntity::pbo;
//auto_ptr<Pixmap2D> BaseColorPickEntity::cachedPixels;
map<string,bool> BaseColorPickEntity::usedColorIDList;
bool BaseColorPickEntity::trackColorUse = true;
@ -2107,6 +2112,13 @@ void BaseColorPickEntity::resetUniqueColors() {
}
void BaseColorPickEntity::init(int bufferSize) {
if(BaseColorPickEntity::pbo.get() == NULL) {
//printf("BaseColorPickEntity::init pbo == null\n");
BaseColorPickEntity::bufferSizeRequired = bufferSize;
BaseColorPickEntity::pbo.reset(new PixelBufferWrapper(2,BaseColorPickEntity::bufferSizeRequired));
}
else if(bufferSize != BaseColorPickEntity::bufferSizeRequired) {
//printf("BaseColorPickEntity::init pbo resize\n");
cleanupPBO();
BaseColorPickEntity::bufferSizeRequired = bufferSize;
BaseColorPickEntity::pbo.reset(new PixelBufferWrapper(2,BaseColorPickEntity::bufferSizeRequired));
}
@ -2170,7 +2182,9 @@ vector<int> BaseColorPickEntity::getPickedList(int x,int y,int w,int h,
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
static auto_ptr<Pixmap2D> cachedPixels;
//auto_ptr<Pixmap2D> cachedPixels;
//printf("PixelBufferWrapper::getIsPBOEnable() = %d\n",PixelBufferWrapper::getIsPBOEnable());
if(rendererModels.empty() == false) {
if(PixelBufferWrapper::getIsPBOEnable() == true) {
Pixmap2D *pixmapScreenShot = BaseColorPickEntity::pbo->getPixelBufferFor(x,y,w,h, COLOR_COMPONENTS);

View File

@ -24,7 +24,7 @@
#include <png.h>
#include <jpeglib.h>
#include <setjmp.h>
#include <memory>
//#include <memory>
#include "opengl.h"
#include "leak_dumper.h"