Jump to content

[SOLVED] Unigine::Ptr + Qt


photo

Recommended Posts

For example :  QMap <int, Unigine::ObjectMeshDynamicPtr> or QVector <Unigine::ImagePtr>

Node *createNode(const Key &k, const T &v, Node *parent = 0, bool left = false)
    {
        Node *n = static_cast<Node *>(QMapDataBase::createNode(sizeof(Node), Q_ALIGNOF(Node),
                                      parent, left));
        QT_TRY {
            new (&n->key) Key(k);
            QT_TRY {
                new (&n->value) T(v); // error
            } QT_CATCH(...) {
                n->key.~Key();
                QT_RETHROW;
            }
        } QT_CATCH(...) {
            QMapDataBase::freeNodeAndRebalance(n);
            QT_RETHROW;
        }
        return n;
    }
Link to comment

Well, Unigine::Ptr class has its own placement new and delete operators, please check UniginePtr.h file, line 126:

UNIGINE_DECLARE_USE_MEMORY

That macro contained all placement new & delete operator declarations. File UnigineBase.h, line 125

#define UNIGINE_DECLARE_USE_MEMORY \
static UNIGINE_INLINE void *operator new(size_t size) { return Unigine::Memory::allocate(size); } \
static UNIGINE_INLINE void *operator new[](size_t size) { return Unigine::Memory::allocate(size); } \
static UNIGINE_INLINE void operator delete(void *ptr) { Unigine::Memory::deallocate(ptr); } \
static UNIGINE_INLINE void operator delete[](void *ptr) { Unigine::Memory::deallocate(ptr); } \
static UNIGINE_INLINE void operator delete(void *ptr,size_t size) { Unigine::Memory::deallocate(ptr,size); } \
static UNIGINE_INLINE void operator delete[](void *ptr,size_t size) { Unigine::Memory::deallocate(ptr,size); }

So I'm not sure if the problem is related to missed placement new operator.

Link to comment

Yes, this all about UNIGINE_DECLARE_USE_MEMORY, we are comment it & now it works for us. but somehow placement new operator is not present when other new operators has overloaded. i am not sure, but it is not possible to overload placement new operator in c++. so, is commenting UNIGINE_USE_MEMORY good solution?

Link to comment

Sergey,

 

Commenting UNIGINE_DECLARE_USE_MEMORY is definitely not a good solution as it may lead you into some serious memory corruptions, especially if you're going to create nodes and share them between UnigineScript and C++.

Link to comment
  • 1 month later...

Hi Sergey,

 

If I understand you correctly, the minimal reproduction sample will be something like this:

#include <QVector>
#include <QMap>
#include <UnigineNode.h>

using namespace Unigine;

void my_func(){
    QVector<Unigine::NodePtr> nodes;
    nodes.append(Unigine::NodePtr(NULL));
    QMap<Unigine::NodePtr,int> nodes2;
    nodes2.insert(Unigine::NodePtr(NULL), 1);
}

int main() {
    my_func();
}

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
  • 3 months later...
×
×
  • Create New...