This topic is now archived and is closed to further replies.


Serious Error please help!

Recommended Posts

Some of you might have seen my post on my VERY strange lookup table error a while back. and I was asked to post my init function, where everything happens, and now when I have started to add some more code to it, it gives me more headache, so please see if you can figure out what''s wrong, because I cannot see any problem.
//This function initializes the game and DirectX----------------------------------------------

void GameInit(int screen_width, int screen_height)
	// Initialize Direct Draw

	DDSURFACEDESC2	surfaceDesc;		//Surface description

	DDSCAPS2		surfaceCaps;		//Surface capabilities

	// Create Direct Draw object and set it''s cooperation level with windows 

	DirectDrawCreateEx(NULL, (VOID** )&directDraw, IID_IDirectDraw7, NULL);
	directDraw->SetCooperativeLevel(main_window_handle, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);
	// Set the display to the screen width and height specified, and 16-bit color

	directDraw->SetDisplayMode(screen_width, screen_height, 16, 0, 0);
	// clean out the surface description struct and set it''s size

	// Set all primary surfaces capabilities and prepare it for a backbuffer

	surfaceDesc.dwBackBufferCount = 1;
	// Create the primary surface

	directDraw->CreateSurface(&surfaceDesc, &primary_surface, NULL);

	// clean out the surface capabilites struct

	ZeroMemory(&surfaceCaps, sizeof(surfaceCaps));

	// Set primary surface''s capabilites to accept an attached surface

	surfaceCaps.dwCaps = DDSCAPS_BACKBUFFER;

	// Attach the backbuffer (back_buffer) to the primary surface

	primary_surface->GetAttachedSurface(&surfaceCaps, &back_buffer);

	//Create a clipper, and atach it to the back_buffer

	clipper->SetHWnd(0, main_window_handle);
	//Set up an offscreen plain system memory scratch buffer surface

	DDSURFACEDESC2   temp_desc;

	temp_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
   	temp_desc.dwWidth = 640;
	temp_desc.dwHeight = 480;
	if(FAILED(directDraw->CreateSurface(&temp_desc, &scratch_buffer, NULL)));

	//Calculate the lookuptable for y values, for Plot_Pixel

	//Lock the back buffer

	DDRAW_INIT_STRUCT(ddsurface) //Clear ddsurface and set size, never assume it''s clean	

	if (FAILED(back_buffer->Lock(NULL, &ddsurface, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
	lpitch16 = (ddsurface.lPitch >> 1);
	for (int counter = 0; counter <= 480; counter++)
		ylookup[counter] = lpitch16 * counter;
	//Unlock the Back buffer

	if (FAILED(back_buffer->Unlock(NULL)))

	// Load the bitmaps to their surfaces here

	Load_Bmp(background,1, "background.bmp", backrect);
	Load_Bmp(particles, 1, "particles2.bmp", partrect);
	Load_Bmp(gnome, 0, "gnome.bmp", gnomerect);
	Load_Bmp(alpha_bmp, 0, "alpha1.bmp", alpharect);

	// Set the position for the bitmap to draw at

	bitmapX = 320;
	bitmapY = 240;

	//Calculate rects for the Particles, each one is 8*8 pixels in size.

	for (int i = 0; i < 8; i++)
		particle_rect[i].left = i * 8;
		particle_rect[i].right = i * 8 + 8;
		particle_rect[i].top = 0;
		particle_rect[i].bottom = 8;
	//Calculates lookup tables for sin and cos functions

	for (int angle = 0; angle <= 360; angle++)
		double rad_angle = angle * (3.141592654/180);
		sin_look[angle] = sin(rad_angle);
		cos_look[angle] = cos(rad_angle);
	ShowCursor(FALSE); //Hide the mouse cursor


Share this post

Link to post
Share on other sites
As Darrell L said, you might still have a bounds problem with your ylookup array. It would be helpful if you posted a bit more info about the actual problem (I haven''t seen your original post about this) and the code where the problem manifests itself.

You could always use a simple for-loop to display the contents of the lookup table and see if anything is incorrect. If the values are incorrect, move the check elsewhere until you pin down the section of your code that causes it to be wrong.

Share this post

Link to post
Share on other sites