int main( int argc, char **argv ) { Debug(debug::init()); Debug(libcw_do.on()); LLMemType mt1(LLMemType::MTYPE_STARTUP); #if LL_SOLARIS && defined(__sparc) asm ("ta\t6"); // NOTE: Make sure memory alignment is enforced on SPARC #endif gArgC = argc; gArgV = argv; LLAppViewer* viewer_app_ptr = new LLAppViewerLinux(); // install unexpected exception handler gOldTerminateHandler = std::set_terminate(exceptionTerminateHandler); // install crash handlers viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); viewer_app_ptr->setSyncErrorHandler(LLAppViewer::handleSyncViewerCrash); bool ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // viewer_app_ptr->cleanup(); } delete viewer_app_ptr; viewer_app_ptr = NULL; return 0; }
int main( int argc, char **argv ) { LLMemType mt1(LLMemType::MTYPE_STARTUP); #if LL_SOLARIS && defined(__sparc) asm ("ta\t6"); // NOTE: Make sure memory alignment is enforced on SPARC #endif // Set the working dir to <bundle>/Contents/Resources (void) chdir(gDirUtilp->getAppRODataDir().c_str()); LLAppViewerMacOSX* viewer_app_ptr = new LLAppViewerMacOSX(); viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); bool ok = viewer_app_ptr->tempStoreCommandOptions(argc, argv); if(!ok) { llwarns << "Unable to parse command line." << llendl; return -1; } ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // viewer_app_ptr->cleanup(); } delete viewer_app_ptr; viewer_app_ptr = NULL; return 0; }
// Reverses the order of the rows in the image void LLImageRaw::verticalFlip() { LLMemType mt1(mMemType); S32 row_bytes = getWidth() * getComponents(); llassert(row_bytes > 0); std::vector<U8> line_buffer(row_bytes); S32 mid_row = getHeight() / 2; for( S32 row = 0; row < mid_row; row++ ) { U8* row_a_data = getData() + row * row_bytes; U8* row_b_data = getData() + (getHeight() - 1 - row) * row_bytes; memcpy( &line_buffer[0], row_a_data, row_bytes ); memcpy( row_a_data, row_b_data, row_bytes ); memcpy( row_b_data, &line_buffer[0], row_bytes ); } }
//scale down image by not blending a pixel with its neighbors. BOOL LLImageRaw::scaleDownWithoutBlending( S32 new_width, S32 new_height) { LLMemType mt1(mMemType); S8 c = getComponents() ; llassert((1 == c) || (3 == c) || (4 == c) ); S32 old_width = getWidth(); S32 old_height = getHeight(); S32 new_data_size = old_width * new_height * c ; llassert_always(new_data_size > 0); F32 ratio_x = (F32)old_width / new_width ; F32 ratio_y = (F32)old_height / new_height ; if( ratio_x < 1.0f || ratio_y < 1.0f ) { return TRUE; // Nothing to do. } ratio_x -= 1.0f ; ratio_y -= 1.0f ; U8* new_data = allocateMemory(new_data_size) ; llassert_always(new_data != NULL) ; U8* old_data = getData() ; S32 i, j, k, s, t; for(i = 0, s = 0, t = 0 ; i < new_height ; i++) { for(j = 0 ; j < new_width ; j++) { for(k = 0 ; k < c ; k++) { new_data[s++] = old_data[t++] ; } t += (S32)(ratio_x * c + 0.1f) ; } t += (S32)(ratio_y * old_width * c + 0.1f) ; } setDataAndSize(new_data, new_width, new_height, c) ; return TRUE ; }
// virtual U8* LLImageBase::allocateData(S32 size) { LLMemType mt1(mMemType); if (size < 0) { size = mWidth * mHeight * mComponents; if (size <= 0) { llerrs << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,(S32)mComponents) << llendl; } } //make this function thread-safe. static const U32 MAX_BUFFER_SIZE = 4096 * 4096 * 16 ; //256 MB if (size < 1 || size > MAX_BUFFER_SIZE) { llinfos << "width: " << mWidth << " height: " << mHeight << " components: " << mComponents << llendl ; if(mAllowOverSize) { llinfos << "Oversize: " << size << llendl ; } else { llerrs << "LLImageBase::allocateData: bad size: " << size << llendl; } } if (!mData || size != mDataSize) { deleteData(); // virtual mBadBufferAllocation = false ; mData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!mData) { llwarns << "Failed to allocate image data size [" << size << "]" << llendl; size = 0 ; mWidth = mHeight = 0 ; mBadBufferAllocation = true ; } mDataSize = size; } return mData; }
// virtual U8* LLImageBase::reallocateData(S32 size) { LLMemType mt1(mMemType); U8 *new_datap = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!new_datap) { llwarns << "Out of memory in LLImageBase::reallocateData" << llendl; return 0; } if (mData) { S32 bytes = llmin(mDataSize, size); memcpy(new_datap, mData, bytes); /* Flawfinder: ignore */ FREE_MEM(sPrivatePoolp, mData) ; } mData = new_datap; mDataSize = size; return mData; }
// virtual U8* LLImageBase::reallocateData(S32 size) { LLMemType mt1((LLMemType::EMemType)mMemType); U8 *new_datap = new U8[size]; if (!new_datap) { llwarns << "Out of memory in LLImageBase::reallocateData" << llendl; return 0; } if (mData) { S32 bytes = llmin(mDataSize, size); memcpy(new_datap, mData, bytes); /* Flawfinder: ignore */ delete[] mData; } mData = new_datap; mDataSize = size; return mData; }
U8 * LLImageRaw::getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const { LLMemType mt1((LLMemType::EMemType)mMemType); U8 *data = new U8[width*height*getComponents()]; // Should do some simple bounds checking if (!data) { llerrs << "Out of memory in LLImageRaw::getSubImage" << llendl; return NULL; } U32 i; for (i = y_pos; i < y_pos+height; i++) { memcpy(data + i*width*getComponents(), /* Flawfinder: ignore */ getData() + ((y_pos + i)*getWidth() + x_pos)*getComponents(), getComponents()*width); } return data; }
U16 LLFace::getGeometryAvatar( LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, LLStrider<LLVector2> &tex_coords, LLStrider<F32> &vertex_weights, LLStrider<LLVector4> &clothing_weights) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); if (mVertexBuffer.notNull()) { mVertexBuffer->getVertexStrider (vertices, mGeomIndex); mVertexBuffer->getNormalStrider (normals, mGeomIndex); mVertexBuffer->getTexCoord0Strider (tex_coords, mGeomIndex); mVertexBuffer->getWeightStrider(vertex_weights, mGeomIndex); mVertexBuffer->getClothWeightStrider(clothing_weights, mGeomIndex); } return mGeomIndex; }
// Reverses the order of the rows in the image void LLImageRaw::verticalFlip() { LLMemType mt1((LLMemType::EMemType)mMemType); S32 row_bytes = getWidth() * getComponents(); U8* line_buffer = new U8[row_bytes]; if (!line_buffer ) { llerrs << "Out of memory in LLImageRaw::verticalFlip()" << llendl; return; } S32 mid_row = getHeight() / 2; for( S32 row = 0; row < mid_row; row++ ) { U8* row_a_data = getData() + row * row_bytes; U8* row_b_data = getData() + (getHeight() - 1 - row) * row_bytes; memcpy( line_buffer, row_a_data, row_bytes ); /* Flawfinder: ignore */ memcpy( row_a_data, row_b_data, row_bytes ); /* Flawfinder: ignore */ memcpy( row_b_data, line_buffer, row_bytes ); /* Flawfinder: ignore */ } delete[] line_buffer; }
U16 LLFace::getGeometry(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, LLStrider<LLVector2> &tex_coords, LLStrider<U16> &indicesp) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); if (mVertexBuffer.notNull()) { mVertexBuffer->getVertexStrider(vertices, mGeomIndex); if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL)) { mVertexBuffer->getNormalStrider(normals, mGeomIndex); } if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD0)) { mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex); } mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex); } return mGeomIndex; }
// virtual U8* LLImageBase::allocateData(S32 size) { LLMemType mt1((LLMemType::EMemType)mMemType); if (size < 0) { size = mWidth * mHeight * mComponents; if (size <= 0) { llerrs << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,mComponents) << llendl; } } else if (size <= 0 || (size > 4096*4096*16 && sSizeOverride == FALSE)) { llerrs << "LLImageBase::allocateData: bad size: " << size << llendl; } if (!mData || size != mDataSize) { deleteData(); // virtual mBadBufferAllocation = FALSE ; U8 *data = (U8 *)realloc(mData,sizeof(U8)*size);//new U8[size]; if (!data) { if(mData) free(mData); llwarns << "allocate image data: " << size << llendl; size = 0 ; mWidth = mHeight = 0 ; mBadBufferAllocation = TRUE ; } mData = data; mDataSize = size; } return mData; }
// Src and dst can be any size. Src and dst have same number of components. void LLImageRaw::copyScaled( LLImageRaw* src ) { LLMemType mt1(mMemType); LLImageRaw* dst = this; // Just for clarity. llassert_always( (1 == src->getComponents()) || (3 == src->getComponents()) || (4 == src->getComponents()) ); llassert_always( src->getComponents() == dst->getComponents() ); if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) ) { memcpy( dst->getData(), src->getData(), getWidth() * getHeight() * getComponents() ); /* Flawfinder: ignore */ return; } // Vertical S32 temp_data_size = src->getWidth() * dst->getHeight() * getComponents(); llassert_always(temp_data_size > 0); U8* temp_buffer = new (std::nothrow) U8[ temp_data_size ]; if (!temp_buffer ) { llerrs << "Out of memory in LLImageRaw::copyScaled()" << llendl; return; } for( S32 col = 0; col < src->getWidth(); col++ ) { copyLineScaled( src->getData() + (getComponents() * col), temp_buffer + (getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() ); } // Horizontal for( S32 row = 0; row < dst->getHeight(); row++ ) { copyLineScaled( temp_buffer + (getComponents() * src->getWidth() * row), dst->getData() + (getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth(), 1, 1 ); } // Clean up delete[] temp_buffer; }
BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data ) { LLMemType mt1((LLMemType::EMemType)mMemType); llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) ); S32 old_width = getWidth(); S32 old_height = getHeight(); if( (old_width == new_width) && (old_height == new_height) ) { return TRUE; // Nothing to do. } // Reallocate the data buffer. if (scale_image_data) { // Vertical S32 temp_data_size = old_width * new_height * getComponents(); llassert_always(temp_data_size > 0); U8* temp_buffer = new U8[ temp_data_size ]; for( S32 col = 0; col < old_width; col++ ) { copyLineScaled( getData() + (getComponents() * col), temp_buffer + (getComponents() * col), old_height, new_height, old_width, old_width ); } deleteData(); U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); // Horizontal for( S32 row = 0; row < new_height; row++ ) { copyLineScaled( temp_buffer + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 ); } // Clean up delete[] temp_buffer; } else { // copy out existing image data S32 temp_data_size = old_width * old_height * getComponents(); U8* temp_buffer = new U8[ temp_data_size ]; if (!temp_buffer) { llwarns << "Out of memory in LLImageRaw::scale: old (w, h, c) = (" << old_width << ", " << old_height << ", " << (S32)getComponents() << ") ; new (w, h, c) = (" << new_width << ", " << new_height << ", " << (S32)getComponents() << ")" << llendl; return FALSE ; } memcpy(temp_buffer, getData(), temp_data_size); /* Flawfinder: ignore */ // allocate new image data, will delete old data U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); for( S32 row = 0; row < new_height; row++ ) { if (row < old_height) { memcpy(new_buffer + (new_width * row * getComponents()), temp_buffer + (old_width * row * getComponents()), getComponents() * llmin(old_width, new_width)); /* Flawfinder: ignore */ if (old_width < new_width) { // pad out rest of row with black memset(new_buffer + (getComponents() * ((new_width * row) + old_width)), 0, getComponents() * (new_width - old_width)); } } else { // pad remaining rows with black memset(new_buffer + (new_width * row * getComponents()), 0, new_width * getComponents()); } } // Clean up delete[] temp_buffer; } return TRUE ; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LLMemType mt1(LLMemType::MTYPE_STARTUP); // *FIX: global gIconResource = MAKEINTRESOURCE(IDI_LL_ICON); // In Win32, we need to generate argc and argv ourselves... // Note: GetCommandLine() returns a potentially return a LPTSTR // which can resolve to a LPWSTR (unicode string). // (That's why it's different from lpCmdLine which is a LPSTR.) // We don't currently do unicode, so call the non-unicode version // directly. LPSTR cmd_line_including_exe_name = GetCommandLineA(); const S32 MAX_ARGS = 100; int argc = 0; char* argv[MAX_ARGS]; /* Flawfinder: ignore */ fill_args(argc, argv, MAX_ARGS, cmd_line_including_exe_name); LLAppViewerWin32* viewer_app_ptr = new LLAppViewerWin32(); // *FIX:Mani This method is poorly named, since the exception // is now handled by LLApp. bool ok = LLWinDebug::setupExceptionHandler(); // Actually here's the exception setup. LPTOP_LEVEL_EXCEPTION_FILTER prev_filter; prev_filter = SetUnhandledExceptionFilter(viewer_windows_exception_handler); if (!prev_filter) { llwarns << "Our exception handler (" << (void *)LLWinDebug::handleException << ") replaced with NULL!" << llendl; ok = FALSE; } if (prev_filter != LLWinDebug::handleException) { llwarns << "Our exception handler (" << (void *)LLWinDebug::handleException << ") replaced with " << prev_filter << "!" << llendl; ok = FALSE; } viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); ok = viewer_app_ptr->tempStoreCommandOptions(argc, argv); if(!ok) { llwarns << "Unable to parse command line." << llendl; return -1; } ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // viewer_app_ptr->cleanup(); } delete viewer_app_ptr; viewer_app_ptr = NULL; return 0; }
// static void LLViewerImageList::receiveImagePacket(LLMessageSystem *msg, void **user_data) { LLMemType mt1(LLMemType::MTYPE_APPFMTIMAGE); LLFastTimer t(LLFastTimer::FTM_PROCESS_IMAGES); // Receives image packet, copy into image object, // checks if all packets received, decompresses if so. LLUUID id; U16 packet_num; char ip_string[256]; u32_to_ip_string(msg->getSenderIP(),ip_string); if (msg->getReceiveCompressedSize()) { gImageList.sTextureBits += msg->getReceiveCompressedSize() * 8; } else { gImageList.sTextureBits += msg->getReceiveSize() * 8; } gImageList.sTexturePackets++; //llprintline("Start decode, image header..."); msg->getUUIDFast(_PREHASH_ImageID, _PREHASH_ID, id); msg->getU16Fast(_PREHASH_ImageID, _PREHASH_Packet, packet_num); S32 data_size = msg->getSizeFast(_PREHASH_ImageData, _PREHASH_Data); if (!data_size) { return; } if (data_size < 0) { // msg->getSizeFast() is probably trying to tell us there // was an error. llerrs << "image data chunk size was negative: " << data_size << llendl; return; } if (data_size > MTUBYTES) { llerrs << "image data chunk too large: " << data_size << " bytes" << llendl; return; } U8 *data = new U8[data_size]; msg->getBinaryDataFast(_PREHASH_ImageData, _PREHASH_Data, data, data_size); LLViewerImage *image = gImageList.getImage(id); if (!image) { delete [] data; return; } image->mLastPacketTimer.reset(); bool res = LLAppViewer::getTextureFetch()->receiveImagePacket(msg->getSender(), id, packet_num, data_size, data); if (!res) { delete[] data; } }
//------------------------------------------------------------------------------ bool DSNTwoWayRange::Evaluate(bool withEvents) { bool retval = false; if (!initialized) InitializeMeasurement(); #ifdef DEBUG_RANGE_CALC MessageInterface::ShowMessage("Entered DSNTwoWayRange::Evaluate(%s)\n", (withEvents ? "true" : "false")); MessageInterface::ShowMessage(" ParticipantCount: %d\n", participants.size()); #endif if (withEvents == false) { #ifdef DEBUG_RANGE_CALC MessageInterface::ShowMessage("DSN 2-Way Range Calculation without " "events\n"); #endif #ifdef VIEW_PARTICIPANT_STATES DumpParticipantStates("++++++++++++++++++++++++++++++++++++++++++++\n" "Evaluating DSN 2-Way Range without events"); #endif CalculateRangeVectorInertial(); Rvector3 outState; // Set feasibility off of topocentric horizon, set by the Z value in topo // coords std::string updateAll = "All"; UpdateRotationMatrix(currentMeasurement.epoch, updateAll); outState = R_o_j2k * rangeVecInertial; currentMeasurement.feasibilityValue = outState[2]; #ifdef CHECK_PARTICIPANT_LOCATIONS MessageInterface::ShowMessage("Evaluating without events\n"); MessageInterface::ShowMessage("Calculating DSN 2-Way Range at epoch " "%.12lf\n", currentMeasurement.epoch); MessageInterface::ShowMessage(" J2K Location of %s, id = '%s': %s", participants[0]->GetName().c_str(), currentMeasurement.participantIDs[0].c_str(), p1Loc.ToString().c_str()); MessageInterface::ShowMessage(" J2K Location of %s, id = '%s': %s", participants[1]->GetName().c_str(), currentMeasurement.participantIDs[1].c_str(), p2Loc.ToString().c_str()); Rvector3 bfLoc = R_o_j2k * p1Loc; MessageInterface::ShowMessage(" BodyFixed Location of %s: %s", participants[0]->GetName().c_str(), bfLoc.ToString().c_str()); bfLoc = R_o_j2k * p2Loc; MessageInterface::ShowMessage(" BodyFixed Location of %s: %s\n", participants[1]->GetName().c_str(), bfLoc.ToString().c_str()); #endif if (currentMeasurement.feasibilityValue > 0.0) { currentMeasurement.isFeasible = true; currentMeasurement.value[0] = rangeVecInertial.GetMagnitude(); currentMeasurement.eventCount = 2; SetHardwareDelays(false); retval = true; } else { currentMeasurement.isFeasible = false; currentMeasurement.value[0] = 0.0; currentMeasurement.eventCount = 0; } #ifdef DEBUG_RANGE_CALC MessageInterface::ShowMessage("Calculating Range at epoch %.12lf\n", currentMeasurement.epoch); MessageInterface::ShowMessage(" Location of %s, id = '%s': %s", participants[0]->GetName().c_str(), currentMeasurement.participantIDs[0].c_str(), p1Loc.ToString().c_str()); MessageInterface::ShowMessage(" Location of %s, id = '%s': %s", participants[1]->GetName().c_str(), currentMeasurement.participantIDs[1].c_str(), p2Loc.ToString().c_str()); MessageInterface::ShowMessage(" Range Vector: %s\n", rangeVecInertial.ToString().c_str()); MessageInterface::ShowMessage(" R(Groundstation) dot RangeVec = %lf\n", currentMeasurement.feasibilityValue); MessageInterface::ShowMessage(" Feasibility: %s\n", (currentMeasurement.isFeasible ? "true" : "false")); MessageInterface::ShowMessage(" Range is %.12lf\n", currentMeasurement.value[0]); MessageInterface::ShowMessage(" EventCount is %d\n", currentMeasurement.eventCount); #endif #ifdef SHOW_RANGE_CALC MessageInterface::ShowMessage("Range at epoch %.12lf is ", currentMeasurement.epoch); if (currentMeasurement.isFeasible) MessageInterface::ShowMessage("feasible, value = %.12lf\n", currentMeasurement.value[0]); else MessageInterface::ShowMessage("not feasible\n"); #endif } else { // Calculate the corrected range measurement #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("\n\n DSN 2-Way Range Calculation:\n"); #endif #ifdef VIEW_PARTICIPANT_STATES_WITH_EVENTS DumpParticipantStates("********************************************\n" "Evaluating DSN 2-Way Range with located events"); #endif // 1. Get the range from the down link Rvector3 r1, r2; Real t1, t2; r1 = downlinkLeg.GetPosition(participants[0]); r2 = downlinkLeg.GetPosition(participants[1]); t1 = downlinkLeg.GetEventData((GmatBase*) participants[0]).epoch; t2 = downlinkLeg.GetEventData((GmatBase*) participants[1]).epoch; Rmatrix33 mt = downlinkLeg.GetEventData((GmatBase*) participants[0]).rInertial2obj.Transpose(); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("1. Get downlink leg range:\n"); MessageInterface::ShowMessage(" Ground station position in FK5: r1 = (%f, %f, %f)km at epoch = %18.12lf\n", r1.Get(0), r1.Get(1), r1.Get(2), t1); MessageInterface::ShowMessage(" Spacecraft position in FK5 : r2 = (%f, %f, %f)km at epoch = %18.12lf\n", r2.Get(0), r2.Get(1), r2.Get(2), t2); MessageInterface::ShowMessage(" Transformation matrix from Earth fixed coordinate system to FK5 coordinate system at epoch = %18.12lf:\n", t1); MessageInterface::ShowMessage(" %18.12lf %18.12lf %18.12lf\n", mt(0,0), mt(0,1), mt(0,2)); MessageInterface::ShowMessage(" %18.12lf %18.12lf %18.12lf\n", mt(1,0), mt(1,1), mt(1,2)); MessageInterface::ShowMessage(" %18.12lf %18.12lf %18.12lf\n", mt(2,0), mt(2,1), mt(2,2)); #endif Rvector3 downlinkVector = r2 - r1; // rVector = r2 - r1; downlinkRange = downlinkVector.GetMagnitude(); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Downlink Range = r2-r1: %.12lf km\n", downlinkRange); #endif // 2. Calculate down link range rate: Rvector3 p1V = downlinkLeg.GetVelocity(participants[0]); Rvector3 p2V = downlinkLeg.GetVelocity(participants[1]); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("2. Get downlink leg range rate:\n"); MessageInterface::ShowMessage(" Ground station velocity in FK5: p1V = (%f, %f, %f)km/s\n", p1V.Get(0), p1V.Get(1), p1V.Get(2)); MessageInterface::ShowMessage(" Spacecraft velocity in FK5 : p2V = (%f, %f, %f)km/s\n", p2V.Get(0), p2V.Get(1), p2V.Get(2)); #endif // @todo Relative origin velocities need to be subtracted when the origins // differ; check and fix that part using r12_j2k_vel here. It's not yet // incorporated because we need to handle the different epochs for the // bodies, and we ought to do this part in barycentric coordinates Rvector downRRateVec = p2V - p1V /* - r12_j2k_vel*/; Rvector3 rangeUnit = downlinkVector.GetUnitVector(); downlinkRangeRate = downRRateVec * rangeUnit; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Downlink Range Rate: %.12lf km/s\n", downlinkRangeRate); #endif // 3. Get the range from the uplink Rvector3 r3, r4; Real t3, t4; r3 = uplinkLeg.GetPosition(participants[0]); r4 = uplinkLeg.GetPosition(participants[1]); t3 = uplinkLeg.GetEventData((GmatBase*) participants[0]).epoch; t4 = uplinkLeg.GetEventData((GmatBase*) participants[1]).epoch; Rmatrix33 mt1 = uplinkLeg.GetEventData((GmatBase*) participants[0]).rInertial2obj.Transpose(); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("3. Get uplink leg range:\n"); MessageInterface::ShowMessage(" Spacecraft position in FK5 : r4 = (%f, %f, %f)km at epoch = %18.12lf\n", r4.Get(0), r4.Get(1), r4.Get(2), t4); MessageInterface::ShowMessage(" Ground station position in FK5: r3 = (%f, %f, %f)km at epoch = %18.12lf\n", r3.Get(0), r3.Get(1), r3.Get(2), t3); MessageInterface::ShowMessage(" Transformation matrix from Earth fixed coordinate system to FK5 coordinate system at epoch = %18.12lf:\n", t3); MessageInterface::ShowMessage(" %18.12lf %18.12lf %18.12lf\n", mt1(0,0), mt1(0,1), mt1(0,2)); MessageInterface::ShowMessage(" %18.12lf %18.12lf %18.12lf\n", mt1(1,0), mt1(1,1), mt1(1,2)); MessageInterface::ShowMessage(" %18.12lf %18.12lf %18.12lf\n", mt1(2,0), mt1(2,1), mt1(2,2)); #endif Rvector3 uplinkVector = r4 - r3; uplinkRange = uplinkVector.GetMagnitude(); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Uplink Range = r4-r3: %.12lf km\n", uplinkRange); #endif // 4. Calculate up link range rate Rvector3 p3V = uplinkLeg.GetVelocity(participants[0]); Rvector3 p4V = uplinkLeg.GetVelocity(participants[1]); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("4. Get uplink leg range rate:\n"); MessageInterface::ShowMessage(" Ground station velocity in FK5: p3V = (%f, %f, %f)km/s\n", p3V.Get(0), p3V.Get(1), p3V.Get(2)); MessageInterface::ShowMessage(" Spacecraft velocity in FK5 : p4V = (%f, %f, %f)km/s\n", p4V.Get(0), p4V.Get(1), p4V.Get(2)); #endif // @todo Relative origin velocities need to be subtracted when the origins // differ; check and fix that part using r12_j2k_vel here. It's not yet // incorporated because we need to handle the different epochs for the // bodies, and we ought to do this part in barycentric coordinates Rvector upRRateVec = p4V - p3V /* - r12_j2k_vel*/ ; rangeUnit = uplinkVector.GetUnitVector(); uplinkRangeRate = upRRateVec * rangeUnit; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Uplink Range Rate: %.12lf km/s\n", uplinkRangeRate); #endif // 4.1. Target range rate: Do we need this as well? targetRangeRate = (downlinkRangeRate + uplinkRangeRate) / 2.0; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Target Range Rate: %.12lf km/s\n", targetRangeRate); #endif // 5. Get sensors used in DSN 2-ways range if (participantHardware.empty()|| ((!participantHardware.empty())&& participantHardware[0].empty()&& participantHardware[1].empty() ) ) { // DO NOT LEAVE THIS RAW IN A SOURCE FILE!!! // MessageInterface::ShowMessage(" Ideal measurement (no hardware delay and no media correction involve):\n"); // Calculate uplink time and down link time: (Is it needed???) uplinkTime = uplinkRange*GmatMathConstants::KM_TO_M / GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM; downlinkTime = downlinkRange*GmatMathConstants::KM_TO_M / GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Ideal measurement (no hardware delay and no media correction involve):\n"); MessageInterface::ShowMessage(" Uplink time = %.12lf s\n",uplinkTime); MessageInterface::ShowMessage(" Downlink time = %.12lf s\n",downlinkTime); #endif // Calculate real range Real freqFactor = GetFrequencyFactor(frequency); // Notice that: unit of "frequency" varaibel is Hz (not MHz) Real realTravelTime = uplinkTime + downlinkTime + receiveDelay + transmitDelay + targetDelay; // unit: second Real realRangeKm = 0.5 *realTravelTime * GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM/1000.0; // unit: km Real realRange = realTravelTime * freqFactor; // unit: no unit #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Frequency = %.12lf MHz (This value is set to the default value in PhysicalMeasurement class due to no hardware used.)\n", frequency/1.0e6); MessageInterface::ShowMessage(" Frequency factor = %.12lf MHz\n", freqFactor/1.0e6); MessageInterface::ShowMessage(" Range in km = %.12lf km\n", realRangeKm); MessageInterface::ShowMessage(" uplinkRange = %lfkm downlinkRange = %lfkm\n", uplinkRange, downlinkRange); MessageInterface::ShowMessage(" receiveDelay = %lfm transmitDelay = %lfm targetDelay = %lfm\n", receiveDelay*GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM, transmitDelay*GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM, targetDelay*GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM); MessageInterface::ShowMessage(" Range = %.12lf (It has no unit)\n", realRange); #endif // Set value for currentMeasurement currentMeasurement.value[0] = realRange; currentMeasurement.isFeasible = true; return true; } ObjectArray objList1; ObjectArray objList2; ObjectArray objList3; // objList1 := all transmitters in participantHardware list // objList2 := all receivers in participantHardware list // objList3 := all transponders in participantHardware list for(std::vector<Hardware*>::iterator hw = this->participantHardware[0].begin(); hw != this->participantHardware[0].end(); ++hw) { if ((*hw) != NULL) { if ((*hw)->GetTypeName() == "Transmitter") objList1.push_back(*hw); if ((*hw)->GetTypeName() == "Receiver") objList2.push_back(*hw); } else MessageInterface::ShowMessage(" sensor = NULL\n"); } for(std::vector<Hardware*>::iterator hw = this->participantHardware[1].begin(); hw != this->participantHardware[1].end(); ++hw) { if ((*hw) != NULL) { if ((*hw)->GetTypeName() == "Transponder") objList3.push_back(*hw); } else MessageInterface::ShowMessage(" sensor = NULL\n"); } if (objList1.size() != 1) { MessageInterface::ShowMessage("The first participant does not have only 1 transmitter to send signal.\n"); throw new MeasurementException("The first participant does not have only 1 transmitter to send signal.\n"); } if (objList2.size() != 1) { MessageInterface::ShowMessage("The first participant does not have only 1 receiver to receive signal.\n"); throw new MeasurementException("The first participant does not have only 1 receiver to receive signal.\n"); } if (objList3.size() != 1) { MessageInterface::ShowMessage("The second participant does not have only 1 transponder to transpond signal.\n"); throw new MeasurementException("The second participant does not have only 1 transponder to transpond signal.\n"); } Transmitter* gsTransmitter = (Transmitter*)objList1[0]; Receiver* gsReceiver = (Receiver*)objList2[0]; Transponder* scTransponder = (Transponder*)objList3[0]; if (gsTransmitter == NULL) { MessageInterface::ShowMessage("Transmitter is NULL object.\n"); throw new GmatBaseException("Transmitter is NULL object.\n"); } if (gsReceiver == NULL) { MessageInterface::ShowMessage("Receiver is NULL object.\n"); throw new GmatBaseException("Receiver is NULL object.\n"); } if (scTransponder == NULL) { MessageInterface::ShowMessage("Transponder is NULL object.\n"); throw new GmatBaseException("Transponder is NULL object.\n"); } #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("5. Sensors, delays, and signals:\n"); MessageInterface::ShowMessage(" List of sensors: %s, %s, %s\n", gsTransmitter->GetName().c_str(), gsReceiver->GetName().c_str(), scTransponder->GetName().c_str()); #endif // 6. Get transmitter, receiver, and transponder delays: transmitDelay = gsTransmitter->GetDelay(); receiveDelay = gsReceiver->GetDelay(); targetDelay = scTransponder->GetDelay(); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Transmitter delay = %le s\n", gsTransmitter->GetDelay()); MessageInterface::ShowMessage(" Receiver delay = %le s\n", gsReceiver->GetDelay()); MessageInterface::ShowMessage(" Transponder delay = %le s\n", scTransponder->GetDelay()); #endif // 7. Get frequency from transmitter of ground station (participants[0]) Signal* uplinkSignal = gsTransmitter->GetSignal(); Real uplinkFreq = uplinkSignal->GetValue(); // 8. Calculate media correction for uplink leg: #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("6. Media correction for uplink leg\n"); MessageInterface::ShowMessage(" UpLink signal frequency = %.12lf MHz\n", uplinkFreq); #endif Real roundTripTime = ((uplinkRange + downlinkRange)*GmatMathConstants::KM_TO_M/GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM)/GmatTimeConstants::SECS_PER_DAY; RealArray uplinkCorrection = CalculateMediaCorrection(uplinkFreq, r1, r2, currentMeasurement.epoch - roundTripTime); Real uplinkRangeCorrection = uplinkCorrection[0]/GmatMathConstants::KM_TO_M; Real uplinkRealRange = uplinkRange + uplinkRangeCorrection; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Uplink range correction = %.12lf km\n",uplinkRangeCorrection); MessageInterface::ShowMessage(" Uplink real range = %.12lf km\n",uplinkRealRange); #endif // 9. Doppler shift the frequency from the transmitter using uplinkRangeRate: Real uplinkDSFreq = (1 - uplinkRangeRate*GmatMathConstants::KM_TO_M/GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM)*uplinkFreq; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("7. Transponder input and output frequencies\n"); MessageInterface::ShowMessage(" Uplink Doppler shift frequency = %.12lf MHz\n", uplinkDSFreq); #endif // 10.Set frequency for the input signal of transponder Signal* inputSignal = scTransponder->GetSignal(0); inputSignal->SetValue(uplinkDSFreq); scTransponder->SetSignal(inputSignal, 0); // 11. Check the transponder feasibility to receive the input signal: if (scTransponder->IsFeasible(0) == false) { currentMeasurement.isFeasible = false; currentMeasurement.value[0] = 0; MessageInterface::ShowMessage("The transponder is unfeasible to receive uplink signal.\n"); throw new GmatBaseException("The transponder is unfeasible to receive uplink signal.\n"); } // 12. Get frequency of transponder output signal Signal* outputSignal = scTransponder->GetSignal(1); Real downlinkFreq = outputSignal->GetValue(); #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Downlink frequency = %.12lf Mhz\n", downlinkFreq); #endif // 13. Doppler shift the transponder output frequency by the downlinkRangeRate: Real downlinkDSFreq = (1 - downlinkRangeRate*GmatMathConstants::KM_TO_M/GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM)*downlinkFreq; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Downlink Doppler shift frequency = %.12lf MHz\n", downlinkDSFreq); #endif // 14. Set frequency on receiver Signal* downlinkSignal = gsReceiver->GetSignal(); downlinkSignal->SetValue(downlinkDSFreq); // 15. Check the receiver feasibility to receive the downlink signal if (gsReceiver->IsFeasible() == false) { currentMeasurement.isFeasible = false; currentMeasurement.value[0] = 0; MessageInterface::ShowMessage("The receiver is unfeasible to receive downlink signal.\n"); throw new MeasurementException("The receiver is unfeasible to receive downlink signal.\n"); } // 16. Calculate media correction for downlink leg: #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("8. Media correction for downlink leg\n"); #endif RealArray downlinkCorrection = CalculateMediaCorrection(downlinkDSFreq, r3, r4, currentMeasurement.epoch); Real downlinkRangeCorrection = downlinkCorrection[0]/GmatMathConstants::KM_TO_M; Real downlinkRealRange = downlinkRange + downlinkRangeCorrection; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Downlink range correction = %.12lf km\n",downlinkRangeCorrection); MessageInterface::ShowMessage(" Downlink real range = %.12lf km\n",downlinkRealRange); #endif // 17. Calculate uplink time and down link time: (Is it needed???) uplinkTime = uplinkRealRange*GmatMathConstants::KM_TO_M / GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM; downlinkTime = downlinkRealRange*GmatMathConstants::KM_TO_M / GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM; #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage("9. Travel time:\n"); MessageInterface::ShowMessage(" Uplink time = %.12lf s\n",uplinkTime); MessageInterface::ShowMessage(" Downlink time = %.12lf s\n",downlinkTime); #endif // 18. Calculate real range // Real realRange = ((upRange + downRange) / // (GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM / GmatMathConstants::KM_TO_M) + // receiveDelay + transmitDelay + targetDelay) * freqFactor; // Real freqFactor = GetFrequencyFactor(frequency); Real freqFactor = GetFrequencyFactor(uplinkFreq*1.0e6); // Notice that: unit of "uplinkFreq" is MHz (not Hz) Real realTravelTime = uplinkTime + downlinkTime + receiveDelay + transmitDelay + targetDelay; // unit: second Real realRangeKm = 0.5*realTravelTime * GmatPhysicalConstants::SPEED_OF_LIGHT_VACUUM/1000.0; // unit: km Real realRange = realTravelTime * freqFactor; // unit: no unit #ifdef DEBUG_RANGE_CALC_WITH_EVENTS MessageInterface::ShowMessage(" Frequency factor = %.12lf MHz\n", freqFactor/1.0e6); MessageInterface::ShowMessage(" Calculated real range in km = %.12lf km\n", realRangeKm); MessageInterface::ShowMessage(" Calculated real range = %.12lf (It has no unit)\n", realRange); #endif // 19. Set value for currentMeasurement // currentMeasurement.value[0] = realRange; currentMeasurement.value[0] = realRangeKm; currentMeasurement.isFeasible = true; retval = true; } return retval; }
int APIENTRY WINMAIN(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LLMemType mt1(LLMemType::MTYPE_STARTUP); #if WINDOWS_CRT_MEM_CHECKS && !INCLUDE_VLD _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // dump memory leaks on exit #endif // *FIX: global gIconResource = MAKEINTRESOURCE(IDI_LL_ICON); LLAppViewerWin32* viewer_app_ptr = new LLAppViewerWin32(lpCmdLine); LLWinDebug::initExceptionHandler(viewer_windows_exception_handler); viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); bool ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // #if WINDOWS_CRT_MEM_CHECKS llinfos << "CRT Checking memory:" << llendflush; if (!_CrtCheckMemory()) { llwarns << "_CrtCheckMemory() failed at prior to cleanup!" << llendflush; } else { llinfos << " No corruption detected." << llendflush; } #endif viewer_app_ptr->cleanup(); #if WINDOWS_CRT_MEM_CHECKS llinfos << "CRT Checking memory:" << llendflush; if (!_CrtCheckMemory()) { llwarns << "_CrtCheckMemory() failed after cleanup!" << llendflush; } else { llinfos << " No corruption detected." << llendflush; } #endif } delete viewer_app_ptr; viewer_app_ptr = NULL; return 0; }
BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, const LLMatrix4& mat_vert_in, const LLMatrix3& mat_normal_in, BOOL global_volume) { LLMemType mt1(LLMemType::MTYPE_DRAWABLE); //get bounding box if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION #if MESH_ENABLED | LLDrawable::REBUILD_RIGGED #endif //MESH_ENABLED )) { //VECTORIZE THIS LLMatrix4a mat_vert; mat_vert.loadu(mat_vert_in); LLMatrix4a mat_normal; mat_normal.loadu(mat_normal_in); //if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME)) //{ //vertex buffer no longer valid // mVertexBuffer = NULL; // mLastVertexBuffer = NULL; //} //VECTORIZE THIS LLVector4a min,max; if (f >= volume.getNumVolumeFaces()) { llwarns << "Generating bounding box for invalid face index!" << llendl; f = 0; } const LLVolumeFace &face = volume.getVolumeFace(f); min = face.mExtents[0]; max = face.mExtents[1]; llassert(less_than_max_mag(min)); llassert(less_than_max_mag(max)); //min, max are in volume space, convert to drawable render space LLVector4a center; LLVector4a t; t.setAdd(min, max); t.mul(0.5f); mat_vert.affineTransform(t, center); LLVector4a size; size.setSub(max, min); size.mul(0.5f); llassert(less_than_max_mag(min)); llassert(less_than_max_mag(max)); if (!global_volume) { //VECTORIZE THIS LLVector4a scale; scale.load3(mDrawablep->getVObj()->getScale().mV); size.mul(scale); } mat_normal.mMatrix[0].normalize3fast(); mat_normal.mMatrix[1].normalize3fast(); mat_normal.mMatrix[2].normalize3fast(); LLVector4a v[4]; //get 4 corners of bounding box mat_normal.rotate(size,v[0]); //VECTORIZE THIS LLVector4a scale; scale.set(-1.f, -1.f, 1.f); scale.mul(size); mat_normal.rotate(scale, v[1]); scale.set(1.f, -1.f, -1.f); scale.mul(size); mat_normal.rotate(scale, v[2]); scale.set(-1.f, 1.f, -1.f); scale.mul(size); mat_normal.rotate(scale, v[3]); LLVector4a& newMin = mExtents[0]; LLVector4a& newMax = mExtents[1]; newMin = newMax = center; llassert(less_than_max_mag(center)); for (U32 i = 0; i < 4; i++) { LLVector4a delta; delta.setAbs(v[i]); LLVector4a min; min.setSub(center, delta); LLVector4a max; max.setAdd(center, delta); newMin.setMin(newMin,min); newMax.setMax(newMax,max); llassert(less_than_max_mag(newMin)); llassert(less_than_max_mag(newMax)); } if (!mDrawablep->isActive()) { LLVector4a offset; offset.load3(mDrawablep->getRegion()->getOriginAgent().mV); newMin.add(offset); newMax.add(offset); llassert(less_than_max_mag(newMin)); llassert(less_than_max_mag(newMax)); } t.setAdd(newMin, newMax); t.mul(0.5f); llassert(less_than_max_mag(t)); //VECTORIZE THIS mCenterLocal.set(t.getF32ptr()); llassert(less_than_max_mag(newMin)); llassert(less_than_max_mag(newMax)); t.setSub(newMax,newMin); mBoundingSphereRadius = t.getLength3().getF32()*0.5f; updateCenterAgent(); } return TRUE; }
int APIENTRY WINMAIN(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { LLMemType mt1(LLMemType::MTYPE_STARTUP); const S32 MAX_HEAPS = 255; DWORD heap_enable_lfh_error[MAX_HEAPS]; S32 num_heaps = 0; #if WINDOWS_CRT_MEM_CHECKS && !INCLUDE_VLD _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // dump memory leaks on exit #elif 1 // Experimental - enable the low fragmentation heap // This results in a 2-3x improvement in opening a new Inventory window (which uses a large numebr of allocations) // Note: This won't work when running from the debugger unless the _NO_DEBUG_HEAP environment variable is set to 1 _CrtSetDbgFlag(0); // default, just making explicit ULONG ulEnableLFH = 2; HANDLE* hHeaps = new HANDLE[MAX_HEAPS]; num_heaps = GetProcessHeaps(MAX_HEAPS, hHeaps); for(S32 i = 0; i < num_heaps; i++) { bool success = HeapSetInformation(hHeaps[i], HeapCompatibilityInformation, &ulEnableLFH, sizeof(ulEnableLFH)); if (success) heap_enable_lfh_error[i] = 0; else heap_enable_lfh_error[i] = GetLastError(); } #endif // *FIX: global gIconResource = MAKEINTRESOURCE(IDI_LL_ICON); LLAppViewerWin32* viewer_app_ptr = new LLAppViewerWin32(lpCmdLine); LLWinDebug::initExceptionHandler(viewer_windows_exception_handler); viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); // Set a debug info flag to indicate if multiple instances are running. bool found_other_instance = !create_app_mutex(); gDebugInfo["FoundOtherInstanceAtStartup"] = LLSD::Boolean(found_other_instance); bool ok = viewer_app_ptr->init(); if(!ok) { llwarns << "Application init failed." << llendl; return -1; } // Have to wait until after logging is initialized to display LFH info if (num_heaps > 0) { llinfos << "Attempted to enable LFH for " << num_heaps << " heaps." << llendl; for(S32 i = 0; i < num_heaps; i++) { if (heap_enable_lfh_error[i]) { llinfos << " Failed to enable LFH for heap: " << i << " Error: " << heap_enable_lfh_error[i] << llendl; } } } // Run the application main loop if(!LLApp::isQuitting()) { viewer_app_ptr->mainLoop(); } if (!LLApp::isError()) { // // We don't want to do cleanup here if the error handler got called - // the assumption is that the error handler is responsible for doing // app cleanup if there was a problem. // #if WINDOWS_CRT_MEM_CHECKS llinfos << "CRT Checking memory:" << llendflush; if (!_CrtCheckMemory()) { llwarns << "_CrtCheckMemory() failed at prior to cleanup!" << llendflush; } else { llinfos << " No corruption detected." << llendflush; } #endif viewer_app_ptr->cleanup(); #if WINDOWS_CRT_MEM_CHECKS llinfos << "CRT Checking memory:" << llendflush; if (!_CrtCheckMemory()) { llwarns << "_CrtCheckMemory() failed after cleanup!" << llendflush; } else { llinfos << " No corruption detected." << llendflush; } #endif } delete viewer_app_ptr; viewer_app_ptr = NULL; //start updater if(LLAppViewer::sUpdaterInfo) { _spawnl(_P_NOWAIT, LLAppViewer::sUpdaterInfo->mUpdateExePath.c_str(), LLAppViewer::sUpdaterInfo->mUpdateExePath.c_str(), LLAppViewer::sUpdaterInfo->mParams.str().c_str(), NULL); delete LLAppViewer::sUpdaterInfo ; LLAppViewer::sUpdaterInfo = NULL ; } return 0; }
BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data ) { LLMemType mt1(mMemType); llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) ); S32 old_width = getWidth(); S32 old_height = getHeight(); if( (old_width == new_width) && (old_height == new_height) ) { return TRUE; // Nothing to do. } // Reallocate the data buffer. if (scale_image_data) { S32 temp_data_size = old_width * new_height * getComponents(); llassert_always(temp_data_size > 0); std::vector<U8> temp_buffer(temp_data_size); // Vertical for( S32 col = 0; col < old_width; col++ ) { copyLineScaled( getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), old_height, new_height, old_width, old_width ); } deleteData(); U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); // Horizontal for( S32 row = 0; row < new_height; row++ ) { copyLineScaled( &temp_buffer[0] + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 ); } } else { // copy out existing image data S32 temp_data_size = old_width * old_height * getComponents(); std::vector<U8> temp_buffer(temp_data_size); memcpy(&temp_buffer[0], getData(), temp_data_size); // allocate new image data, will delete old data U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); for( S32 row = 0; row < new_height; row++ ) { if (row < old_height) { memcpy(new_buffer + (new_width * row * getComponents()), &temp_buffer[0] + (old_width * row * getComponents()), getComponents() * llmin(old_width, new_width)); if (old_width < new_width) { // pad out rest of row with black memset(new_buffer + (getComponents() * ((new_width * row) + old_width)), 0, getComponents() * (new_width - old_width)); } } else { // pad remaining rows with black memset(new_buffer + (new_width * row * getComponents()), 0, new_width * getComponents()); } } } return TRUE ; }