diff --git a/Engine/source/T3D/convexShape.cpp b/Engine/source/T3D/convexShape.cpp index 713f52ccd..622b28fa2 100644 --- a/Engine/source/T3D/convexShape.cpp +++ b/Engine/source/T3D/convexShape.cpp @@ -367,7 +367,14 @@ void ConvexShape::writeFields( Stream &stream, U32 tabStop ) stream.write(2, "\r\n"); - for ( U32 i = 0; i < mSurfaces.size(); i++ ) + S32 count = mSurfaces.size(); + if ( count > smMaxSurfaces ) + { + Con::errorf( "ConvexShape has too many surfaces to save! Truncated value %d to maximum value of %d", count, smMaxSurfaces ); + count = smMaxSurfaces; + } + + for ( U32 i = 0; i < count; i++ ) { const MatrixF &mat = mSurfaces[i]; @@ -423,12 +430,18 @@ U32 ConvexShape::packUpdate( NetConnection *conn, U32 mask, BitStream *stream ) if ( stream->writeFlag( mask & UpdateMask ) ) { stream->write( mMaterialName ); - - const U32 surfCount = mSurfaces.size(); + + U32 surfCount = mSurfaces.size(); stream->writeInt( surfCount, 32 ); - for ( S32 i = 0; i < surfCount; i++ ) - mathWrite( *stream, mSurfaces[i] ); + for ( S32 i = 0; i < surfCount; i++ ) + { + QuatF quat( mSurfaces[i] ); + Point3F pos( mSurfaces[i].getPosition() ); + + mathWrite( *stream, quat ); + mathWrite( *stream, pos ); + } } return retMask; @@ -462,7 +475,14 @@ void ConvexShape::unpackUpdate( NetConnection *conn, BitStream *stream ) mSurfaces.increment(); MatrixF &mat = mSurfaces.last(); - mathRead( *stream, &mat ); + QuatF quat; + Point3F pos; + + mathRead( *stream, &quat ); + mathRead( *stream, &pos ); + + quat.setMatrix( &mat ); + mat.setPosition( pos ); } if ( isProperlyAdded() ) diff --git a/Engine/source/T3D/convexShape.h b/Engine/source/T3D/convexShape.h index ed9f23d2e..d0f30eeaa 100644 --- a/Engine/source/T3D/convexShape.h +++ b/Engine/source/T3D/convexShape.h @@ -141,6 +141,10 @@ public: static bool smRenderEdges; + // To prevent bitpack overflows. + // This is only indirectly enforced by trucation when serializing. + static const S32 smMaxSurfaces = 100; + public: ConvexShape(); diff --git a/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp b/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp index f0d41f423..00245376e 100644 --- a/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp +++ b/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp @@ -871,10 +871,17 @@ void GuiConvexEditorCtrl::renderScene(const RectI & updateRect) text = "Scale face."; } } + + // Issue a warning in the status bar + // if this convex has an excessive number of surfaces... + if ( mConvexSEL && mConvexSEL->getSurfaces().size() > ConvexShape::smMaxSurfaces ) + { + text = "WARNING: Reduce the number of surfaces on the selected ConvexShape, only the first 100 will be saved!"; + } Con::executef( statusbar, "setInfo", text.c_str() ); - Con::executef( statusbar, "setSelectionObjectsByCount", Con::getIntArg( mConvexSEL == NULL ? 0 : 1 ) ); + Con::executef( statusbar, "setSelectionObjectsByCount", Con::getIntArg( mConvexSEL == NULL ? 0 : 1 ) ); } if ( mActiveTool )