segmentation fault

41 views
Skip to first unread message

3rdshiftcoder -

unread,
Mar 4, 2012, 5:19:24 PM3/4/12
to haxe...@googlegroups.com
Hi-

Is there anything that jumps off the page that is causing a segmentation fault for my library when i run .n that calls .ndll?
thanks, I read that it is caused by  a reference to an object that doesnt get freed.
jim


#define IMPLEMENT_API
#include <C:/Motion-Twin/haxe/lib/hxcpp/2,08,1/include/hx/CFFI.h>
#include<c:/Motion-Twin/haxe/lib/hxcpp/2,08,1/include/hxcpp.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "vacation.h"



<code haxe>
void myFinalizer(void* abstract_object){
     hx::Object *obj = (hx::Object *) abstract_object;
     void * np;
     np =  obj->__GetHandle();
     // get the pointer to the native instance
     free(np); // free resources
}


value GetServiceContainer(int number ){
        printf("%s", "foo_");
        vector<Credit> * tier(0);
        Credit Street1(104,8,1,200,400); // >=20
        Credit Street2(104,8,2,152,304); //11-19
        Credit Street3(104,8,3,136,272); //6-10
        Credit Street4(70,0,0,70,140); // 1-5
        // add rest of tier vacation data
       
       
        switch(number)
        {
        case 1: // std::cout << "you will retire in a gated community\n";
                break;
            case 2:  tier->push_back(Street2); //std::cout<<"tier2\n";
                break;
            case 3: tier->push_back(Street3); //std::cout<<"tier3\n";
                break;
            case 4: tier->push_back(Street4); //std::cout<<"tier4\n";
                break;
            default: //std::cout<< "no higher tier in current manual";
                break;
               
               
        }
       
        CAN * molson;
       
        molson = (CAN*) malloc(sizeof(CAN));
        molson->beer = tier;
        //printf("%d",tier[0]->vAnnual);
        value abstract_object = alloc_abstract(myContainer, molson);  
         val_gc(abstract_object, ((hxFinalizer) &myFinalizer));
          return abstract_object;
     
       
}
</code>


Hugh

unread,
Mar 4, 2012, 7:54:38 PM3/4/12
to haXe
Hi,
Did you mean?
vector<Credit> * tier(0);

Is a null pointer? vector<Credit> * tier( new vector<Credit>(0) );
Seems it may also be easier to not be a pointer, just:
vector<Credit> tier(0);
The use "." instead of "->" and all the memory tracking issues go
away.

Hugh

3rdshiftcoder -

unread,
Mar 5, 2012, 6:14:39 PM3/5/12
to haxe...@googlegroups.com
hi Hugh-

I don't see my thread where I replied back to you. It basically said very cool and
that is the example I needed to continue.

thanks,
jim
Reply all
Reply to author
Forward
0 new messages