Skip to main content
GameDev.net gamedev.net
🔒 Locked

Mysterious SDL.net exception [ SDL.NET bug - unsolved]

Started by RKillian Jun 22, 2006 at 7:23 PM 4 replies 1.8k views
Original Post
RKillian
RKillian
Hey guys, I need some help here. 1. No matter what I set delay or targetfps to, I always get exactly 1 frame per second. It ruins half the reason I went with .net as opposed to the C version. If only Torque2D didn't need networking kludged in (and a TGE license for the code to be kludged)... 2. When I close the application, I get 2 different errors. The first time I get "illegal access at 0x00000000 could not be 'written'" from Windows and the second time I just get a similar error from Visual Studio's debugger. I guess it could be complaining about the screen/sprite/bitmap context but I have no idea how to appease it or where to do so. 3. Sort of related, Alt+F4 won't cause a quit event on this or regular SDL. Am I supposed to check the keyboard handler for Alt+F4 manually? I didn't find anything in their 10 pages of very sparse docs and Google didn't point anywhere but their site. Using .net 2.0 on Windows 2000 SP4 with over a GB of RAM, so it can't be the system.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SdlDotNet;
using SdlDotNet.Sprites;
using SdlDotNet.Windows; 

namespace WindowsApplication2
{
    public class Program
    {
        SdlDotNet.Sprites.AnimatedSprite Hero = new SdlDotNet.Sprites.AnimatedSprite();
        
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        public static void Main ()
        {
            Program Application = new Program();
            Application.Run();
        }

        public Program ()
        {
            SdlDotNet.Video.SetVideoModeWindow(320, 240, 16, false);
            SdlDotNet.Video.WindowCaption = "RRK - C# 2005 - Windows 2000 - SDL 4.0";

            SdlDotNet.SurfaceCollection MainFile = new SdlDotNet.SurfaceCollection("./graphics/SmallFoot.png", new System.Drawing.Size(64, 64));
            SdlDotNet.Sprites.Animation Temporary;

            Temporary = new SdlDotNet.Sprites.Animation();
            Temporary.Add(MainFile[0]);
            Temporary.Add(MainFile[32]);
            Temporary.Add(MainFile[0]);
            Temporary.Add(MainFile[40]);
            Temporary.Delay = 1000;
            Hero.Animations.Add("MS", Temporary);

            Temporary = new SdlDotNet.Sprites.Animation();
            Temporary.Add(MainFile[1]);
            Temporary.Add(MainFile[33]);
            Temporary.Add(MainFile[1]);
            Temporary.Add(MainFile[41]);
            Temporary.Delay = 1000;
            Hero.Animations.Add("ME", Temporary);

            Temporary = new SdlDotNet.Sprites.Animation();
            Temporary.Add(MainFile[2]);
            Temporary.Add(MainFile[34]);
            Temporary.Add(MainFile[2]);
            Temporary.Add(MainFile[42]);
            Temporary.Delay = 1000;
            Hero.Animations.Add("MW", Temporary);

            Hero.CurrentAnimation = "MS";
            Hero.Animate = true;
        }

        public void Run()
        {
            SdlDotNet.Events.TargetFps = 30;
            SdlDotNet.Events.KeyboardDown += new SdlDotNet.KeyboardEventHandler(this.OnKeyboardDown);
            SdlDotNet.Events.Tick += new SdlDotNet.TickEventHandler(this.OnTick);
            SdlDotNet.Events.Quit += new SdlDotNet.QuitEventHandler(this.OnQuit);
            SdlDotNet.Events.Run();
        }

        private void OnKeyboardDown(System.Object Sender, SdlDotNet.KeyboardEventArgs Arguments)
        {
            //if (e.Key == Key.Escape || e.Key == Key.Q)
            //{
            //    Events.QuitApplication();
            //}
        }

        private void OnTick(System.Object Sender, SdlDotNet.TickEventArgs Arguments)
        {
            //screen.Fill(Color.Black);
            //screen.Blit(surface);
            //screen.Flip();
            Video.Screen.Fill(System.Drawing.Color.Black);
            Video.Screen.Blit(Hero);
            Video.Screen.Flip();
        }

        private void OnQuit(System.Object Sender, SdlDotNet.QuitEventArgs Arguments)
        {
            Hero.Kill();
            SdlDotNet.Events.QuitApplication();
        }
    }
}
[Edited by - RKillian on June 28, 2006 11:47:58 AM]
RKillian
RKillian
So nobody knows how not to crash SDL.net on exit?
Rob Loach
Rob Loach
I tried it with the following code along with the HeroExample Hero.png and it worked without any problems. It didn't crash on exit.

using System;using System.Collections.Generic;using SdlDotNet;using SdlDotNet.Sprites;using SdlDotNet.Windows;namespace Program{    public class Program    {        SdlDotNet.Sprites.AnimatedSprite Hero = new SdlDotNet.Sprites.AnimatedSprite();        /// <summary>        /// The main entry point for the application.        /// </summary>        [STAThread]        public static void Main()        {            Program Application = new Program();            Application.Run();        }        public Program()        {            SdlDotNet.Video.SetVideoModeWindow(320, 240, 16, false);            SdlDotNet.Video.WindowCaption = "RRK - C# 2005 - Windows 2000 - SDL 4.0";            SdlDotNet.SurfaceCollection MainFile = new SdlDotNet.SurfaceCollection("Hero.png", new System.Drawing.Size(24, 32));            SdlDotNet.Sprites.Animation Temporary;            Temporary = new SdlDotNet.Sprites.Animation();            Temporary.Add(MainFile[0]);            Temporary.Add(MainFile[1]);            Temporary.Add(MainFile[2]);            Temporary.Delay = 1000;            Hero.Animations.Add("MS", Temporary);            Temporary = new SdlDotNet.Sprites.Animation();            Temporary.Add(MainFile[3]);            Temporary.Add(MainFile[4]);            Temporary.Add(MainFile[5]);            Temporary.Delay = 1000;            Hero.Animations.Add("ME", Temporary);            Temporary = new SdlDotNet.Sprites.Animation();            Temporary.Add(MainFile[6]);            Temporary.Add(MainFile[7]);            Temporary.Add(MainFile[8]);            Temporary.Delay = 1000;            Hero.Animations.Add("MW", Temporary);            Hero.CurrentAnimation = "MS";            Hero.Animate = true;        }        public void Run()        {            SdlDotNet.Events.TargetFps = 30;            SdlDotNet.Events.KeyboardDown += new SdlDotNet.KeyboardEventHandler(this.OnKeyboardDown);            SdlDotNet.Events.Tick += new SdlDotNet.TickEventHandler(this.OnTick);            SdlDotNet.Events.Quit += new SdlDotNet.QuitEventHandler(this.OnQuit);            SdlDotNet.Events.Run();        }        private void OnKeyboardDown(System.Object Sender, SdlDotNet.KeyboardEventArgs Arguments)        {            //if (e.Key == Key.Escape || e.Key == Key.Q)            //{            //    Events.QuitApplication();            //}        }        private void OnTick(System.Object Sender, SdlDotNet.TickEventArgs Arguments)        {            //screen.Fill(Color.Black);            //screen.Blit(surface);            //screen.Flip();            Video.Screen.Fill(System.Drawing.Color.Black);            Video.Screen.Blit(Hero);            Video.Screen.Flip();            Video.WindowCaption = Arguments.Fps + " FPS";        }        private void OnQuit(System.Object Sender, SdlDotNet.QuitEventArgs Arguments)        {            Hero.Kill();            SdlDotNet.Events.QuitApplication();        }    }}


The reason your animated sprite is only moving one frame a second is because you set the delay between frames to 1000 milliseconds:
Temporary.Delay = 1000;
If you set it to something less, the animation will move faster. You're also getting 30 FPS, it's just that it looks slower because your animation was moving only one frame per second. In the code I provided you, I reported the FPS to the window caption, you'll see that it's running at about 30 FPS.

You're right about ALT-F4. Would that have to do with SDL not passing the Quit event?
Rob Loach [Website] [Projects] [
RKillian
RKillian
Guess I forgot to edit the post, Alt+F4 is indeed manual and the delay problem was solved. It just didn't show any difference the first couple times I changed delay and then all of a sudden it did. I find it astonishing that you didn't get the Quit crash though. Maybe you got lucky and caught it in between ticks or something, because I get it every single time I try to close the window. It just keeps throwing up that 0x00000000 error over and over whether it's from Microsoft's IDE or launched EXE itself.

I've compiled and run a couple other .NET applications and it appears to be an isolated (SDL) occurrence. At this point I guess it's something that can be ignored for awhile...it's at least a little less scary than the 95 warnings STL and C SDL are giving me in the other thread :/
RKillian
RKillian
So I've gone and tried your code and...it still crashes. I've tried my code and gotten it to shut off correctly once or twice. It in fact appears that it doesn't like being shut down in the middle of a draw cycle and you were very lucky to miss that in your attempt. Removing the Tick callback and stalling does not appear to change the odds of winning that particular game of Russian Roulette.
jendave
jendave
I tried out the code and had no problem exiting the example. What version of SDL.NET are you using? Are the SdlDotNet.dll and Tao.Sdl.dll installed in the GAC? If so, you may want to remove them and try just having the assemblies in the same directory as the exe.

BTW, you mention the "very sparse docs". What docs need to be improved? There are a number of tutorials and examples on the SDL.NET website, but what else needs to be added to help?
SDL.NET http://cs-sdl.sourceforge.netTao.Sdlhttp://mono-project.com/Tao

Topic Locked

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

Sign in to reply to this topic.