View previous topic :: View next topic |
Author |
Message |
tijmenjoppe
Joined: 04 Jun 2009 Posts: 3
|
Posted: Thu Jun 04, 2009 14:39 Post subject: Problem initializing parameter with more than 15 chars |
|
|
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 |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Thu Jun 04, 2009 15:01 Post subject: |
|
|
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 |
|
|
tijmenjoppe
Joined: 04 Jun 2009 Posts: 3
|
Posted: Thu Jun 04, 2009 17:05 Post subject: |
|
|
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 |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
tijmenjoppe
Joined: 04 Jun 2009 Posts: 3
|
Posted: Thu Jun 04, 2009 21:37 Post subject: |
|
|
That led to the solution, thank you! |
|
Back to top |
|
|
|