|
-
Aug 26th, 2012, 09:24 AM
#3
Thread Starter
Lively Member
Re: XNA Corrupted memory
 Originally Posted by Inferrd
You might be using a different spritebatch for the map box and for the tileset box, but you use the same Texture2D object (TileSet) for both. As that was created with a reference to the map box's GraphicsDevice, it is (presumably?) only renderable in the map box.
I would change the global scope of your OurContent variable to being declared locally within each InitalizeGraphics functions and then create any needed Texture2D objects within those functions.
vb.net Code:
Imports System.Windows.Forms
Module modPublics
Public GDevice_MAP As GraphicsDevice
Public SBatch_MAP As SpriteBatch
Public GDevice_TILESET As GraphicsDevice
Public SBatch_TILESET As SpriteBatch
Public Tileset As Texture2D = Nothing
Public Mapset As Texture2D = Nothing
Public Function InitalizeGraphics_TILESET(ByRef Surface As PictureBox) As Boolean
Dim retValue As Boolean
Try
Dim PParam As New PresentationParameters
PParam.PresentationInterval = PresentInterval.Immediate
PParam.DeviceWindowHandle = Surface.Handle
PParam.IsFullScreen = False
Dim GAdapter As GraphicsAdapter = GraphicsAdapter.Adapters.Item(0)
GDevice_TILESET = New GraphicsDevice(GAdapter, GraphicsProfile.HiDef, PParam)
SBatch_TILESET = New SpriteBatch(GDevice_TILESET)
Dim OurContent = New clsContent.GameContent(GDevice_TILESET)
OurContent.Content.RootDirectory = "Content"
'//LOAD GRAPHICS
Tileset = OurContent.Content.Load(Of Texture2D)("Content/Graphics/Tilesets/0")
retValue = True
Catch ex As Exception
retValue = False
MessageBox.Show(ex.Message)
End Try
Return retValue
End Function
Public Function InitalizeGraphics_MAP(ByRef Surface As PictureBox) As Boolean
Dim retValue As Boolean
Try
Dim PParam As New PresentationParameters
PParam.PresentationInterval = PresentInterval.Immediate
PParam.DeviceWindowHandle = Surface.Handle
PParam.IsFullScreen = False
Dim GAdapter As GraphicsAdapter = GraphicsAdapter.Adapters.Item(0)
GDevice_MAP = New GraphicsDevice(GAdapter, GraphicsProfile.HiDef, PParam)
SBatch_MAP = New SpriteBatch(GDevice_MAP)
Dim OurContent = New clsContent.GameContent(GDevice_MAP)
OurContent.Content.RootDirectory = "Content"
'//LOAD GRAPHICS
Mapset = OurContent.Content.Load(Of Texture2D)("Content/Graphics/Tilesets/0")
retValue = True
Catch ex As Exception
retValue = False
MessageBox.Show(ex.Message)
End Try
Return retValue
End Function
End Module
Use the apropriate Texture2D object for the SpriteBatch and GraphicsDevice that you are drawing to. (Tileset with SBatch_TILESET and Mapset with SBatch_MAP)
Code:
Public Sub NewMap()
GDevice_TILESET.Clear(Color.Black)
SBatch_TILESET.Begin()
SBatch_TILESET.Draw(Tileset, New Rectangle(0, 0, 32, 32), New Rectangle(0, 0, 32, 32), Color.White)
SBatch_TILESET.End()
GDevice_TILESET.Present()
GDevice_MAP.Clear(Color.Black)
SBatch_MAP.Begin()
SBatch_MAP.Draw(Mapset, New Rectangle(0, 0, 32, 32), New Rectangle(0, 0, 32, 32), Color.White)
SBatch_MAP.End()
GDevice_MAP.Present()
End Sub
Thanks, guess it worked!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|