2011-12-18 3 views
0

エラー:廃棄されたオブジェクトにアクセスすることはできません。オブジェクト名: 'Texture2D'c#XNA廃棄オブジェクトにアクセスできません。オブジェクト名: 'Texture2D'。しかし、それを処分しないでください

なぜこのようなことが起こりますか?私のコード全体のどこにでも、処分するよう指示しています! これは、XNA C#のLoadContent()で発生しています。 コードこのエラーが発生すると、Texture2Dが強調表示され、これが発生しました。

protected override void LoadContent() 
    { 
     SoundEffect.DistanceScale = 20; 
     SetUpPlain(); 
     SetUpWalls(); 
     // Walls 
     wallsEffect = new BasicEffect(graphics.GraphicsDevice); 
     wallsEffect.World = Matrix.Identity; 
     wallsEffect.Projection = vars.projection; 
     wallsEffect.TextureEnabled = true; 
     wallsEffect.Texture = Content.Load<**Texture2D**>("Textures\\Fence"); 
     // Set-up Player Options 
     Player1.PlayerModel = Content.Load<Model>("PlayerA"); 
     Player1.BoundingSphere = new BoundingSphere(new Vector3(Player1.Position.X, Player1.Position.Y - 2, Player1.Position.Z), Player1.PlayerModel.Meshes[0].BoundingSphere.Radius * 0.04f); 
     Player2.PlayerModel = Content.Load<Model>("PlayerA"); 
     Player2.BoundingSphere = new BoundingSphere(new Vector3(Player2.Position.X, Player2.Position.Y - 2, Player2.Position.Z), Player2.PlayerModel.Meshes[0].BoundingSphere.Radius * 0.04f); 
     // 
     loadStaticModel(Content, "Radio", null, 11, 4, -2, 0, 180, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "AmmoCrate", null, 10, 1, 0, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "AmmoCrate", null, 12, 1, 0, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "AmmoCrate", null, 11, 3, 0, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Forklift", null, 15, 0, -5, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "PepsiMachine", null, 25, 0, -5, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Chest", null, 10, 0, -20, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "PalletBoard", "Cork", 10, 0, -20, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Table", "Cork", 15, 0, -20, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Cylinder", "Cork", 15, 0, -40, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Wall", "Cork", 184, 0, -196, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "WallTop", "Cork", 184, 0, -188, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Wall", "Cork", 184, 0, -180, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Door1", "MetalA", 184, 0, -188, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Door1", "MetalA", 184, 0, -184, 0, 0, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Wall", "Cork", 188, 0, -176.15f, 0, 90, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     loadStaticModel(Content, "Wall", "Cork", 196, 0, -176.15f, 0, 90, 0, CollisionType.Default, LightingType.AmbientDirectional, true, false); 
     for (int i = 1; i <= MapSize/8; i++) 
     { 
      loadStaticModel(Content, "Fence", "Fence", i * 8.12f - 4, 0, 0, 0, 270, 0, CollisionType.None, LightingType.AmbientDirectional, false, false); 
      loadStaticModel(Content, "Fence", "Fence", 0, 0, -(i * 8.12f - 4), 0, 180, 0, CollisionType.None, LightingType.AmbientDirectional, false, false); 
      loadStaticModel(Content, "Fence", "Fence", MapSize, 0, -(i * 8.12f - 4), 0, 0, 0, CollisionType.None, LightingType.AmbientDirectional, false, false); 
      loadStaticModel(Content, "Fence", "Fence", i * 8.12f - 4, 0, -MapSize, 0, 90, 0, CollisionType.None, LightingType.AmbientDirectional, false, false); 
     } 
     // Sound 
     vars.soundEffect[0] = Content.Load<SoundEffect>("Sounds\\NormalStep"); 
     vars.soundEffect[1] = Content.Load<SoundEffect>("Sounds\\Enter Sandman"); 
     vars.soundEffect[2] = Content.Load<SoundEffect>("Sounds\\PlayerJoinGame"); 
     vars.soundEffect[3] = Content.Load<SoundEffect>("Sounds\\JumpLand"); 
     vars.soundEffectInstance[0] = vars.soundEffect[1].CreateInstance(); 
     soundEffectPosition[0] = new Vector3(0, 200, 200); 
     soundEffectEmitter[0] = new AudioEmitter(); 
     soundEffectEmitter[0].Position = soundEffectPosition[1]; 
     soundEffectListener[0] = new AudioListener(); 
     soundEffectListener[0].Position = Player1.Position; 
     vars.soundEffectInstance[0].Apply3D(soundEffectListener[0], soundEffectEmitter[0]); 
     vars.isSoundPlaying[0] = false; 
     // Menu's 
     vars.menuBackground = Content.Load<Texture2D>("Textures\\menuBackground"); 
     PauseMenu.screenShotHighlight = Content.Load<Texture2D>("Textures\\ScreenShotViewerHighlight"); 
     vars.MenuFont = Content.Load<SpriteFont>("Fonts//MenuFont"); 
     // Death HUD 
     deathBackground = Content.Load<Texture2D>("Textures\\deathBackground"); 
     // 
     chatBackground = Content.Load<Texture2D>("Textures\\chatBackground"); 
     plainTexture = Content.Load<Texture2D>("Textures\\Grass"); 
     // Tank 
     tank = Content.Load<Model>("tank"); 
     tankTransforms = new Matrix[tank.Bones.Count]; 
     // Sky Dome 
     skyDome = Content.Load<Model>("SkyDome"); 
     skyDomeTexture = Content.Load<Texture2D>("Textures\\skyBox"); 
     skyDomeTransforms = new Matrix[skyDome.Bones.Count]; 
     // 
     font = Content.Load<SpriteFont>("Fonts//PCFont1"); 
     chatFont = Content.Load<SpriteFont>("Fonts//chatFont"); 
     xboxButtons = Content.Load<SpriteFont>("Fonts//xboxControllerSpriteFont"); 
     xboxFont = Content.Load<SpriteFont>("Fonts//MenuFont"); 
     spriteBatch = new SpriteBatch(graphics.GraphicsDevice); 
     TextureEffect = Content.Load<Effect>("TextureEffect"); 
     // Viewports 
     leftViewport = GraphicsDevice.Viewport; 
     rightViewport = GraphicsDevice.Viewport; 
     leftViewport.Width = leftViewport.Width/2; 
     rightViewport.Width = rightViewport.Width/2; 
     rightViewport.X = leftViewport.Width; 
     // 
    } 
+0

ContentManagerでDispose()を呼び出しますか?何らかのカスタムコンテンツプロセッサー/ローダーを使用していますか?あなたはモデルのような何か他のものを処分しますか?あなたのDispose()にあなたのプログラムに何か*があり、それはそのテクスチャを呼び出すことができますか?また、エラーメッセージのスタックトレースは何ですか?私が見ているのは、コードを読み込むことです - それはそこで失敗しますか?コードを初めて実行するとき、または将来のあるとき? –

+0

私は決してDispose()を呼び出し、カスタムコンテンツプロセッサー/ローダーを使用していません。 スタックトレースを取得するにはどうすればよいですか? –

+0

Texture2Dをロードしようとすると例外がスローされますか?例外は何ですか? try ... catchでLoadContentのコードを囲むことができ、そこにキャッチされた例外を私たちに送信することができます。 –

答えて

0

skyDomeTexture = Content.Load( "Textures \ skyBox");

この

skyDomeTexture = Content.Load(@ "テクスチャ/スカイボックス")をしてみてください。

+0

あなたは文字通りのリテラルにバックスラッシュをつけなければなりません。最初の例では、文字列を\ sがスペースとしてエスケープし、2番目の例ではsをエスケープしません。 – Phill

関連する問題