2014-12-31 90 views
0

我試圖在Monogame下運行Visual Studio中構建的項目。它成功地建立,但是當我運行它,我收到以下錯誤信息:Monogame中的錯誤消息:未處理的異常:System.DllNotFoundException:SDL2.dll

Unhandled Exception: 
System.DllNotFoundException: SDL2.dll 
    at (wrapper managed-to-native) SDL2.SDL:SDL_SetMainReady() 
    at Microsoft.Xna.Framework.SDL2_GameWindow..ctor() [0x00000] in <filename unknown>:0 
    at Microsoft.Xna.Framework.SDL2_GamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0 
    at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0 
    at Microsoft.Xna.Framework.Game..ctor() [0x00000] in <filename unknown>:0 
    at MovingTeddyBears.Game1..ctor() [0x00000] in /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/Game1.cs:30 
    at MovingTeddyBears.Program.Main() [0x00001] in /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/Program.cs:19 
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: SDL2.dll 
    at (wrapper managed-to-native) SDL2.SDL:SDL_SetMainReady() 
    at Microsoft.Xna.Framework.SDL2_GameWindow..ctor() [0x00000] in <filename unknown>:0 
    at Microsoft.Xna.Framework.SDL2_GamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0 
    at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) 

[0x00000] in <filename unknown>:0 
    at Microsoft.Xna.Framework.Game..ctor() [0x00000] in <filename unknown>:0 
    at MovingTeddyBears.Game1..ctor() [0x00000] in /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/Game1.cs:30 
    at MovingTeddyBears.Program.Main() [0x00001] in /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/Program.cs:19 
The application was terminated by a signal: SIGHUP 

下面是實際的代碼:

Game1.cs:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Audio; 
using Microsoft.Xna.Framework.Content; 
using Microsoft.Xna.Framework.GamerServices; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
using Microsoft.Xna.Framework.Media; 

namespace MovingTeddyBears 
{ 
    /// <summary> 
    /// This is the main type for your game 
    /// </summary> 
    public class Game1 : Microsoft.Xna.Framework.Game 
    { 
     GraphicsDeviceManager graphics; 
     SpriteBatch spriteBatch; 

     const int WINDOW_WIDTH = 800; 
     const int WINDOW_HEIGHT = 600; 

     // teddy bears 
     TeddyBear bear0; 
     TeddyBear bear1; 
     TeddyBear bear2; 

     public Game1() 
     { 
      graphics = new GraphicsDeviceManager(this); 
      Content.RootDirectory = "Content"; 

      // set resolution to 800 by 600 
      graphics.PreferredBackBufferWidth = WINDOW_WIDTH; 
      graphics.PreferredBackBufferHeight = WINDOW_HEIGHT; 
     } 

     /// <summary> 
     /// Allows the game to perform any initialization it needs to before starting to run. 
     /// This is where it can query for any required services and load any non-graphic 
     /// related content. Calling base.Initialize will enumerate through any components 
     /// and initialize them as well. 
     /// </summary> 
     protected override void Initialize() 
     { 
      // TODO: Add your initialization logic here 

      base.Initialize(); 
     } 

     /// <summary> 
     /// LoadContent will be called once per game and is the place to load 
     /// all of your content. 
     /// </summary> 
     protected override void LoadContent() 
     { 
      // Create a new SpriteBatch, which can be used to draw textures. 
      spriteBatch = new SpriteBatch(GraphicsDevice); 

      // create teddy bears 
      bear0 = new TeddyBear(Content, "teddybear0", 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT); 
      bear1 = new TeddyBear(Content, "teddybear1", 200, 100, WINDOW_WIDTH, WINDOW_HEIGHT); 
      bear2 = new TeddyBear(Content, "teddybear2", 300, 100, WINDOW_WIDTH, WINDOW_HEIGHT); 
     } 

     /// <summary> 
     /// UnloadContent will be called once per game and is the place to unload 
     /// all content. 
     /// </summary> 
     protected override void UnloadContent() 
     { 
      // TODO: Unload any non ContentManager content here 
     } 

     /// <summary> 
     /// Allows the game to run logic such as updating the world, 
     /// checking for collisions, gathering input, and playing audio. 
     /// </summary> 
     /// <param name="gameTime">Provides a snapshot of timing values.</param> 
     protected override void Update(GameTime gameTime) 
     { 
      // Allows the game to exit 
      if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
       this.Exit(); 

      // update teddy bears 
      bear0.Update(); 
      bear1.Update(); 
      bear2.Update(); 

      base.Update(gameTime); 
     } 

     /// <summary> 
     /// This is called when the game should draw itself. 
     /// </summary> 
     /// <param name="gameTime">Provides a snapshot of timing values.</param> 
     protected override void Draw(GameTime gameTime) 
     { 
      GraphicsDevice.Clear(Color.CornflowerBlue); 

      // draw teddy bears 
      spriteBatch.Begin(); 
      bear0.Draw(spriteBatch); 
      bear1.Draw(spriteBatch); 
      bear2.Draw(spriteBatch); 
      spriteBatch.End(); 

      base.Draw(gameTime); 
     } 
    } 
} 

的Program.cs:

#region Using Statements 
using System; 
using System.Collections.Generic; 
using System.Linq; 
#endregion 

namespace MovingTeddyBears 
{ 
    static class Program 
    { 
     private static Game1 game; 

     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
      game = new Game1(); 
      game.Run(); 
     } 
    } 
} 

TeddyBear.cs:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Content; 
using Microsoft.Xna.Framework.Graphics; 

namespace MovingTeddyBears 
{ 
    /// <summary> 
    /// A class for a teddy bear 
    /// </summary> 
    class TeddyBear 
    { 
     #region Fields 

     // drawing support 
     Texture2D sprite; 
     Rectangle drawRectangle; 

     // velocity information 
     Vector2 velocity = new Vector2(0, 0); 

     // bouncing support 
     int windowWidth; 
     int windowHeight; 

     #endregion 

     #region Constructors 

     /// <summary> 
     /// Constructs a teddy bear with random direction and speed 
     /// </summary> 
     /// <param name="contentManager">the content manager for loading content</param> 
     /// <param name="spriteName">the name of the sprite for the teddy bear</param> 
     /// <param name="x">the x location of the center of the teddy bear</param> 
     /// <param name="y">the y location of the center of the teddy bear</param> 
     /// <param name="windowWidth">the window width</param> 
     /// <param name="windowHeight">the window height</param> 
     public TeddyBear(ContentManager contentManager, string spriteName, int x, int y, 
      int windowWidth, int windowHeight) 
     { 
      this.windowWidth = windowWidth; 
      this.windowHeight = windowHeight; 

      LoadContent(contentManager,spriteName, x, y); 

      // generate random velocity 
      Random rand = new Random(); 
      int speed = rand.Next(5) + 3; 
      double angle = 2 * Math.PI * rand.NextDouble(); 
      velocity.X = (float)Math.Cos(angle) * speed; 
      velocity.Y = -1 * (float)Math.Sin(angle) * speed; 
     } 

     /// <summary> 
     /// Constructs a teddy bear with the given characteristics 
     /// </summary> 
     /// <param name="contentManager">the content manager for loading content</param> 
     /// <param name="spriteName">the name of the sprite for the teddy bear</param> 
     /// <param name="x">the x location of the center of the teddy bear</param> 
     /// <param name="y">the y location of the center of the teddy bear</param> 
     /// <param name="velocity">the velocity vector for the teddy bear</param> 
     /// <param name="windowWidth">the window width</param> 
     /// <param name="windowHeight">the window height</param> 
     public TeddyBear(ContentManager contentManager, string spriteName, int x, int y, 
      Vector2 velocity, int windowWidth, int windowHeight) 
     { 
      this.windowWidth = windowWidth; 
      this.windowHeight = windowHeight; 

      LoadContent(contentManager, spriteName, x, y); 
      this.velocity = velocity; 
     } 

     #endregion 

     #region Public methods 

     /// <summary> 
     /// Updates the teddy bear's location, bouncing if necessary 
     /// </summary> 
     public void Update() 
     { 
      // move the teddy bear 
      drawRectangle.X += (int)(velocity.X); 
      drawRectangle.Y += (int)(velocity.Y); 

      // bounce as necessary 
      BounceTopBottom(); 
      BounceLeftRight(); 
     } 

     /// <summary> 
     /// Draws the teddy bear 
     /// </summary> 
     /// <param name="spriteBatch">the sprite batch to use</param> 
     public void Draw(SpriteBatch spriteBatch) 
     { 
      spriteBatch.Draw(sprite, drawRectangle, Color.White); 
     } 

     #endregion 

     #region Private methods 

     /// <summary> 
     /// Loads the content for the teddy bear 
     /// </summary> 
     /// <param name="contentManager">the content manager to use</param> 
     /// <param name="spriteName">the name of the sprite for the teddy bear</param> 
     /// <param name="x">the x location of the center of the teddy bear</param> 
     /// <param name="y">the y location of the center of the teddy bear</param> 
     private void LoadContent(ContentManager contentManager, string spriteName, 
      int x, int y) 
     { 
      // load content and set remainder of draw rectangle 
      sprite = contentManager.Load<Texture2D>(spriteName); 
      drawRectangle = new Rectangle(x - sprite.Width/2, 
       y - sprite.Height/2, sprite.Width, 
       sprite.Height); 
     } 

     /// <summary> 
     /// Bounces the teddy bear off the top and bottom window borders if necessary 
     /// </summary> 
     private void BounceTopBottom() 
     { 
      if (drawRectangle.Y < 0) 
      { 
       // bounce off top 
       drawRectangle.Y = 0; 
       velocity.Y *= -1; 
      } 
      else if ((drawRectangle.Y + drawRectangle.Height) > windowHeight) 
      { 
       // bounce off bottom 
       drawRectangle.Y = windowHeight - drawRectangle.Height; 
       velocity.Y *= -1; 
      } 
     } 
     /// <summary> 
     /// Bounces the teddy bear off the left and right window borders if necessary 
     /// </summary> 
     private void BounceLeftRight() 
     { 
      if (drawRectangle.X < 0) 
      { 
       // bounc off left 
       drawRectangle.X = 0; 
       velocity.X *= -1; 
      } 
      else if ((drawRectangle.X + drawRectangle.Width) > windowWidth) 
      { 
       // bounce off right 
       drawRectangle.X = windowWidth - drawRectangle.Width; 
       velocity.X *= -1; 
      } 
     } 

     #endregion 
    } 
} 

我發現此頁面http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/但這並沒有解決問題。其實,當我運行ldconfig -p |grep libgdiplus 我得到

libgdiplus.so.0 (libc6,x86-64) => /usr/lib/libgdiplus.so.0 
libgdiplus.so (libc6,x86-64) => /usr/lib/libgdiplus.so 

所以.so文件(S)似乎並不成爲問題(我想,不知道雖然)。

+0

[MonoGame應用程序說可能重複SDL.dll丟失,即使它在那裏。爲什麼?](http://stackoverflow.com/questions/25171606/monogame-application-says-sdl-dll-is-missing-even-though-its-there-why) –

+0

大衛,我不認爲這是一個重複 - 兩個問題中的錯誤信息是不同的。有關詳細信息,請參閱下面的答案(他們太長,無法發佈評論,但我仍然沒有解決問題)。 – Stefan

回答

0

我不認爲它是重複的,因爲如果仔細觀察錯誤消息,它們會有所不同。 Tao.Sdl.dll.config文件存在於/ bin/Debug文件夾中。作爲http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/建議我打 MONO_LOG_LEVEL=debug mono /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe

和我

Mono: Assembly Loader probing location: '/usr/lib/mono/4.5/mscorlib.dll'. 
Mono: Image addref mscorlib[0x1620550] -> /usr/lib/mono/4.5/mscorlib.dll[0x161fad0]: 2 
Mono: AOT module '/usr/lib/mono/4.5/mscorlib.dll.so' not found: /usr/lib/mono/4.5/mscorlib.dll.so: cannot open shared object file: No such file or directory 

Mono: Assembly Loader loaded assembly from location: '/usr/lib/mono/4.5/mscorlib.dll'. 
Mono: Config attempting to parse: '/usr/lib/mono/4.5/mscorlib.dll.config'. 
Mono: Config attempting to parse: '/etc/mono/assemblies/mscorlib/mscorlib.config'. 
Mono: GC_MAJOR: (mature allocation failure) pause 0.58ms, total 0.58ms, bridge 0.00ms major 384K/128K los 0K/0K 
Mono: Assembly mscorlib[0x1620550] added to domain MovingTeddyBears.exe, ref_count=1 
Mono: Config attempting to parse: '/etc/mono/config'. 
Mono: Config attempting to parse: '/home/stefan/.mono/config'. 
Mono: Assembly Loader probing location: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe'. 
Mono: Image addref MovingTeddyBears[0x1689590] -> /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe[0x161e6c0]: 3 
Mono: Assembly MovingTeddyBears[0x1689590] added to domain MovingTeddyBears.exe, ref_count=1 
Mono: AOT module '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe.so' not found: /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe.so: cannot open shared object file: No such file or directory 

Mono: Assembly Loader loaded assembly from location: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe'. 
Mono: Config attempting to parse: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe.config'. 
Mono: Config attempting to parse: '/etc/mono/assemblies/MovingTeddyBears/MovingTeddyBears.config'. 
Mono: Assembly Loader probing location: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe'. 
Mono: AOT module '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe.so' not found: /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe.so: cannot open shared object file: No such file or directory 

Mono: Assembly Ref addref MovingTeddyBears[0x1689590] -> mscorlib[0x1620550]: 2 
Mono: Assembly Loader probing location: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MonoGame.Framework.dll'. 
Mono: Image addref MonoGame.Framework[0x168e8f0] -> /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MonoGame.Framework.dll[0x168da10]: 2 
Mono: Assembly MonoGame.Framework[0x168e8f0] added to domain MovingTeddyBears.exe, ref_count=1 
Mono: AOT module '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MonoGame.Framework.dll.so' not found: /home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MonoGame.Framework.dll.so: cannot open shared object file: No such file or directory 

Mono: Assembly Loader loaded assembly from location: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MonoGame.Framework.dll'. 
Mono: Config attempting to parse: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MonoGame.Framework.dll.config'. 
Mono: Config attempting to parse: '/etc/mono/assemblies/MonoGame.Framework/MonoGame.Framework.config'. 
Mono: Assembly Ref addref MovingTeddyBears[0x1689590] -> MonoGame.Framework[0x168e8f0]: 2 
Mono: Assembly Ref addref MonoGame.Framework[0x168e8f0] -> mscorlib[0x1620550]: 3 
Mono: Config attempting to parse: '/home/stefan/Downloads/LinuxMonoGameMovingTeddyBears/bin/Debug/MovingTeddyBears.exe.config'. 
Mono: Assembly Loader probing location: '/usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll'. 
Mono: Image addref System[0x169ea60] -> /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll[0x169db20]: 2 
Mono: Assembly System[0x169ea60] added to domain MovingTeddyBears.exe, ref_count=1 
Mono: AOT module '/usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll.so' not found: /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll.so: cannot open shared object file: No such file or directory 

其實,有很多更,但它太長時間,張貼在這裏。另外,如http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/中所建議的,我查看了/usr/local/lib/libgdiplus.so文件,該文件證明是鏈接到libgdiplus.so.0.0.0,但是當我嘗試用gedit打開它或vi一切都是亂七八糟的,即我看到的只是問號和奇怪的角色。有人能幫助我嗎?

相關問題