Archived

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

Annoying Managed DirectDraw Surface.Lock Bug

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

Recommended Posts

Surface.Lock returns a byte[*,*] array. Writinng to this byte array does not fill the entire surface. I don''t think pitch can really be ussed in this situation since the array has a limit on its dimensions. I have heard of SEVERAL people that have this same problem, and it''s quite frustrating. Is there ANY way at all of direct surface manipulation? When is this expected to be fixed?

Share on other sites
pitch is always used, no matter what kind of surface you use. if you did not take care of the pitch it's clear you won't be able to fill the screen.

EDIT: Lock does not give back a byte[*,*], it gives back a byte*. look at it like a file which has some predefined gap between lines and not like a thight fitting bitmap.

[edited by - RPTD on March 24, 2004 3:27:48 PM]

Share on other sites
The version of DirectX 9 I have returns a byte[,]. I am using Managed DirectDraw, and the wrapper somewhat disappoints me. What I meant about pitch is th at the values in the byte array clearly don't match up with the image coordinates, and there is no way to access an index outside of the bounds of the array, which the pitch might suggest.

Here is my code.

				byte[,] image;				//Lock the surface				image= surf.Lock(LockFlags.SurfaceMemoryPointer | LockFlags.Wait);					//loop through all of the ys				for(int y=0; y<image.GetUpperBound(1); y++)				{					//and through every x that corresponds to that y					for(int x=0; x<image.GetUpperBound(0); x++)					{						//Just set it to black/						image[x,y]=0;					}				}				//Unlockf				this.surf.Unlock(image);

And I've tried using pitch, and I'll get an OutOfBounds exception I think. I dont fancy much the 2 dimmensional approach that they've taken with this.

[edited by - Muzlack on March 24, 2004 5:13:30 PM]

Share on other sites
Yeah I had that problem when I tried locking a surface too. I ended up doing a color fill to the points I needed. Slow, but it worked for my purposes.

Share on other sites
what language and wrapper you use? i personally never use wrappers cause they tend to crank up more than they help. if you can try casting it (clean cast or dirty cast) it to a simple byte pointer and then access it like that (or use mem functions), whatever way you have to access a one dimensional byte data area.

Share on other sites
I''m using C#, and I''m making my own wrapper. Is it possible to use non-managed DirectX? I''m familiar with C++, and in fact, I''m porting my engine to C#, so if it were possible to use the same data structures etc. that I''m using, that would be cool.

*bump*

Share on other sites
*bump* again. I''ve read a *lot* of complaints like these but no solution as of yet. has anyone figured this out?

Share on other sites
I have had the same problem. From what I am looking at it looks as if it converts whats in memory directly to a 2d array.

The issue is I think IS casting. if you just do a :
Array temp = surfaceSecondary.Lock(LockFlags.SurfaceMemoryPointer);

I produces a 1024,768 array of shorts. Short being the default size of the Array class.

Humm... You know, I wonder what happens if you cast it to long. Maybe, since it gives an Array on the size of the screen, it also depends on the depth of the screen.

Aka, it needs to be an Int32 because my screen is at 32 bits.

I am checking on this.

Share on other sites
Still waiting for my regestration information.

Ok, I am using remote desktop, so apperently thats why it was in shorts.

Check this out. Try running the DirectX9 wizard and making a DirectDraw project. Plop this code in and run it though the Quick watch.
// Snip
temp = surfaceSecondary.Lock(LockFlags.SurfaceMemoryPointer);
surfaceSecondary.Unlock(temp);

surfaceSecondary.ColorFill(Color.Yellow); // Change this and see the array values change!

temp = surfaceSecondary.Lock(LockFlags.SurfaceMemoryPointer);
surfaceSecondary.Unlock(temp);

// Snip

It looks like that Lock comamnd just gives a nice raw buffer of the surface. Since I am set up at 16-bit/1024x768 it makes an array of Int16, 1024 long, 768 tall. Only problem is clipping. If your not using full screen, you have to remeber where the clip window is.

Humm. Can''t wait to get home and try this.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×