Re: Program Crashes

new topic     » goto parent     » topic index » view thread      » older message » newer message
xecronix said...
Icy_Viking said...

Hello,

Whenver I try to launch an executable file from my program, it crashes. I have it so that you can launch .exe files from within the program, but when trying to launch them, my program crashes. Here is my code. Maybe I'm not loading it correctly?

procedure Launched(integer self, integer event, sequence parm) 
 
	parm = getOpenFileName(MainWin,"",{"Exe Files","*.exe"}) 
	 
	if parm = -1 then 
		self = message_box("Could not open file!","File",MB_OK) 
		else 
		x = system_exec(parm,0) 
	end if 
	 
	if x = -1 then 
		self = message_box("Could not launch game","Launcher",MB_OK) 
		elsif x = 0 then 
			times_game_played += 1 
	end if 
	 
end procedure 
setHandler(Launch_Game,w32HClick,routine_id("Launched")) 
 
 

I can post more code if it is needed.

This looks like a windows program and I may not be much help... but I'll try. There are some interesting things going on in this code.

  1. The variable "self" is reassigned and then never used.
  2. The variable "event" is passed in but never used.
  3. The variable "param" is passed in as a sequence and then an attempt to reassign it to an integer (or atom) was made. This may be your bug.

-xecronix

Hi

self and event are general purpose variables, used by other functions / procedures within win32lib - they don't need to be used, but are indicators for other things going on. For instance event could be mouse_move, or r_click.

parm is a sequence of params that the programmer passes to the function. For some reason it was called parm and not params when win32lib forst written, much like for some reason unmount was called umount in Linux, to save one character.

parm should be a sequence, but to be extra safe, this is testing for a -1, so the sequence parm should be object parm - doesn't matter whether a sequence or integer is passed then.

However, if parm is a sequence, it will ALWAYS crash if a sequence is passed. Correctly, you should first test for it being an integer before testing what value the integer is, so

if integer(parm) and if parm = -1 then

or

if sequence(parm) then

<<

also, getopenfilename is passing a sequence into an integer variable - use object instead.

If you want to have a quick look at what parm is, use

puts(1, parm)

Cheers

Chris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu