Jump to content
  • Advertisement

Archived

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

tifkagh

DirectDraw Object as a parameter

This topic is 6193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a member function to initialise an object which is prototyped as follows: int Init(LPDIRECTDRAW7 DDobj, int x, int y, int width, int height, int num_frames, int attr, int mem_flags); Within my object I have the following member: LPDIRECTDRAW7 lpDD; When I call Init the following line cauases the program to crash: lpDD = DDobj Please help.

Share this post


Link to post
Share on other sites
Advertisement
Make sure you are passing the pointer to your Init function as DDobj, and not as a reference &DDobj, example
say you have a function

SetDDraw(LPDIRECTDRAW7 DDobj)
{
DDraw = DDobj;
}

if you call it as

SetDDraw(DDobj);

it should work as spected, if you do

SetDDraw(&DDobj);

DDobj will have a pointer to the LPDIRECTDRAW7 POINTER (as opposed to the DIRECTDRAW Object), which is not what you want.
remember LPDIRECTDRAW7 is already a pointer LP = Long Pointer





Edited by - kwizatz on December 30, 2001 5:39:43 PM

Share this post


Link to post
Share on other sites
I''m pretty sure the pointer is not null and the object is not passed with the ampersand prefix. Cheers anyway.

Share this post


Link to post
Share on other sites
Are you sure that the assignment causes the exception?
I can''t believe it, since it is a simple pointer assignment and nothing can go wrong at this point, regardless of the actual pointer value. What is in the line preceeding?

Share this post


Link to post
Share on other sites
your bug might be somewhere else, have you added a watch to the DDobj with a debugger?, perhaps something is turning the pointer to something else, invalid data, I am doing the exact same thing with my CGui class, and it works.

yesterday I was having problems with my PCX file format class, I check to see if a surface is valid before releasing it in order to load a new file, I was swearing it was null, but the program thought otherwhise, creating a problem trying to release invalid data, I couldnt find where was the pointer being corrupted, no luck, then I just cleaned the project (deleted executable and object files) rebuilt the thing, and the bug was gone, my guess is that the old object files for classes using my CPcxImage Object had old data relating to the PCX class, thus giving the error.

Share this post


Link to post
Share on other sites
Yep Volker it's the assignment statement. Furthermore, when I comment out the lpDD assignment I find that an exception is thrown on the very next statement (also an assignmet within the object). So my problem can be restated as: I cannot assign members within my own object.

I'm sure I'm making some blindingly obvious C++ mistake. Any clues folks?

Edited by - tifkagh on January 1, 2002 3:48:32 PM

Share this post


Link to post
Share on other sites
I''m setting the lpDD member = NULL within the constructor. What is the correct method of of creating the object?

Share this post


Link to post
Share on other sites
Is this a run-time error? The debugger isn''t giving you any data on it? Because then it is really weird. I can understand this going wrong:
LPDIRECTDRAW7 m_pDD;

Init(LPDIRECTDRAW7* ppDD,...)
{
m_pDD = *ppDD;
}
but what you have should work fine...

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!