[mapguide-commits] r4469 - sandbox/rfc60/MgDev/Server/src/Services/Rendering

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Dec 23 17:51:31 EST 2009


Author: waltweltonlair
Date: 2009-12-23 17:51:30 -0500 (Wed, 23 Dec 2009)
New Revision: 4469

Modified:
   sandbox/rfc60/MgDev/Server/src/Services/Rendering/ServerRenderingService.cpp
Log:
RFC60 fixes to ServerRenderingService.cpp

 * Fixed a memory leak.  In the case of AGG the RS_ColorVector object is
   allocated but never deleted.  Fixed by allocating the RS_ColorVector
   object on the stack.

 * Fixed logic error.  When getting the image data from the renderer, the code
   which checks for the AGG renderer also now included a check for hasColorMap.
   If the renderer is AGG but hasColorMap returned false then the code would
   incorrectly jump to the else block and use GD renderer.

 * Fixed exception usage (1).  When the renderer returns no data the code now
   throws an exception.  Original an MgNullArgumentException was raised, and
   in my review comments I suggested using MgStylizeLayerFailedException instead.
   Turns out that one doesn't work because it requires a specific layer as a
   what argument.  Looking through the exception types, the right one is
   actually MgNullReferenceException.

 * Fixed exception usage (2).  When creating the exception the message argument
   needs to be an id of a message in the resource file, and not the message itself.
   I added a new id to the resource file with the desired message.


Modified: sandbox/rfc60/MgDev/Server/src/Services/Rendering/ServerRenderingService.cpp
===================================================================
--- sandbox/rfc60/MgDev/Server/src/Services/Rendering/ServerRenderingService.cpp	2009-12-23 21:39:00 UTC (rev 4468)
+++ sandbox/rfc60/MgDev/Server/src/Services/Rendering/ServerRenderingService.cpp	2009-12-23 22:51:30 UTC (rev 4469)
@@ -835,6 +835,7 @@
     dr->StartMap(&mapInfo, b, scale, map->GetDisplayDpi(), map->GetMetersPerUnit(), NULL);
 
     MG_TRY()
+
         // if no layer collection is supplied, then put all layers in a temporary collection
         Ptr<MgReadOnlyLayerCollection> tempLayers = SAFE_ADDREF(roLayers);
         if (tempLayers == NULL)  // if called from renderMap not RenderTile
@@ -909,8 +910,9 @@
                     modLayers, overrideFilters, &ds, dr, dstCs, false, false, scale, (behavior & MgRenderingOptions::KeepSelection) != 0);
             }
         }
-    MG_CATCH(L"MgServerRenderingService.RenderMapInternal-StylizeLayers")
 
+    MG_CATCH(L"MgServerRenderingService.RenderMapInternal")
+
     dr->EndMap();   // cleanup of DWF Renderer
 
     MG_THROW()  // to skip a faulty tile we need to rethrow the exception which could be thrown in StylizeLayers
@@ -939,32 +941,39 @@
 
     // get a byte representation of the image
     auto_ptr<RS_ByteData> data;
-    /////////////////////////////////////////////////////////////////////////////////////////////////
-    /// rfc60 code to correct colormaps by UV
-    /////////////////////////////////////////////////////////////////////////////////////////////////
-    /// we examine the expressions collected from xml definitions of all layer.
-    /// the map object has a list from all color entries found in the most recent Layerstylization
-    /// TODO currently they are interpreted as ffffffff 32 bit RGBA string values.
-    /// adding expresssions and other interpretations should be done in ParseColorStrings. 
-    /// the color Palette for the renderer is a list<RSColor>
-    RS_ColorVector* tileColorPalette = NULL;
-    try {
-        //  call the image renderer to create the image ----------------------------------------
-        if (wcscmp(m_rendererName.c_str(), L"AGG") == 0  && hasColorMap(format))   
-        {    
-            tileColorPalette = new RS_ColorVector();
-            MgMappingUtil::ParseColorStrings (tileColorPalette, map);
-            #ifdef _DEBUG_PNG8
-            printf("<<<<<<<<<<<<<<<<<<<<< MgServerRenderingService::ColorPalette->size(): %d\n", mapColorPalette->size());
-            #endif
-            data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, tileColorPalette));
-        } else
+
+    try
+    {
+        // call the image renderer to create the image
+        if (wcscmp(m_rendererName.c_str(), L"AGG") == 0)
+        {
+            //-------------------------------------------------------
+            /// rfc60 code to correct colormaps by UV
+            //-------------------------------------------------------
+            /// we examine the expressions collected from xml definitions of all layers.
+            /// the map object has a list from all color entries found in the most recent layer stylization
+            /// TODO currently they are interpreted as ffffffff 32 bit RGBA string values.
+            /// adding expresssions and other interpretations should be done in ParseColorStrings.
+            /// the color Palette for the renderer is a list<RSColor>
+            if (hasColorMap(format))
+            {
+                RS_ColorVector tileColorPalette;
+                MgMappingUtil::ParseColorStrings(&tileColorPalette, map);
+//              printf("<<<<<<<<<<<<<<<<<<<<< MgServerRenderingService::ColorPalette->size(): %d\n", tileColorPalette.size());
+                data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, &tileColorPalette));
+            }
+            else
+                data.reset(((AGGRenderer*)dr)->Save(format, saveWidth, saveHeight, NULL));
+        }
+        else
             data.reset(((GDRenderer*)dr)->Save(format, saveWidth, saveHeight));
-    } catch (exception e) 
+    }
+    catch (exception e) 
     {
         ACE_DEBUG((LM_DEBUG, L"(%t) %w caught in RenderingService ColorPaletteGeneration\n", e.what()));
         throw e;
     }
+
     if (NULL != data.get())
     {
         // put this into a byte source
@@ -982,7 +991,7 @@
         ret = bs->GetReader();
     }
     else 
-        throw new MgStylizeLayerFailedException(L"RenderMapInternal", __LINE__, __WFILE__, NULL, L"No data from Renderer", NULL);
+        throw new MgNullReferenceException(L"MgServerRenderingService.RenderMapInternal", __LINE__, __WFILE__, NULL, L"MgNoDataFromRenderer", NULL);
 
     return ret.Detach();
 }



More information about the mapguide-commits mailing list