Skip to main content
gamedev.net
🔒 Locked

C# SurfaceLoader problem (bug?)

Started by The Frugal Gourmet 4 replies 1.6k views
Original Post
The Frugal Gourmet
The Frugal Gourmet
I'm having an odd problem with SurfaceLoader.FromSurface() or SurfaceLoader.FromFile() in C#. If I declare a source rectangle offset from the point 0,0 I often have an error, even if that rectangle is properly contained by the surface. Let me show an example. In this situation, I have a Surface loaded in memory which is 2048x2048 called _mainSurface or (in C++) pSurface. C# Version
Texture tempTexture = new Texture(_device, 256, 256, 1, 0, 
		_mainSurface.Description.Format, Pool.Managed);

Rectangle srcRect = new Rectangle(0, 256, 256, 256);

Surface tempSurface = tempTexture.GetSurfaceLevel(0);

SurfaceLoader.FromSurface(tempSurface, _mainSurface, srcRect, Filter.None, 0); 


The above version craps out saying that the rectangle has "zero area" (when obviously it does not).  

C++ Version

   
LPDIRECT3DTEXTURE9 tempTexture;
Rectangle srcRect;

D3DXCreateTexture(m_pDevice, 256, 256, 1, 0, srcInfo.Format, D3DPOOL_MANAGED, &tempTexture);

RECT srcRect;
srcRect.left = 0;
srcRect.right = 256;
srcRect.top = 256;
srcRect.bottom = 512;

LPDIRECT3DSURFACE9 pTempSurface;
tempTexture->GetSurfaceLevel(0, &pTempSurface);

D3DXLoadSurfaceFromSurface(pTempSurface, NULL, NULL, pSurface, NULL, &srcRect, D3DX_FILTER_NONE, 0);
In C++, the above works flawlessly. My tempTexture is now correctly set. It is essentially the same method taking the exact same rectangle from the exact same surface. Anyone know what's going on? [edited by - The Frugal Gourmet on August 3, 2003 12:51:40 AM]
Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
Martee
Martee
Rectangle srcRect = new Rectangle(0, 256, 256, 256);

Look carefully at the numbers ... this rectangle does indeed have zero area (assuming that the constructor takes left, right, top, and bottom as parameters).
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
The Frugal Gourmet
The Frugal Gourmet
It doesn''t. In C#, the Rectangle constructor takes X,Y, height, width. However, I''ve tried it the other way just to be sure .. same result.

Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
The Frugal Gourmet
The Frugal Gourmet
BTW, I still believe this is a bug in Managed DirectX....
Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
Entz
Entz
Most likely a bug in the runtime (Far from being the first one I have seen). More often then not calling one of the other overloads usually helps.

i.e. have you tried :

FromSurface( destSurface, destRectangle, srcSurface, srcRectangle, filter, colorKey )

Explicitly setting the destRectangle may help. The other verson may be using a blank rect or a clipped version of the srcRectangle for some stupid reason.
Cheers,~Entz-=-=-=-=-=-=-=-=-=-=-=-=-=-http:www.leviathan3d.com (under construction)
The Frugal Gourmet
The Frugal Gourmet
Yeah.. .hmm... I tried a couple of those but they all seemed to give the same result. I seem to be able to change the source rectangle appropriately, but changing the destination rectangle to someplace inside the target surface doesn''t seem to work.

Unless my target rectangle begins at point: 0,0 .. the debug info always says "Error locking surface: destination rectangle has zero area.".

I''m positive my source and destination rectangles are the same size as well and that both are very much valid rectangles.

But, I''m very curious about this because I have not seen anyone else report this (perceived) bug here or any other place. I still wonder if maybe I am doing something wrong...

...

But, regardless, the fact that it performs exactly like I suspect it should in (unmanaged) C++ makes me think this could indeed be a bug.



Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.