Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++ stl]errore allocazione oggetto

    Ciao .
    Ho il seguente vector dichiarato come oggetto , non come puntatore come variabile membro-
    protected:
    std::vector<SpatialPtr> m_kChild;

    dove spatialPtr è uno smartpointer di una classe base da cui derivano molti oggetti , tra cui il mio

    Il problema è che a volte il debug me lo mostra cosi:
    m_kChild [0]()
    e tutto è ok,
    ma a volte me lo rappresenta cosi :
    m_kChild [...]()

    e sembra che non sia allocato(e non riesco a capire perchè) , infatti qualsiasi operazione che faccio sul vector mi ritorna un eccezione :
    m_kChild.size():
    Unhandled exception at 0x0062e7d9 in MaterialTextures_VC90WglDebSta.exe: 0xC0000005: Access violation reading location 0x00000120.

  2. #2
    1) Qual è la semantica di copia dello smart pointer in questione?
    2) Sicuro di non aver deallocato o paciugato in qualche altra maniera l'oggetto che contiene il vector?
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    si, ho paciugato in una qualche maniera , questa è la classe che contiene il vector:

    codice:
    
    class CMesh;
    
    namespace Wm4{
    typedef Pointer<CMesh> CMeshPtr;
    }
    
    class CMesh : public CNodeBase
    {
    public:
    	CMesh(void);
    	virtual ~CMesh(void);
    	Wm4::CMaterialBasePtr GetMaterial();
    	void SetMaterial(Wm4::CMaterialBasePtr pMaterial);
    	std::vector<tagPositionXYZ*> m_vPosition;
    	std::vector<NORMAL*> m_vNormals;
    	std::vector<TEXCOORD*> m_vTextureCoord;//coordinate texture front
    	std::vector<TEXCOORD*> m_vTextureCoordBack;//coordinte texture back
    	Wm4::CNodeBasePtr GetParent();
    	void SetParent(Wm4::CNodeBasePtr pNode);
    	void merge(Wm4::CMeshPtr pMesh);
    	void TransformPoints(Wm4::Matrix3f& rot, Wm4::Vector3f& tra);
    	void TransformUV(const ReadOffsets& Offset);
    	void TransformUVBack(const ReadOffsets& Offset);
    	void SaveTexture();
    	void NormalizeTextures(NormalizeTx& norm);
    	void CMesh::TransformUVBase(Wm4::Matrix3f Matrix);
    
    private:	
    	Wm4::CMaterialBasePtr m_pMaterial;
    	Wm4::CNodeBasePtr m_pParent;
    	Wm4::Matrix4f m_mxTransform;
    	bool m_bHaveAtlas;
    	std::string m_strTextureAtlas;
    	bool IsTiled();
    };
    e anche la classe che lo usa e dove mi da l'errore del vector è fatta cosi:
    [code]
    #pragma once
    #include "nodebase.h"
    #include <vector>
    #include "SketchUp_i.h"
    #include "material.h"
    #include "wm4matrix4.h"
    #include "wm4SmartPointer.h"
    #include "Mesh.h"
    class CBaseVisitor;

    using namespace Wm4;

    class CNodeImporter;

    namespace Wm4{
    typedef Pointer<CNodeImporter> NodeImporterPtr;
    }

    class CNodeImporter : public CNodeBase
    {
    public:
    CNodeImporter(void);
    virtual ~CNodeImporter(void);
    virtual void ClearParents();
    void Remove(const Wm4::CNodeBasePtr pNode);
    void Insert(Wm4::NodeImporterPtr pNode);
    void InsertMesh(CMeshPtr pMesh);
    Wm4::CMeshPtr GetMeshAt(long nPos);
    long GetMeshCount();
    Wm4::Matrix4f GetCurrentMatrix();
    CNodeBasePtr GetAt(int pos);
    void SetMatrixT(Matrix4f* pMatrix, double *pValue);
    Wm4::Matrix4f* GetmatrixT();
    void SetParent(NodeImporterPtr pNode);
    Wm4::NodeImporterPtr GetParent();
    long GetChildrenCount();

    bool AcceptVisitors(CBaseVisitor* pVisitor);
    ISkpDrawingElement* pDrawingElement;
    Wm4::Matrix4f* m_pTransformMatrix;
    Wm4::Matrix4f m_pTransformMatrixCurrent;
    Wm4::Vector3f* m_pVectTransl;
    std::vector< CMeshPtr > m_childMeshes;
    protected:
    std::vector< NodeImporterPtr> m_children;


    Wm4::NodeImporterPtr m_pParent;

    };

    [code]
    ho dovuto inserire il forward reference perchè la classe contiene a sua volta uno smart pointer dello stesso tipo , in effetti sono le uniche 2 classi che uso nel mio progetto con questa modifica , e l'unica che mi da questo genenere di errore.

    il vector è dichiarato cosi:
    std::vector<CMeshPtr> m_Vector;

    grazie.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.