Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 1,170 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[SOLVED]Pixel_to_vec() is crashing engine? #348697
11/29/10 17:44
11/29/10 17:44
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
Hi!

I am attempting to write an sub-routine that will read a pixel from a bitmap based on the position of the mouse and give me a return value based on the color of that pixel. here is what I have so far:

function get_pixel_color()
{var x_coord = integer(mouse_pos.x*(bmap_width(my_bmap)/screen_size.x));
var y_coord = integer(mouse_pos.y*(bmap_height(my_bmap)/screen_size.y));
var pixel;
COLOR* pixel_color;
if(x_coord>bmap_width(my_bmap)||x_coord<0) { return(-1); }
if(y_coord>bmap_height(my_bmap)||y_coord<0) { return(-1); }
bmap_lock(my_bmap,0);
pixel = pixel_for_bmap(my_bmap,x_coord,y_coord);
bmap_unlock(my_bmap);
pixel_to_vec(pixel_color,NULL,8888,pixel);
if(pixel_color.red)
{ if(pixel_color.red>245&&pixel_color.red<255)
{ return(0);
}
}
return(-1)
}

The routine works fine - x_coord and y_coord are always co-ordinates within the bmap and pixel_for_bmap() is returning the pixel it is supposed to. However, when I execute the pixel_to_vec() command, the game crashes.

I tested the return value from bmap_lock and it is 8888, indicating that it is locking a 32-bit tga file with an alpha channel - which is curious becuse the bmap im reading from was created in photshop and saved as a 24-bit tga file with no alpha channel.

Am I feeding pixel_to_vec a bad pixel value? or maybe im feeding some bad value for one of the other parameters? Is bmap_lock misreading the bmap and thats whats causing problems? why would pixel_to_vec() crash the engine like this?



Last edited by Caermundh; 11/30/10 05:39.
Re: Pixel_to_vec() is crashing engine? [Re: Caermundh] #348698
11/29/10 18:00
11/29/10 18:00
Joined: Nov 2009
Posts: 201
Logitek Offline
Member
Logitek  Offline
Member

Joined: Nov 2009
Posts: 201
Have you tried it also with bmp?

Re: Pixel_to_vec() is crashing engine? [Re: Logitek] #348704
11/29/10 18:44
11/29/10 18:44
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
I will try that and let you know

Re: Pixel_to_vec() is crashing engine? [Re: Caermundh] #348705
11/29/10 18:47
11/29/10 18:47
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
Yes...my_bmap.bmp crashes on the pixel_to_vec() just the same as my_bmap.tga.

Re: Pixel_to_vec() is crashing engine? [Re: Caermundh] #348731
11/29/10 23:07
11/29/10 23:07
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
1st guess... you've using .red instead of .blue (i know... thank you Conitec!) i'll have a look more if that doesn't solve it

Re: Pixel_to_vec() is crashing engine? [Re: MrGuest] #348735
11/29/10 23:26
11/29/10 23:26
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
Sorry....i dont understand, .red instead of .blue? I'm feeding pixel_color to the function, not pixel_color.red or pixel_color.blue. I use if(pixel_color.red) after calling pixel_to_vec() to determine if there is any red in the pixel that is read from the bitmap. The program is crashing when it calls pixel_to_vec(), not when it tries to evaluate if(pixel_color.red).

Re: Pixel_to_vec() is crashing engine? [Re: Caermundh] #348738
11/30/10 00:00
11/30/10 00:00
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
sorry only read half the thread.

Should
var x_coord = integer(mouse_pos.x*(bmap_width(my_bmap)/screen_size.x));
be
var x_coord = integer(mouse_pos.x+[(bmap_width(my_bmap)/screen_size.x));

I'm using a function (hopefully) similar to what you're trying to achieve
Code:
void av_colorChange(var id, PANEL* pnl){
	
	var min_x, min_y, max_x, max_y;
	BMAP* bmp;
	
	switch(id){
		case 1: //color pallette
			min_x = pnl.pos_x + 6;
			min_y = pnl.pos_y + 42;
			max_x = pnl.pos_x + 6 + bmap_width(bmp_avColorPallette);
			max_y = pnl.pos_y + 42 + bmap_height(bmp_avColorPallette);
			bmp = bmp_avColorPallette;
		break;
		case 2: //skin pallette
			min_x = pnl.pos_x + 6;
			min_y = pnl.pos_y + 130;
			max_x = pnl.pos_x + 6 + bmap_width(bmp_avSkinPallette);
			max_y = pnl.pos_y + 130 + bmap_height(bmp_avSkinPallette);
			bmp = bmp_avSkinPallette;
		break;
		case 3: //pattern color pallette
			min_x = pnl.pos_x + 6;
			min_y = pnl.pos_y + 322;
			max_x = pnl.pos_x + 6 + bmap_width(bmp_avColorPallette);
			max_y = pnl.pos_y + 322 + bmap_height(bmp_avColorPallette);
			bmp = bmp_avColorPallette;
		break;
	}
	
	var format = bmap_lock(bmp, 0), pixel;
	VECTOR vec_temp;
	
	while(mouse_left){
		
		if((mouse_pos.x >= min_x) && (mouse_pos.x < max_x)){
			if((mouse_pos.y >= min_y) && (mouse_pos.y < max_y)){
				pixel = pixel_for_bmap(bmp, mouse_pos.x - min_x, mouse_pos.y - min_y);
			}
		}
		
		pixel_to_vec(vec_temp, NULL, format, pixel);
		vec_temp.x /= 256;
		vec_temp.y /= 256;
		vec_temp.z /= 256;
		
		switch(id){
			case 1: case 2:
				vec_set(var_avArea[0], vector(vec_temp.z, vec_temp.y, vec_temp.x));
			break;
			case 3:
				vec_set(var_avPattern[0], vector(vec_temp.z, vec_temp.y, vec_temp.x));
			break;
		}
		wait(1);
	}
	
	bmap_unlock(bmp);
}

1, 2 and 3 chooses the panel clicked and the limits of the bmap while holding mouse_left

Re: Pixel_to_vec() is crashing engine? [Re: MrGuest] #348748
11/30/10 05:35
11/30/10 05:35
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
i'm reading from a bmap that is not displayed on screen, therefore the mouse co-ordinates have to be converted to co-ordinates on the bmap. the bmap i am reading from is 744x600 pixels, the mouse position x (lets say the video_mode is 8 and the screen size therefore 1024x768) is between 0 and 1024 and the mouse position y is between 0 and 768. Dividing bmap_width(my_bmap) by screen_size.x gives me the ratio i need to convert the mouse pos_x to the equivalent x co-ordinate on the bmap. lets say the mouse is halfway across the screen - mouse_pos.x = 512.

x_coord = integer(mouse_pos.x*(bmap_width(my_bmap)/screen_size.x));
x_coord = integer(512*(744/1024));
x_coord = integer(512*0.727);
x_coord = 372;

mouse_pos.x of 512 = bitmap_pos.x of 372. Even when this formula generates a number outside the bounds of the bitmap i am still boundary checking and force an early return in this instance. (if(x_coord>bmap_width(my_bmap)||x_coord<0) { return(-1); }). The same is for y_coord.

I know that x_coord and y_coord are giving me the numbers im expecting. I know that bmap_lock is sucessful - it returns 8888. I know that the pixel for bmap is returning the pixel read from the bmap....well, i know it is returing *A* value...perhaps the value returned by pixel_for_bmap is the problem? or perhaps the format returned by bmap_lock is the problem?

I mentioned before that the bmap was made in photoshop and saved as a 24 bit tga file with no alpha channel - a return code of 8888 means it is reading the bmap as a 32 bit tga file with an alpha channel. I recall reading that the bmap_lock "upconverts" a bmap to the next compatible mode if its native mode isnt compatible or something like that.

I notice you save the return value of bmap_lock to format and pass format to the pixel_to_vec function instead of passing 8888. I will try that and see if that solves the problem

Re: Pixel_to_vec() is crashing engine? [Re: Caermundh] #348749
11/30/10 05:39
11/30/10 05:39
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
Ah....found the problem.

"COLOR* pixel_color;" needs to be "COLOR pixel_color;". I'm passing a pointer to a color instead of the color vector itself - THATS what was crashing pixel_to_vec().

Dumb, dumb, dumb me. every other capitalised variable declaration requires a * (PANEL*, TEXT*, BMAP*, FONT*, etc etc). I know not ALL of them do though, I need to learn to check these things.

Thank you everyone for your time and input.


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

Gamestudio download | chip programmers | 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