Page 1 of 1

GE script pointer point to memory where allocat in function

PostPosted: Fri Feb 26, 2010 8:55 am
by linjichao
:oops:
i just define a function which is build-in function, the ge script side pass a point a pointer of pointer that in order to get the allocate memory where allocate in build-in function, the build-in function like this:
int getData(char** pp)
{
(*pp) = (char*)malloc(10);
memset((*pp), 0, 10);
return 1;
}

// ge script side call the build-in function
char* pData = NULL;
getData(&pData);
// then show the data to text of actor
strncpy(show.text, pData, 10);
//result is: nothing (blank)

// if use sprintf();
sprintf(show.text, "%s", pData);// like this:
// result is: access beyond allowed memory area where show in a pop dialog...

// i try to show the address of pData, and check address in vs2008,
// that already allocate data , i confuse...
// why i can't access memory that use a pointer to a allocate memory block which allocate in build-in function

Re: GE script pointer point to memory where allocat in function

PostPosted: Fri Feb 26, 2010 4:28 pm
by makslane
Are you creating a new function inside Game Editor code?
If yes, you need to pass arguments between the script and the engine by using the val_t type and setEp function.
Look, for example, the implementation of the eic_getclone function in the http://sourceforge.net/apps/trac/game-e ... Script.cpp file.

The function checkPtr in the file http://sourceforge.net/apps/trac/game-e ... interpre.c is used to check the memory limits.

Re: GE script pointer point to memory where allocat in function

PostPosted: Sat Feb 27, 2010 3:49 am
by linjichao
makslane wrote:Are you creating a new function inside Game Editor code?
If yes, you need to pass arguments between the script and the engine by using the val_t type and setEp function.
Look, for example, the implementation of the eic_getclone function in the http://sourceforge.net/apps/trac/game-e ... Script.cpp file.

The function checkPtr in the file http://sourceforge.net/apps/trac/game-e ... interpre.c is used to check the memory limits.


thanks a lot...