Hi,

I have managed to track down the issue and have attached the fix. The problem 
was that the GLU functions were using a different calling convention. I don't 
for a second pretend to understand the issue properly or why it exists as 
anything that combines windows and C++ completely defies my understanding. 
However, what I have done seems reasonable and does fix the problem. Somebody 
who actually understands this stuff might have a cleaner solution but the 
changes are actually very small and seem inline with what has been done in 
other parts of OSG.

For anyone who is interested or might understand the errors better, the Visual 
Studio debugger reported the following:
>> Run-Time Check Failure #0 - The value of ESP was not properly saved across a 
>> function call.  This is usually a result of calling a function declared with 
>> one calling convention with a function pointer declared with a different 
>> calling convention.

This led me here: 
http://blogs.msdn.com/b/mithuns/archive/2006/12/11/pay-attention-to-the-calling-convention.aspx
Which is what I based my fix on.



I have also noticed some warning during compilation which I haven't fixed but 
thought I would mention anyway:

1>  tess.cpp
1>..\..\..\src-trunk\src\osg\glu\libtess\tess.cpp(505): warning C4611: 
interaction between '_setjmp' and C++ object destruction is non-portable

1>  error.cpp
1>..\..\..\src-trunk\src\osg\glu\libutil\error.cpp(135): warning C4245: 
'initializing' : conversion from 'int' to 'GLuint', signed/unsigned mismatch

1>  tess.cpp
1>..\..\..\src-trunk\src\osg\glu\libtess\tess.cpp(505): warning C4611: 
interaction between '_setjmp' and C++ object destruction is non-portable

1>d:\osg\osg-trunk\src-trunk\src\osg\glu\libutil\mipmap.cpp(5208): warning 
C4701: potentially uninitialized local variable 'iter' used
1>d:\osg\osg-trunk\src-trunk\src\osg\glu\libutil\mipmap.cpp(5550): warning 
C4701: potentially uninitialized local variable 'iter' used
1>d:\osg\osg-trunk\src-trunk\src\osg\glu\libutil\mipmap.cpp(6934): warning 
C4701: potentially uninitialized local variable 'iter' used
1>d:\osg\osg-trunk\src-trunk\src\osg\glu\libutil\mipmap.cpp(7368): warning 
C4701: potentially uninitialized local variable 'iter' used

Cheers.
Brad


-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Christiansen, 
Brad
Sent: Thursday, 14 October 2010 9:40 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Crash with SVN version of Tessellator

Hi Robert,

Both osgtesselate and osgtext3D crash as well. The stack trace for osgtesselate 
is:

>    osgd.dll!RenderStrip(osg::GLUtesselator * tess=0x0272a9f8, GLUhalfEdge * 
> e=0x0272e6a0, long size=12907152)  Line 311 + 0x32 bytes    C++
     osgd.dll!__gl_renderMesh(osg::GLUtesselator * tess=0x0272a9f8, GLUmesh * 
mesh=0x0272bb40)  Line 99 + 0xd bytes    C++
     osgd.dll!osg::gluTessEndPolygon(osg::GLUtesselator * tess=0x0272a9f8)  
Line 572 + 0xd bytes    C++
     osgUtild.dll!osgUtil::Tessellator::endTessellation()  Line 87 + 0xf bytes  
  C++
     osgUtild.dll!osgUtil::Tessellator::retessellatePolygons(osg::Geometry & 
geom={...})  Line 285    C++
     osgtessellated.exe!makeFrontWall(const float zpos=0.00000000)  Line 289 + 
0x19 bytes    C++
     osgtessellated.exe!makeHouse()  Line 295 + 0xb bytes    C++
     osgtessellated.exe!makeTessellateExample()  Line 563 + 0x5 bytes    C++
     osgtessellated.exe!main(int argc=1, char * * argv=0x0270dbe8)  Line 762 + 
0x5 bytes    C++
     osgtessellated.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes    C
     osgtessellated.exe!mainCRTStartup()  Line 371    C

Now I have a nice simple example to debug (and a debug build of it) I will try 
and dig a little further and track down the issue. I am not holding my breath 
though as my C++ debugging skills are not exactly stellar. I am primarily a 
Java programmer after all : )

I assume this is a platform specific issue of some type? It would be great to 
get some feedback from others using different platforms and compilers to try 
and narrow down the cause of the crash.

Cheers,

Brad

-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield
Sent: Wednesday, 13 October 2010 4:54 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Crash with SVN version of Tessellator

Hi Brad,

As you've spotted the GLU tessellation code has now been integrated
with the build of the core OSG library.  I have taken the code from
Mesa 7.9, which in turn based it's GLU implementation on SGI base.
I'd expect most GLU implementations are based on the original SGI code
base, they might all have different bug fixes applied to them, perhaps
the Mesa code doesn't have a fix that the previous GLU library that
you were linking against had, or perhaps I've introduced a bug during
integration.

One advantage now is that you will be able build the GLU code with
debug along with the rest of the OSG and be able step through it see
where problems might be arising.  From your stack trace the line:

:push_back(osg::Vec3f * const & _Val=0x00000000)

Looks pretty suspicious.  The debug info doesn't really reveal exactly
which code is calling phs_back with the dodgy value.

BTW, Do you see problems when you run osgtext3D? Or osgtessellate?
Both of these will be using the newly integrated GLU tessellation
code.

Robert.


On Wed, Oct 13, 2010 at 9:42 AM, Christiansen, Brad
<brad.christian...@thalesgroup.com.au> wrote:
> Hi,
>
> I forgot a few details. I am runnign Windows 7 with Visual Studio 2010.
>
> The relevent bit of the stack trace is:
>
>        msvcr100.dll!free(void * pBlock=0x0c3acde8)  Line 51    C
>>       osgUtilrd.dll!std::vector<osg::Vec3f *,std::allocator<osg::Vec3f *> 
>> >::reserve(unsigned int _Count=141)  Line 765 + 0x6 bytes   C++
>        osgUtilrd.dll!std::vector<osg::Vec3f *,std::allocator<osg::Vec3f *> 
> >::_Reserve(unsigned int _Count=150271084)  Line 1297 + 0x21 bytes  C++
>        osgUtilrd.dll!std::vector<osg::Vec3f *,std::allocator<osg::Vec3f *> 
> >::push_back(osg::Vec3f * const & _Val=0x00000000)  Line 995 + 0xe bytes    
> C++
>        08f4f488()
>        osgrd.dll!__gl_renderCache(osg::GLUtesselator * tess=0x08f4f9b4)  Line 
> 493 + 0x1a bytes C++
>
> Cheers,
>
> Brad
>
> -----Original Message-----
> From: osg-users-boun...@lists.openscenegraph.org 
> [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of 
> Christiansen, Brad
> Sent: Wednesday, 13 October 2010 2:05 PM
> To: OpenSceneGraph Users
> Subject: [osg-users] Crash with SVN version of Tessellator
>
> Hi,
>
> I have just updated to the latest revision of OSG and am now getting a crash 
> when calling Tessellator.retessellatePolygons.
>
> The code in my application calling this function hasn't changed in many years 
> and has started breaking since the update. I have debugged the issue a little 
> and the crash is occuring when the Tessellator::endTessellation function is 
> called. The crash occurs on a call to free. I think I will need to do a full 
> debug build of OSG to get much further with my debuging (I am using release 
> with debug info) but a full rebuild will take me a while.
>
> The previous (working) version of OSG I used was revision 11703 and the new 
> (broken) revision is 11835.
>
> I know al the new GLU code has been added between these revision so I am 
> guessing that is what is causing the error. Before I go much further I was 
> wondering if anyone had any info that might help me track down the issue. It 
> doesn't seem that the required usage of Tessellator has changed but I am 
> hoping it has so I can simply call some different methods to fix the issue.
>
> Cheers,
>
> Brad
>
>
>
>
>
> DISCLAIMER:---------------------------------------------------------------------------
> This e-mail transmission and any documents, files and previous e-mail messages
> attached to it are private and confidential. They may contain proprietary or 
> copyright
> material or information that is subject to legal professional privilege. They 
> are for
> the use of the intended recipient only.  Any unauthorised viewing, use, 
> disclosure,
> copying, alteration, storage or distribution of, or reliance on, this message 
> is
> strictly prohibited. No part may be reproduced, adapted or transmitted 
> without the
> written permission of the owner. If you have received this transmission in 
> error, or
> are not an authorised recipient, please immediately notify the sender by 
> return email,
> delete this message and all copies from your e-mail system, and destroy any 
> printed
> copies. Receipt by anyone other than the intended recipient should not be 
> deemed a
> waiver of any privilege or protection. Thales Australia does not warrant or 
> represent
> that this e-mail or any documents, files and previous e-mail messages 
> attached are
> error or virus free.
> --------------------------------------------------------------------------------------
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
> DISCLAIMER:---------------------------------------------------------------------------
> This e-mail transmission and any documents, files and previous e-mail messages
> attached to it are private and confidential. They may contain proprietary or 
> copyright
> material or information that is subject to legal professional privilege. They 
> are for
> the use of the intended recipient only.  Any unauthorised viewing, use, 
> disclosure,
> copying, alteration, storage or distribution of, or reliance on, this message 
> is
> strictly prohibited. No part may be reproduced, adapted or transmitted 
> without the
> written permission of the owner. If you have received this transmission in 
> error, or
> are not an authorised recipient, please immediately notify the sender by 
> return email,
> delete this message and all copies from your e-mail system, and destroy any 
> printed
> copies. Receipt by anyone other than the intended recipient should not be 
> deemed a
> waiver of any privilege or protection. Thales Australia does not warrant or 
> represent
> that this e-mail or any documents, files and previous e-mail messages 
> attached are
> error or virus free.
> --------------------------------------------------------------------------------------
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



DISCLAIMER:---------------------------------------------------------------------------
This e-mail transmission and any documents, files and previous e-mail messages
attached to it are private and confidential. They may contain proprietary or 
copyright
material or information that is subject to legal professional privilege. They 
are for
the use of the intended recipient only.  Any unauthorised viewing, use, 
disclosure,
copying, alteration, storage or distribution of, or reliance on, this message is
strictly prohibited. No part may be reproduced, adapted or transmitted without 
the
written permission of the owner. If you have received this transmission in 
error, or
are not an authorised recipient, please immediately notify the sender by return 
email,
delete this message and all copies from your e-mail system, and destroy any 
printed
copies. Receipt by anyone other than the intended recipient should not be 
deemed a
waiver of any privilege or protection. Thales Australia does not warrant or 
represent
that this e-mail or any documents, files and previous e-mail messages attached 
are
error or virus free.
--------------------------------------------------------------------------------------

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



DISCLAIMER:---------------------------------------------------------------------------
This e-mail transmission and any documents, files and previous e-mail messages
attached to it are private and confidential. They may contain proprietary or 
copyright
material or information that is subject to legal professional privilege. They 
are for
the use of the intended recipient only.  Any unauthorised viewing, use, 
disclosure,
copying, alteration, storage or distribution of, or reliance on, this message is
strictly prohibited. No part may be reproduced, adapted or transmitted without 
the
written permission of the owner. If you have received this transmission in 
error, or
are not an authorised recipient, please immediately notify the sender by return 
email,
delete this message and all copies from your e-mail system, and destroy any 
printed
copies. Receipt by anyone other than the intended recipient should not be 
deemed a
waiver of any privilege or protection. Thales Australia does not warrant or 
represent
that this e-mail or any documents, files and previous e-mail messages attached 
are
error or virus free.
--------------------------------------------------------------------------------------

Attachment: GLU
Description: GLU

/*
 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice including the dates of first publication and
 * either this permission notice or a reference to
 * http://oss.sgi.com/projects/FreeB/
 * shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Except as contained in this notice, the name of Silicon Graphics, Inc.
 * shall not be used in advertising or otherwise to promote the sale, use or
 * other dealings in this Software without prior written authorization from
 * Silicon Graphics, Inc.
 */
/*
** Author: Eric Veach, July 1994.
**
*/

#ifndef __tess_h_
#define __tess_h_

// #include <GL/glu.h>
#include <osg/GLU>
 
#if defined(WIN32) && !defined(__CYGWIN__)
//Under windows need to ensure calling convention is consistent
#define GLAPIENTRY __stdcall
#else
// simply define GLAPIENTRY as nothing so that we can keep function signatures 
the same as declaration.
#define GLAPIENTRY
#endif

#include <setjmp.h>
#include "mesh.h"
#include "dict.h"
#include "priorityq.h"

/* The begin/end calls must be properly nested.  We keep track of
 * the current state to enforce the ordering.
 */
enum TessState { T_DORMANT, T_IN_POLYGON, T_IN_CONTOUR };

/* We cache vertex data for single-contour polygons so that we can
 * try a quick-and-dirty decomposition first.
 */
#define TESS_MAX_CACHE  100

typedef struct CachedVertex {
  GLdouble      coords[3];
  void          *data;
} CachedVertex;

struct osg::GLUtesselator {

  /*** state needed for collecting the input data ***/

  enum TessState state;         /* what begin/end calls have we seen? */

  GLUhalfEdge   *lastEdge;      /* lastEdge->Org is the most recent vertex */
  GLUmesh       *mesh;          /* stores the input contours, and eventually
                                   the tessellation itself */

  void          (GLAPIENTRY *callError)( GLenum errnum );

  /*** state needed for projecting onto the sweep plane ***/

  GLdouble      normal[3];      /* user-specified normal (if provided) */
  GLdouble      sUnit[3];       /* unit vector in s-direction (debugging) */
  GLdouble      tUnit[3];       /* unit vector in t-direction (debugging) */

  /*** state needed for the line sweep ***/

  GLdouble      relTolerance;   /* tolerance for merging features */
  GLenum        windingRule;    /* rule for determining polygon interior */
  GLboolean     fatalError;     /* fatal error: needed combine callback */

  Dict          *dict;          /* edge dictionary for sweep line */
  PriorityQ     *pq;            /* priority queue of vertex events */
  GLUvertex     *event;         /* current sweep event being processed */

  void          (GLAPIENTRY *callCombine)( GLdouble coords[3], void *data[4],
                                GLfloat weight[4], void **outData );

  /*** state needed for rendering callbacks (see render.c) ***/

  GLboolean     flagBoundary;   /* mark boundary edges (use EdgeFlag) */
  GLboolean     boundaryOnly;   /* Extract contours, not triangles */
  GLUface       *lonelyTriList;
    /* list of triangles which could not be rendered as strips or fans */

  void          (GLAPIENTRY *callBegin)( GLenum type );
  void          (GLAPIENTRY *callEdgeFlag)( GLboolean boundaryEdge );
  void          (GLAPIENTRY *callVertex)( void *data );
  void          (GLAPIENTRY *callEnd)( void );
  void          (GLAPIENTRY *callMesh)( GLUmesh *mesh );


  /*** state needed to cache single-contour polygons for renderCache() */

  GLboolean     emptyCache;             /* empty cache on next vertex() call */
  int           cacheCount;             /* number of cached vertices */
  CachedVertex  cache[TESS_MAX_CACHE];  /* the vertex data */

  /*** rendering callbacks that also pass polygon data  ***/ 
  void          (GLAPIENTRY *callBeginData)( GLenum type, void *polygonData );
  void          (GLAPIENTRY *callEdgeFlagData)( GLboolean boundaryEdge, 
                                     void *polygonData );
  void          (GLAPIENTRY *callVertexData)( void *data, void *polygonData );
  void          (GLAPIENTRY *callEndData)( void *polygonData );
  void          (GLAPIENTRY *callErrorData)( GLenum errnum, void *polygonData );
  void          (GLAPIENTRY *callCombineData)( GLdouble coords[3], void 
*data[4],
                                    GLfloat weight[4], void **outData,
                                    void *polygonData );

  jmp_buf env;                  /* place to jump to when memAllocs fail */

  void *polygonData;            /* client data for current polygon */
};


void GLAPIENTRY __gl_noBeginData( GLenum type, void *polygonData );
void GLAPIENTRY __gl_noEdgeFlagData( GLboolean boundaryEdge, void *polygonData 
);
void GLAPIENTRY __gl_noVertexData( void *data, void *polygonData );
void GLAPIENTRY __gl_noEndData( void *polygonData );
void GLAPIENTRY __gl_noErrorData( GLenum errnum, void *polygonData );
void GLAPIENTRY __gl_noCombineData( GLdouble coords[3], void *data[4],
                         GLfloat weight[4], void **outData,
                         void *polygonData );

#define CALL_BEGIN_OR_BEGIN_DATA(a) \
   if (tess->callBeginData != &__gl_noBeginData) \
      (*tess->callBeginData)((a),tess->polygonData); \
   else (*tess->callBegin)((a));

#define CALL_VERTEX_OR_VERTEX_DATA(a) \
   if (tess->callVertexData != &__gl_noVertexData) \
      (*tess->callVertexData)((a),tess->polygonData); \
   else (*tess->callVertex)((a));

#define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \
   if (tess->callEdgeFlagData != &__gl_noEdgeFlagData) \
      (*tess->callEdgeFlagData)((a),tess->polygonData); \
   else (*tess->callEdgeFlag)((a));

#define CALL_END_OR_END_DATA() \
   if (tess->callEndData != &__gl_noEndData) \
      (*tess->callEndData)(tess->polygonData); \
   else (*tess->callEnd)();

#define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) \
   if (tess->callCombineData != &__gl_noCombineData) \
      (*tess->callCombineData)((a),(b),(c),(d),tess->polygonData); \
   else (*tess->callCombine)((a),(b),(c),(d));

#define CALL_ERROR_OR_ERROR_DATA(a) \
   if (tess->callErrorData != &__gl_noErrorData) \
      (*tess->callErrorData)((a),tess->polygonData); \
   else (*tess->callError)((a));

// make it easy to introduce the namespace osg for the public functions and 
typedefs
using osg::GLUtesselator;
using osg::_GLUfuncptr;


#endif
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to