Jump to content
  • Advertisement

3D DirectDraw Create Surface access violation

Recommended Posts

Hello to all i have got a DirectX 8 game i am fixing all works well besides one DirectShow function that streams a video into a DirectDraw surface, I get an Access Violation error in ->CreateSurface...Can someone help me?. Thanks Here is the function.

create_stream(const char *file_path)
	IAMMultiMediaStream *local_stream_ptr;
    IAMMultiMediaStream *global_stream_ptr;
    IMediaStream *primary_video_stream_ptr; 
    IDirectDrawMediaStream *ddraw_stream_ptr; 
    IDirectDrawStreamSample *video_sample_ptr;
    LPDIRECTDRAWSURFACE video_surface_ptr;
    DDPIXELFORMAT ddraw_video_pixel_format;
	DDSURFACEDESC ddraw_surface_desc;
	RECT rect;
	int video_width, video_height;

	// Initialise the COM library.


	// Initialise the global variables.

	global_stream_ptr = NULL;
	primary_video_stream_ptr = NULL;
	ddraw_stream_ptr = NULL;
	video_sample_ptr = NULL;
	video_surface_ptr = NULL;

	// Create the local multi-media stream object.

	if (CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream, (void **)&local_stream_ptr) != S_OK)

	// Initialise the local stream object.

	if (local_stream_ptr->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD,NULL) != S_OK) {

	// Add a primary video stream to the local stream object.

	if (local_stream_ptr->AddMediaStream(ddraw_object_ptr, &MSPID_PrimaryVideo, 0, NULL) != S_OK) {

	// Add a primary audio stream to the local stream object, using the 
	// default audio renderer for playback.

	if (local_stream_ptr->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL) != S_OK) {

	// Open the streaming media file.

	MultiByteToWideChar(CP_ACP, 0, file_path, -1, wPath, MAX_PATH);   
	if (local_stream_ptr->OpenFile(wPath, 0) != S_OK) {
		diagnose("Windows Media Player was unable to open stream URL %s", file_path);
	// Convert the local stream object into a global stream object.
	global_stream_ptr = local_stream_ptr;
	// Initialise the primary video stream, if it exists.
	if (global_stream_ptr->GetMediaStream(MSPID_PrimaryVideo, &primary_video_stream_ptr) != S_OK)  {
	        warning("Could not get the primary video stream");
	} else {
              warning("Get the primary video stream");
        if (primary_video_stream_ptr->QueryInterface(IID_IDirectDrawMediaStream,(void **)&ddraw_stream_ptr) != S_OK) {
	        warning("Could not obtain the DirectDraw stream object");
	  } else {
            warning("Obtain the DirectDraw stream object");
        // Determine the unscaled size of the video frame.

	if (ddraw_stream_ptr->GetFormat(&ddraw_surface_desc, NULL, NULL, NULL) != S_OK)  {
	        warning("Could not determine the unscaled size of the video frame");
	} else {
            warning("Determine the unscaled size of the video frame");
	video_width = ddraw_surface_desc.dwWidth;
	video_height = ddraw_surface_desc.dwHeight;

	// Create a DirectDraw video surface using the texture pixel format, but 
	// without an alpha channel (otherwise CreateSample will spit the dummy).

	memset(&ddraw_surface_desc, 0, sizeof(DDSURFACEDESC));
    ddraw_surface_desc.dwSize = sizeof(DDSURFACEDESC);
     ddraw_surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
    ddraw_surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
    ddraw_surface_desc.dwWidth = video_width;
    ddraw_surface_desc.dwHeight = video_height;
    ddraw_surface_desc.ddpfPixelFormat = ddraw_video_pixel_format;
	// Here i got acccess violation 
	if (ddraw_object_ptr->CreateSurface(&ddraw_surface_desc, &video_surface_ptr, NULL) != DD_OK)  {
	        warning("Could not create a DirectDraw video surface");
		} else {
            warning("Create a DirectDraw video surface");
	// Set the rectangle that is to be rendered to on the video surface.

	rect.left = 0;
 	rect.right = video_width;
 	rect.top = 0;
 	rect.bottom = video_height;

	// Create the video sample for the video surface.
	if (ddraw_stream_ptr->CreateSample(video_surface_ptr, &rect, 0, &video_sample_ptr) != S_OK) {
	        warning("Could not create the video sample for the video surface");
	} else {
          warning("Created the video sample for the video surface");
	// Create the event that will be used to signal that a video frame is
	// available.


	// Initialise the video textures now, since we already know the
	// dimensions of the video frame.

	init_video_textures(video_width, video_height, RGB16);
	warning("Surface started");

	streaming_video_available = true;

	// Get the end of stream event handle.


	// Return a success status.
    warning("Stream started");


Edited by Vic666

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!