1 registered members (TipmyPip),
18,619
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
empty pointer
#387369
11/17/11 16:54
11/17/11 16:54
|
Joined: May 2008
Posts: 113 Italien, Südtirol, Naturns
Patrick92
OP
Member
|
OP
Member
Joined: May 2008
Posts: 113
Italien, Südtirol, Naturns
|
hallo wiso kommt hier ein empty pointer odr ein crash in bone_lange fehler?
function bone_lange(ENTITY* ENT, STRING* BONE_1,var lang,var dicke,var hoch,var beginn_abstand) { VECTOR* BONE_VEC; ANGLE* BONE_ANG; ENTITY* quant1; quant1 = ent_create("mod1quant.mdl",BONE_VEC,NULL); c_updatehull(quant1,1); while(1) { vec_for_bone(BONE_VEC,ENT,BONE_1); ang_for_bone(BONE_ANG,ENT,BONE_1); if(quant1 != NULL) { quant1.scale_x = lang; quant1.scale_y = dicke; quant1.scale_z = hoch; vec_set(quant1.pan,BONE_ANG); } wait(1); }
}
|
|
|
Re: empty pointer
[Re: Patrick92]
#387370
11/17/11 17:12
11/17/11 17:12
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Weil du keinen Speicher für BONE_VEC und BONE_ANG allozierst.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: empty pointer
[Re: WretchedSid]
#387400
11/18/11 07:24
11/18/11 07:24
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Oder mit den Worten eines Laien wie mir ausgedrückt: BONE_VEC hat in dieser Zeile noch keinen Wert: "quant1 = ent_create("mod1quant.mdl",BONE_VEC,NULL); " Du kannst das Zuweisen von einer generellen Funktionmachen lassen: "#define PRAGMA_ZERO Initializes all local variables to 0. This makes function execution a little slower, but gives all variables a fixed starting value. Good for quick testing whether a random problem is related to an uninitialized local variable. " http://www.conitec.net/beta/define.htmOder Du musst etwas Ähnliches wie dieses hinter die Deklaration schreiben: vec_set(BONE_VEC, nullveector); vec_set(BONE_ANG, nullveector);
|
|
|
Re: empty pointer
[Re: Pappenheimer]
#387410
11/18/11 11:47
11/18/11 11:47
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Dann fehlt aber immer noch der Speicher, du hast nur jetzt stattdessen Pointer die auf NULL zeigen  Protipp: vec_create() nutzen oder ganz auf den Pointer verzichten.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: empty pointer
[Re: WretchedSid]
#387414
11/18/11 12:22
11/18/11 12:22
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Du meinst ohne das Sternchen: VECTOR BONE_VEC; ANGLE BONE_ANG; EDIT: BTW, in Lite-C you don't need to allocate the VECTOR* pointer. This at least works:
VECTOR* sca;
vec_zero(sca);
ent_create(CUBE_MDL, sca, NULL);
Here the article from the manual: Always initialize variables In C-Script, uninitialized local variables (like var myvar;) were automatically initialized to zero. Not anymore. You now should to either initialize variables in the definition (like var myvar = 0;), or leave them uninitalized only when their inital value does not matter. Because structs can not be initialized in their definition, use the zero() macro (defined in acknex.h) for initalizing local or global structs to zero, and vec_zero() for initializing vectors consisting of 3 vars:
VECTOR speed;
vec_zero(speed); // initializes the VECTOR "speed" to x=0,y=0,z=0
For migration and testing, lite-C can automatically initialize all local variables to zero with the PRAGMA_ZERO definition. If you add
#define PRAGMA_ZERO // initialize variables
at the beginning of your script, all uninitialized global and local variables are set to zero. This slows down function calls a little, so it's preferable not to to use PRAGMA_ZERO in your final version. Global variables and structs are still automatically initialized to zero in lite-C, but you should make it a habit to give their initial values nevertheless. Check vectors and arrays In C-Script, we could use x, y, z elements for var arrays. In lite-C there's the VECTOR struct. So for using x, y, z elements, and for calling engine functions that expect VECTOR* pointers, you now need to define a VECTOR* rather than a var[3]:
var vSpeed[3] = 10,20,30; // C-Script var vSpeed[3] = { 10,20,30 }; // lite-C - address with [0], [1], [2] VECTOR* vSpeed = {x=10;y=20;z=30;} // lite-C - address with .x, .y, .z
!! The wrong use of arrays can lead to trouble when converting a script. In C-Script, the name of an array was equivalent to its first element; in C it's the address of the array. So the following code has correct syntax, but leads to different results in C-Script and lite-C:
var my_vector[3]; ... var x = my_vector; // C-Script: x is set to the first array element var x = my_vector; // lite-C - wrong: x is set to the array pointer! var x = my_vector[0]; // lite-C - correct: x is set to the first array element http://www.conitec.net/beta/litec_migration.htm
Last edited by Pappenheimer; 11/18/11 12:40.
|
|
|
Re: empty pointer
[Re: Patrick92]
#387416
11/18/11 12:42
11/18/11 12:42
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
Declaring global struct pointers (f.i. VECTOR* v = {x=1;y=2;z=3;} ) //inside functions will now issue an error message. Try outside like this:
#include <default.c>
VECTOR* BONE_VEC = {x=0;y=0;z=0;}
ANGLE* BONE_ANG = {x=0;y=0;z=0;}
ENTITY* ent1;
function bone_lange(ENTITY* ENT, STRING* BONE_1,var lang,var dicke,var hoch,var beginn_abstand)
{
//VECTOR* BONE_VEC
//ANGLE* BONE_ANG;
ENTITY* quant1;
quant1 = ent_create(SPHERE_MDL,BONE_VEC,NULL);
c_updatehull(quant1,1);
while(1)
{
//vec_for_bone(BONE_VEC,ENT,BONE_1);
//ang_for_bone(BONE_ANG,ENT,BONE_1);
if(quant1 != NULL)
{
quant1.scale_x = lang;
quant1.scale_y = dicke;
quant1.scale_z = hoch;
vec_set(quant1.pan,BONE_ANG);
}
wait(1);
}
}
function main()
{
level_load("");
vec_set(camera.x,vector(-850,0,50));
bone_lange(ent1, "bone",10,20,30,40);
}
|
|
|
Re: empty pointer
[Re: rojart]
#387419
11/18/11 12:55
11/18/11 12:55
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Declaring global struct pointers (f.i. VECTOR* v = {x=1;y=2;z=3;} ) //inside functions will now issue an error message. That's odd. You're right, it is in the beta page, but I tried my example in 8.10, and no error message.
|
|
|
Re: empty pointer
[Re: Pappenheimer]
#387422
11/18/11 13:24
11/18/11 13:24
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
BTW, in Lite-C you don't need to allocate the VECTOR* pointer. This at least works: Code: VECTOR* sca; vec_zero(sca); ent_create(CUBE_MDL, sca, NULL); Wieso sollte man das nicht müssen?
Last edited by Superku; 11/18/11 13:26.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: empty pointer
[Re: Pappenheimer]
#387435
11/18/11 15:55
11/18/11 15:55
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
Du meinst ohne das Sternchen: VECTOR BONE_VEC; ANGLE BONE_ANG; EDIT: BTW, in Lite-C you don't need to allocate the VECTOR* pointer. This at least works: 0 Genial, einfach von einem Satz zum nächsten die Sprache wechseln ^^
VECTOR* sca;
vec_zero(sca);
ent_create(CUBE_MDL, sca, NULL);
this will work, but you are overwriting 12 bytes of RAM with zeros if you remove vec_zero, you'll get a random memory sequence in RAM which now represents this vector you have to create the vector or simple don't use a pointer for a local, temporary variable
|
|
|
Re: empty pointer
[Re: MasterQ32]
#387436
11/18/11 15:57
11/18/11 15:57
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
...in the worst case. In the best case your program crashes. Working with unallocated memory is a horrible idea!
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|