Gamestudio Links
Zorro Links
Newest Posts
[MED] Import from FBX (2010) missing!!!
by USER0328. 09/03/26 18:03
Purchase A8 full licence version
by ukgamer. 08/30/26 14:27
ZorroGPT
by TipmyPip. 08/29/26 06:56
Retrieve optimize() variables order (edited)
by NorbertSz. 08/25/26 13:24
Max Number of Strategies in /Strategy folder
by Martin_HH. 08/17/26 07:54
Pause button for evaluation shell?
by AndrewAMD. 08/13/26 17:16
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 08/10/26 12:46
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (AndrewAMD), 1,337 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Student_64151, Koti
19230 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Script Crash #411499
11/17/12 14:20
11/17/12 14:20
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
Code:
void SetTimer (int * p,int time,void * func)
{
	while(*p > 0)
	{
		wait((time * -1));
	}	
}



The above code is producing a Script Crash.

Additional:
Code:
Function Call:
SetTimer (SpeedRun_Time,1,NULL);

Variable:
int * SpeedRun_Time = sys_malloc(sizeof(int));



Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
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 Offline
Expert
Kartoffel  Offline
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 function

an int is always 4 bytes big. -> fixed-size -> no need to allocate memory. wink

(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: Kartoffel] #411507
11/17/12 14:45
11/17/12 14:45
Joined: Nov 2011
Posts: 139
India
Yashas Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
I made a pointer(I had planned my whole application in a few pages,I am doing it according to my plans) becaz I am going to switch between variables by assigning new addresses to it.Hence I have already declared it as a pointer. laugh laugh

Anyway Thanks laugh laugh laugh


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Quote:
[...] 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 Offline
Expert
Uhrwerk  Offline
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:
Code:
int i;
int* p = &i;



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 Offline
Expert
Kartoffel  Offline
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 Offline OP
Member
Yashas  Offline OP
Member

Joined: Nov 2011
Posts: 139
India
Code:
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.

Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
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 Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: Kartoffel
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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
you wrote [\code] instead of [/code] tongue

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 Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Code:
SpeedRun_Time = 60;


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...
Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1