logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Problem initializing parameter with more than 15 chars

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support
View previous topic :: View next topic  
Author Message
tijmenjoppe



Joined: 04 Jun 2009
Posts: 3

PostPosted: Thu Jun 04, 2009 14:39    Post subject: Problem initializing parameter with more than 15 chars Reply with quote

Hello everyone,

I seem to run into a very basic problem, but I wasn't able to find an ready-made answer. After creating my own NWN extension, I seem to have a problem with the returning char* Parameters in the OnRequest method. If I initialize it with more than 15 characters, the Neverwinter Nights server crashes. For example:

Code:

char* CNWNXSamuraiPlugin::OnRequest(char *gameObject, char* Request, char* Parameters)
{
    string sSendLine = "string with more than 15 chars";
    sprintf(Parameters, "%s", sSendLine.c_str());
    return NULL;
}


I use Neverwinter Nights 1.68.8099 and NWNX2 2.6.1. I compile my extension using VS C++ 2008 Express Edition (9.0.30729.1 SP).

Can anyone tell me how to return more than 15 characters?

Thanks in advance,
Tijmen
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Thu Jun 04, 2009 15:01    Post subject: Reply with quote

The Parameters string is a pointer to pre-allocated memory. Seems like you've passed 15 bytes as a SetLocalString value, so you can't write more than 15 bytes.
You can either use a longer spacer or allocate a new memory with malloc(), write your message there and use it as a return value.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tijmenjoppe



Joined: 04 Jun 2009
Posts: 3

PostPosted: Thu Jun 04, 2009 17:05    Post subject: Reply with quote

Hello virusman,

Thank you for your quick reply. I understand your solution, but I'm not yet clear on how to implement this; aren't the provided methods (within NWN scripting and the NWNX extensions) default? (I'm not aware that I "passed 15 bytes as a SetLocalString value".) In other words: how would I be able to allocate more memory for a return string?

Thanks again,
Tijmen
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Thu Jun 04, 2009 18:10    Post subject: Reply with quote

An example of first approach:
http://nwn.virusman.ru/trac/nwnx2-linux/browser/trunk/plugins/functions/NWNXFunction.cpp#L299
An example of second approach:
http://nwn.virusman.ru/trac/nwnx2-linux/browser/trunk/plugins/functions/NWNXFunction.cpp#L385
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tijmenjoppe



Joined: 04 Jun 2009
Posts: 3

PostPosted: Thu Jun 04, 2009 21:37    Post subject: Reply with quote

That led to the solution, thank you!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group