Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#2205 closed defect (fixed)

imageObj.getBytes() is severely broken

Reported by: hobu Owned by: sdlime
Priority: normal Milestone: 5.0 release
Component: MapServer C Library Version: svn-trunk (development)
Severity: normal Keywords:
Cc:

Description

Attempting to do imageObj.getBytes() results in a segfault. imageObj.save() works fine and as expected.

Here's some gdb output:

#0  0x0054a4b8 in gdImageInterlace (im=0x0, interlaceArg=1) at gd.c:3199
#1  0x010ca4e1 in msSaveImageBufferGD (img=0x0, size_ptr=0xbffff320, format=0x311b60) at mapgd.c:3663
#2  0x0101c972 in _wrap_imageObj_getBytes (self=0x0, args=0x4cabf0) at mapscript_wrap.c:4608
#3  0x97eb67fe in PyObject_Call ()
#4  0x97f07450 in _PyEval_SliceIndex ()
#5  0x97f08a98 in PyEval_EvalCodeEx ()
#6  0x97f06f6d in _PyEval_SliceIndex ()
#7  0x97f06eac in _PyEval_SliceIndex ()
#8  0x97f08a98 in PyEval_EvalCodeEx ()
#9  0x97f08bbb in PyEval_EvalCode ()
#10 0x97f21dc5 in PyErr_Display ()
#11 0x97f2395a in PyRun_SimpleFileExFlags ()
#12 0x97f2b42b in Py_Main ()
#13 0x00001f8e in start ()
(gdb) f 1
#1  0x010ca4e1 in msSaveImageBufferGD (img=0x0, size_ptr=0xbffff320, format=0x311b60) at mapgd.c:3663
3663        gdImageInterlace(img, 1);
(gdb) p img
$1 = (gdImagePtr) 0x0
(gdb) f 2
#2  0x0101c972 in _wrap_imageObj_getBytes (self=0x0, args=0x4cabf0) at mapscript_wrap.c:4608
4608                buffer.data = msSaveImageBufferGD(self->img.gd, &buffer.size,
(gdb) arg1
Undefined command: "arg1".  Try "help".
(gdb) p arg1
$2 = (imageObj *) 0x337570
(gdb) p arg1->format
$3 = (outputFormatObj *) 0x311b60
(gdb) p *(arg1->format)
$4 = {
  name = 0x312240 "png", 
  mimetype = 0x3122b0 "image/png", 
  driver = 0x311b90 "GD/PNG", 
  extension = 0x311b40 "png", 
  renderer = 1, 
  imagemode = 0, 
  transparent = 0, 
  bands = 1, 
  numformatoptions = 0, 
  formatoptions = 0x0, 
  refcount = 3, 
  inmapfile = 1
}
(gdb) p *(arg1->img)
Attempt to take contents of a non-pointer value.
(gdb) p *(arg1->)
A parse error in expression, near `)'.
(gdb) p *(arg1)
$5 = {
  width = 400, 
  height = 400, 
  imagepath = 0x337540 "", 
  imageurl = 0x337550 "", 
  format = 0x311b60, 
  renderer = 0, 
  size = 0, 
  img = {
    gd = 0x0, 
    svg = 0x0, 
    imagemap = 0x0, 
    raw_16bit = 0x0, 
    raw_float = 0x0, 
    raw_byte = 0x0
  }
}

As you can see the img->img and img->img.gd seem to be getting zero'd out somehow. Any ideas? This worked fine in 4.10. I am using swig 1.3.31, and I tried rolling back to swig 1.3.29, but the same problem happened in the same way.

Change History (6)

comment:1 by hobu, 17 years ago

I rolled back to r5714 and things work. The graticule data is in #2202

MAP
  EXTENT -180 -90 180 90
  FONTSET "/Users/hobu/svn/mapserver/tests/fonts.txt"
  SYMBOLSET "symbols.sym"
  IMAGECOLOR 255 255 255
  IMAGETYPE png
  SIZE 400 400
  STATUS ON
  UNITS METERS
  NAME "MS"

 # DEBUG 1
  OUTPUTFORMAT
    NAME "png"
    MIMETYPE "image/png"
    DRIVER "GD/PNG"
    EXTENSION "png"
    IMAGEMODE "PC256"
    TRANSPARENT FALSE
  END

  # outputformat
  #   name "agg"
  #   driver "AGG/PNG"
  # end
# 
# SYMBOL
#   NAME "circle"
#   TYPE ellipse
#   FILLED true
#   POINTS
#     1 1
#   END
# END

    PROJECTION
      "init=epsg:4326"
    END

  LAYER
  #  CLASSITEM "TYPE"
    DATA "data/world_borders.shp"
  #  DEBUG 1
  #  LABELITEM "VALUE"

    #        OPACITY 40
    NAME "world_borders"
    PROJECTION
      "init=epsg:4326"
    END
    STATUS DEFAULT
    TYPE POLYGON
    UNITS DD
    CLASS


        STYLE # solid fill
            COLOR 0 104 104

        END
        STYLE # thick outline (could use a circle symbol with size too)
            OUTLINECOLOR 0 0 0
            WIDTH 2
            ANTIALIAS TRUE
        END

    END

  END
  
  LAYER
    CLASSITEM "TYPE"
    DATA "data/graticule.shp"
  #  DEBUG 1
    LABELITEM "VALUE"

    NAME "base_layer"
    PROJECTION
      "init=epsg:4326"
    END
    STATUS DEFAULT
    TYPE LINE
    UNITS DD
    CLASS
      EXPRESSION ([TYPE] EQ 1)
      LABEL

        ANTIALIAS TRUE
        FONT "Vera"

        SIZE 6
        TYPE TRUETYPE
        COLOR 255 0 0
        FORCE FALSE
        MINDISTANCE 200
        MINFEATURESIZE -1

        PARTIALS TRUE
        POSITION AUTO
      END

      STYLE

        COLOR 0 0 255
#        WIDTH 6
        SIZE 3
        SYMBOL 'circle'
      END

    END

  END


END

import sys
sys.path.insert(0,'/Users/hobu/svn/mapserver/mapscript/python/build/lib.darwin-8.10.1-i386-2.3')
import mapscript
import cStringIO




def get_srs(url):
    import urllib2
    return urllib2.urlopen(url).read()

def get_extent(bounds, srs):
    ll = mapscript.pointObj()
    ll.x = bounds[0]
    ll.y = bounds[1]

    ur = mapscript.pointObj()
    ur.x = bounds[2]
    ur.y = bounds[3]

    # project our point into the mapObj's projection
    output_proj = mapscript.projectionObj(srs)
    print srs
    input_proj = mapscript.projectionObj("init=epsg:4326")
    ll.project(input_proj, output_proj)
    ur.project(input_proj, output_proj)
    print 'in bounds: ', bounds
    print 'out bounds: ', (ll.x, ll.y, ur.x, ur.y)
    return (ll.x, ll.y, ur.x, ur.y)
def render(bounds, url):
    mo = mapscript.mapObj('render.map')
    
    srs = get_srs(url)

    extent = get_extent(bounds, srs)
    mo.setProjection(srs)
    mo.setExtent(*extent)
    im = mo.draw()
    print im
    print im.format
    print im.width, im.height
    print im.this, im.thisown
    print dir(im)
    im.save('foo2.png')
    data = im.saveToString()
    
#    data = im.getBytes()
    
    output = cStringIO.StringIO(data)
    return output
    
b = (-5.2, 42.25, 8.23, 51.1)
o = render(b, 'http://spatialreference.org/ref/epsg/27572/proj4/')

f = file('junk.png','wb')
f.write(o.read())
f.close()
# # Mollweide Projection
# mo.setSize(600, 300)
# mo.setProjection('+proj=moll +lon_0=0.0')
# mo.setExtent(-18100000, -9050000, 18100000, 9050000)
# im = mo.draw()
# im.save('graticule-moll.png')
# 
# mo.setSize(400, 400)
# mo.setProjection('+proj=ortho +lon_0=0.0 +lat_0=40.0')
# mo.setExtent(-6400000,-6400000,6400000,6400000)
# im = mo.draw()
# im.save('graticule-ortho.png')


comment:2 by hobu, 17 years ago

Things work as expected in r6386

comment:3 by hobu, 17 years ago

last comment was incorrect.

r5957 -- good r5960 -- bad

as soon as we link in AGG, it seems that imageObj.getBytes no longer works

comment:4 by hobu, 17 years ago

fixed in r6462. Damn conditional struct members!!!! Die! Die! Die!

comment:5 by hobu, 17 years ago

Resolution: fixed
Status: newclosed

r6463 is related, and makes getBytes use msSaveImageBufferAGG for AGG-formated stuff

comment:6 by warmerdam, 17 years ago

r6468 makes imageextra field non condition to avoid this problem occuring in other contexts where the USE_AGG might not be properly available.

Note: See TracTickets for help on using tickets.