fix storing of userdata address on 64 bits version
[scilab.git] / scilab / modules / graphic_objects / src / cpp / createGraphicObject.cpp
index 87ff10b..cf6d314 100644 (file)
@@ -19,6 +19,7 @@ extern "C"
 #include "FigureModel.h"
 #include "AxesModel.h"
 #include "CurrentSubwin.h"
+#include "api_scilab.h"
 }
 
 #include "CallGraphicController.hxx"
@@ -94,7 +95,18 @@ int createNewFigureWithAxes()
     if (iUserDataSize != 0)
     {
         int* pUserData = NULL;
+
         getGraphicObjectProperty(getFigureModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+
+        if(sizeof(void*) == 4) //32 bits
+        {
+            increaseValRef(NULL, (int*)*(int*)pUserData);
+        }
+        else //64 bits
+        {
+            increaseValRef(NULL, (int*)*(long long*)pUserData);
+        }
+
         setGraphicObjectProperty(id, __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
     }
 
@@ -125,6 +137,7 @@ int createFigure(int iDockable, int iMenubarType, int iToolbarType, int iDefault
     int* piUserDataSize = &iUserDataSize;
 
     id = Builder::createFigure(getScilabJavaVM(), iDockable != 0, iMenubarType, iToolbarType, iDefaultAxes != 0, iVisible != 0);
+
     //clone gdf user_data is needed
     getGraphicObjectProperty(getFigureModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
     if (iUserDataSize != 0)
@@ -153,7 +166,20 @@ void cloneMenus(int model, int newParent)
 
 int cloneAxesModel(int parent)
 {
-    return Builder::cloneAxesModel(getScilabJavaVM(), parent);
+    int id = Builder::cloneAxesModel(getScilabJavaVM(), parent);
+    int iUserDataSize = 0;
+    int* piUserDataSize = &iUserDataSize;
+
+    //clone user_data is needed
+    getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+        getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+        setGraphicObjectProperty(id, __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    return id;
 }
 
 int createSubWin(int parent)