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

  • Similar Content

    • By Aleksid1
      We sell presentation app which uses Direct3D 9. It works slow on laptops with dual video cards (Intel + NVIDIA or AMD). We have to ask users to manually choose NVIDIA video card for our app.
      Is there any API to automatically select dedicated NVIDIA/AMD video card in our app on Windows 10?
    • By Emerald_Eel_Entertainment
      Forest-themed levels in 3D linear games seem to be tricky to pull off. I primarily refer to first person games though this can easily be applied to third person games and possibly top-down games.
      Older games were limited by the hardware used at the time so texture space and polygon counts were important to manage. These games uses a flat texture of trees to create the illusion of depth or create rocky cliff walls to obscure parts of the scene the player is not meant to view.
      An example of a linear forest level is Forest Edge from Disney's Donald Duck: Goin' Quakers on the PlayStation 1.

      A relatively recent example of a linear forest level are portions the Outlands White Forest from Half-Life 2: Episode 2 on the PC. You can see that it looks more like a small narrow valley. For gameplay and readability it works well and doesn't feel artificial though it's not quite a dense forest.

      Outlast 2 did have areas set in tree-filled areas but the only indication of not being able to go through some bushes or trees are invisible barriers, which supposedly works but feels very artificial in my opinion.

      Some games in recent years like The Forest and Ark: Survival Evolved have made fully explorable forest levels but they are non-linear open world games. Since the respective games aren't linear in nature they have no need to funnel players through areas designed to be traversed.

      How can depth and believability be achieved without making the player confused or lose their direction? How can making a linear forest level be done without making the environment appear artificial?
      I created this topic as I'd love to hear what you guys think. I don't think there's a right or wrong way going about making a 3D linear forest level.
  • Popular Now