GE script pointer point to memory where allocat in function

Questions, comments and discussion about the Game Editor development.

GE script pointer point to memory where allocat in function

Postby linjichao » Fri Feb 26, 2010 8:55 am

: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
linjichao
 
Posts: 35
Joined: Fri Jan 22, 2010 10:13 am
Score: 0 Give a positive score

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

Postby makslane » Fri Feb 26, 2010 4:28 pm

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.
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

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

Postby linjichao » Sat Feb 27, 2010 3:49 am

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...
linjichao
 
Posts: 35
Joined: Fri Jan 22, 2010 10:13 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest