Advertisement

Data hiding and Access violations

Started by December 04, 2000 03:30 PM
1 comment, last by JwayneT 24 years, 1 month ago
I have an interesting problem,

I decided to put all of my ddraw surfaces and related functions into a class. After I had gotten it into the form I wanted I ran into access violations when I tried to aquire a back buffer. I worked with it for a while, checking to see if the window handle was passed to the DDraw object and stuff like that. When this yeilded nothing I took my code that had all DX stuff global, and encased a class around that.
//from this global LPDIRECTDRAW7 lpdd; LPDIRECTDRAWSURFACE7 lpddprimary,lpddback; LPSURFACDESC2 ddsd; void ddraw_init(); void ddraw_dest(); //to this class class screen{ public: LPDIRECTDRAW7 lpdd; LPDIRECTDRAWSURFACE7 lpddprimary,lpddback; LPSURFACDESC2 ddsd; void ddraw_init(); void ddraw_dest(); };

I might of misspelled some data types, but this was just to give you an idea.
Remember that the global code worked perfectly.
So with that modification and an instance in WinMain of screen declared as test, the only changes in my code was from lpddprimary, to test.lpddprimary. With that change brought the same access violations. The Direct draw object is created just fine inside of a class, just not surfaces. <style>a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn''t it cold when it goes in the tank?

-=CF=-</html>
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]
I''m sure you haven''t, but have you left any of the original globals in your code? The test.ddraw_init() function may be referring to the global structures.

The only other possibility I can think of is that the instance of screen is coming out of scope, but if its declared in WinMain then this won''t happen until the program terminates.

It may seem a fudge, but try giving your test object global scope, ie declare it outside any function.

How are you passing the screen object to functions? If you''re passing it as an parameter, make sure you''re passing a pointer or reference to it. If you pass a class as a parameter to a function, then that function will receive a copy of the class, which takes up a lot of stack space. Any modifications made to it will be lost when the function returns.

Just some thoughts; I hope they are useful!

Dave
Advertisement
Well, I''ll try declaring it outside of the winmain. As far as passing it as refrence, that was the whole point of taking it out of global scope. Thanks for the input anyways. I''ll try what you suggested and see if that leads anywhere.

<style>a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn''t it cold when it goes in the tank?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]

This topic is closed to new replies.

Advertisement