|
6 registered members (AndrewAMD, madpower2000, Quad, VoroneTZ, TipmyPip, 1 invisible),
1,674
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: STRING* and external plugins
[Re: jcl]
#323922
05/18/10 12:38
05/18/10 12:38
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Thanks for your answer! I did some more tests: The problem only occures with overloaded functions. Example: Lite-C:
void exSample_function(STRING* str);
void exSample_function(char* str) {exSample_function(_str(str));}
void main()
{
STRING* test_str = str_create("#10");
str_cpy(test_str,"TEST");
exSample_function(test_str);
}
C++:
DLLFUNC void exSample_function(STRING* str)
{
char str_as_char[10];
strcpy(str_as_char,str->chars);
//str_as_char is NOT filled with the correct content
//only with random symbols
}
str_as_char is filled with wrong content now (checked with the C++ Debugger). This worked with A7.82. After removing the char* prototype it works as before. And another thing I came over: If I'm calling a function: C++:
void exSample_function(STRING* teststr)
{
if(strlen(_CHR(password)) > 0) //causes a crash now
}
Causes a crash because password is not an empty string but an empty pointer. Worked in A7.82 also.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: STRING* and external plugins
[Re: Dark_samurai]
#323937
05/18/10 13:51
05/18/10 13:51
|
Joined: Jul 2000
Posts: 28,126 Frankfurt
jcl

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 28,126
Frankfurt
|
Ok, I see problems in that code that most likely explain the crashes. "" is not a STRING. It's just a char* pointer pointing to a 0 byte. This is C/C++ standard. I suppose your _CHR function can not handle this and crashes. For converting a STRING* to a char*, just use the proper conversion: http://manual.3dgamestudio.net/_chr.htmThis won't crash. Overloading won't do because engine functions make no difference between char* and STRING*. Otherwise, users had to overload all their STRING* functions - I think most would not like that.
|
|
|
Re: STRING* and external plugins
[Re: jcl]
#323945
05/18/10 15:02
05/18/10 15:02
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
_CHR is a Macro from the SDK not a function I made: adll.h:
inline char* _CHR(STRING* s) { return s->chars; } // STRING* -> char
But you're right it crashes because I'm passing a char* instead of a STRING*. It works if I convert the char* to a STRING* with _str(""). Overloading won't do because engine functions make no difference between char* and STRING*. Otherwise, users had to overload all their STRING* functions - I think most would not like that.
So that behavior was changed since A7.82? Because with A7.82 everything went out fine... Is this the correct way how it should be done? Lite-C:
void exSample_function(STRING* str);
void main()
{
STRING* test_str = str_create("#10");
str_cpy(test_str,"TEST");
exSample_function(test_str);
exSample_function("Blabla"); //works also with char now
}
C++:
void exSample_function(STRING* str)
{
char* temp_str;
temp_str = _chr(str);
}
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: STRING* and external plugins
[Re: jcl]
#324351
05/20/10 13:46
05/20/10 13:46
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Thanks for the info!
Edit: "the char* string must be null-terminated and contain at least 3 characters"
And what is with char* strings with less then 3 characters? It's required that those are also supported...
Last edited by Dark_samurai; 05/20/10 13:52.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: STRING* and external plugins
[Re: Dark_samurai]
#325388
05/26/10 11:48
05/26/10 11:48
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
"the char* string must be null-terminated and contain at least 3 characters"
And what is with char* strings with less then 3 characters? It's required that those are also supported...
Any chance that this limtation will be changed?
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|