1 registered members (AndrewAMD),
14,661
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Script Crash
#411499
11/17/12 14:20
11/17/12 14:20
|
Joined: Nov 2011
Posts: 139 India
Yashas
OP
Member
|
OP
Member
Joined: Nov 2011
Posts: 139
India
|
void SetTimer (int * p,int time,void * func)
{
while(*p > 0)
{
wait((time * -1));
}
}
The above code is producing a Script Crash. Additional:
Function Call:
SetTimer (SpeedRun_Time,1,NULL);
Variable:
int * SpeedRun_Time = sys_malloc(sizeof(int));
|
|
|
Re: Script Crash
[Re: Yashas]
#411503
11/17/12 14:38
11/17/12 14:38
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
I'm not sure why it crashes but you don't need: int * SpeedRun_Time = sys_malloc(sizeof(int)); simply using int SpeedRun_Time = 0; works. remember, you only have to use pointers and allocate memory to them if you are initializing somthing which has got a dynamic size (like dynamic array-sizes) or a non-fixed size (like BMAP* or STRING*) inside a functionan int is always 4 bytes big. -> fixed-size -> no need to allocate memory.  (But since I don't know that much about pointers/arrays/memory allocation, someone please correct me if I'm wrong)
Last edited by Kartoffel; 11/17/12 14:41.
POTATO-MAN saves the day! - Random
|
|
|
Re: Script Crash
[Re: Yashas]
#411511
11/17/12 14:51
11/17/12 14:51
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
[...] becaz I am going to switch between variables by assigning new addresses to it [...] ...I'm sorry but does this make any sense?
POTATO-MAN saves the day! - Random
|
|
|
Re: Script Crash
[Re: Yashas]
#411512
11/17/12 14:52
11/17/12 14:52
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Kartoffel, you're right about this point. Yashas, of course you can do it like this, but it very unusual and even does not clearly express what you intend to do. A clearer approach without malloc: To the crash: I do not understand why you post about a script crash but conceal the error message from us. Please note that the while loop while never gets executed as the memory area SpeedRun_Time points to is zero, unless you have intialized it to something else somehwere else.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Script Crash
[Re: Uhrwerk]
#411516
11/17/12 14:57
11/17/12 14:57
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
well If he uses int * SpeedRun_Time as first parameter in SetTimer isn't p then a pointer to a pointer to an allocated memory block? Maybe that's the problem...
Last edited by Kartoffel; 11/17/12 14:57.
POTATO-MAN saves the day! - Random
|
|
|
Re: Script Crash
[Re: Uhrwerk]
#411517
11/17/12 14:57
11/17/12 14:57
|
Joined: Nov 2011
Posts: 139 India
Yashas
OP
Member
|
OP
Member
Joined: Nov 2011
Posts: 139
India
|
void SpeedRun_GoGoGo ()
{
BMAP * SpeedRun_TEMP;
int SpeedRun_i = integer(random(6));
int SpeedRun_Row = 1;
int SpeedRun_Trys = 0;
int SpeedRun_Wrong = 0;
SpeedRun_TEMP = SpeedRun_Shapes[SpeedRun_i];
SpeedRun_Previous = SpeedRun_i;
pan_setwindow(SpeedRun_ControlsPlaying,1,200,150,200,200,SpeedRun_TEMP,200,200);
pan_setstring(SpeedRun_ControlsPlaying,4,-100,-100,"",str_create(""));
pan_setbutton(SpeedRun_ControlsPlaying,1,0,-100,-100,bmap_create("button1.tga"),bmap_create("button1.tga"),bmap_create("button1.tga"),NULL,NULL,NULL,NULL);
SpeedRun_Time = 60;
SetTimer (SpeedRun_Time,1,NULL);
while(SpeedRun_Time != 0)
{
if(key_cur)//Same
{
if(SpeedRun_Previous == SpeedRun_i)
{
//Correct
//AddUserXP(2);
SpeedRun_Score += 5 * SpeedRun_Row;
SpeedRun_Row++;
}
else
{
//Wrong
}
}
else if (key_cul) //Not Same
{
if(SpeedRun_Previous == SpeedRun_i)
{
//Wrong
}
else
{
//Correct
}
}
wait(1);
}
}
The complete code which will help understand better. And SpeedRun_Time is initialized with a value. The Error is "Script Crash in SetTimer" and then Windows notifies "acknex.exe has stopped working...".
Last edited by Yashas; 11/17/12 15:02.
|
|
|
Re: Script Crash
[Re: Kartoffel]
#411521
11/17/12 15:01
11/17/12 15:01
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
well If he uses int * SpeedRun_Time as first parameter in SetTimer isn't p then a pointer to a pointer to an allocated memory block? No. The function expects a pointer to an int and that's exactly what it gets.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Script Crash
[Re: Uhrwerk]
#411524
11/17/12 15:06
11/17/12 15:06
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
you wrote [\code] instead of [/code]  and if it says 'Crash in (function name)' have a look at the lines before this function gets called. It often says Crash in... but the mistake is in some of the previous lines of code.
Last edited by Kartoffel; 11/17/12 15:07.
POTATO-MAN saves the day! - Random
|
|
|
Re: Script Crash
[Re: Uhrwerk]
#411526
11/17/12 15:06
11/17/12 15:06
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
That is wrong. SpeedRun_Time is a pointer. You write the address 60 to that pointer. What you intended to do was setting the integer value SpeedRun_Time was pointing to, right?
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|