Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: My Mario game crashes if I click the mouse  (Read 4920 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
My Mario game crashes if I click the mouse
« on: May 09, 2013, 12:51:42 pm »
Hello Ladies and Guys from SFML
I made a Mario game with C# .NET and SFML,

https://www.dropbox.com/s/akpuofnp6tdro7e/Super%20Mario%20Bros%20by%20Pablito.rar

My problem is that if I click the mouse while it is running, it immediatly crashes.
I tried to disable the mouse but just was able to set it invisible
If the applicaction is minimized it also crashes at restoring
A letter appears like "Your app stopped working", but at its background the app still running Ok but the screen has turned gray ... and if I press "Wait for the app to respond", the letter leaves and appears once and again

If you want, you can see this by yourselves, downloading and running the program

Could you help me,  and my program to be mouse clicking safe?
Thank you very much

Pablo Marty (Bs As, Argentina)

PS Now I m working in a very nicer version

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: My Mario game crashes if I click the mouse
« Reply #1 on: May 09, 2013, 02:03:12 pm »
We cant' see why it crashes from a binary.. We 'd need code..

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #2 on: May 09, 2013, 04:15:25 pm »
Hello
the code is quite extense, but here you have the link to it (is C#)

https://www.dropbox.com/s/5ejes56atnwbm40/CODIGO%20FUENTE.rar

it just builds the exe file,
if you want to test the program, there should be the data files, that is the folders GRAFICOS and MUSICA at the same directory level than the exe, and also the dll s, as it is in the link I passed in the previous post

Warning: the code is quite untidy; and if needed to translate it to English, please tell me and in 1 or 2 days I will ... I m sorry, sometimes neither do I understand my code

Thanks for replying
Pablo

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #3 on: May 09, 2013, 05:23:48 pm »
Please do not just give us your entire project and ask us to find your problem. I can safely say most of us probably do not have time to dig through your project to find what you are doing wrong. Please read this and then post a complete and minimal example that causes a crash when the mouse is clicked.

On a side note, its usually better if you host your code in a git repository like github or bitbucket rather than using dropbox.
« Last Edit: May 09, 2013, 05:28:07 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: My Mario game crashes if I click the mouse
« Reply #4 on: May 10, 2013, 12:36:58 am »
I m sorry, sometimes neither do I understand my code

Well, there's your problem. :)

The best way to solve any issues like this, is to create the simplest possible program you can that causes the error to occur. By that time hopefully you would have found the problem, but if not, then you should post the code here.

But at a guess, I would say the problem is in your event handler, are you checking the event.type when you process the events? (As is shown in the tutorials)


Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #5 on: May 10, 2013, 07:57:05 am »
I m not using the Events, I m just using Keyboard.IsKeyPressed(), ... I feel I can guess it s wrong? Anyway, the game works. Could this be the cause of the crash? I don t suposse that an input that is not read by the program may cause it crash
Well, I ll see if using the Events solves my problem, ... I was ignoring them cos I have the intention to use multiple threads in my program soon, and thought that using that class would make it impossible ... I suposse I m wrong in this too
Then I tell you
Thank you

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #6 on: May 10, 2013, 11:02:26 am »
Please post a complete a minimal CODE example that causes this problem, without we can NOT help you.


I m not using the Events, I m just using Keyboard.IsKeyPressed(), ... I feel I can guess it s wrong?
Quote
I made a Mario game with C# .NET and SFML
Quote
but at its background the app still running Ok but the screen has turned gray ... and if I press "Wait for the app to respond", the letter leaves and appears once and again



Without a minimal example I can only guess. If you are using the .NET package for SFML you still need to call

RenderWindow.DispatchEvents()

If you do not call that then the system event queue will stack up in your window unprocessed and cause windows to think that your application is not responding.



Quote
I was ignoring them cos I have the intention to use multiple threads in my program soon, and thought that using that class would make it impossible ...

Apparently you are new to programming (as this thread shows), so I highly recommend you do not touch multi threading. Multiple threads just add unneeded complexity for no gain to a program. Very rarely will a 2d game need to have multiple threads, so unless you discover a bottle neck that threading could solve do not multi thread your application. Be wary of premature optimization.
« Last Edit: May 10, 2013, 11:17:06 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #7 on: May 10, 2013, 10:18:50 pm »
No, I m a programmer since I was 16, now I m 33. Although I know I still need to learn so much, specially what concerns to multi threading, but I ll follow your advise, I won t use it, you re right that s not necesary

I ll do this, I ll try to use Event Handling, and then if the problem doesnt go away, I ll write a minimal but complete code example that recreates the application crash at mouse clicking, I suposse you guessed well that there is an overflow in the event queue

Could you tell me where to find the Event handling tutorial, or pass me the link? (for C# .NET) I can t find it with Google
I tried this:

App.KeyPressed += new EventHandler(App_KeyPressed);
App.KeyReleased += new EventHandler(App_KeyReleased);
App.DispatchEvents();

But the events were not launched, keys doesn t reply, I don t know how to use them in SFML

Thank you for all
////
Have you seen my game? I know it isn t the most professional, and I can t draw very well, ... but I think it s quite interesting ... What s your opinion?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #8 on: May 11, 2013, 02:12:45 am »
No, I m a programmer since I was 16, now I m 33. Although I know I still need to learn so much, specially what concerns to multi threading, but I ll follow your advise, I won t use it, you re right that s not necesary

Yes that is a good idea, I am sure you can find a lot of information on that in google.



Quote
I ll do this, I ll try to use Event Handling, and then if the problem doesnt go away, I ll write a minimal but complete code example that recreates the application crash at mouse clicking, I suposse you guessed well that there is an overflow in the event queue

Could you tell me where to find the Event handling tutorial, or pass me the link? (for C# .NET) I can t find it with Google
I tried this:

App.KeyPressed += new EventHandler(App_KeyPressed);
App.KeyReleased += new EventHandler(App_KeyReleased);
App.DispatchEvents();

But the events were not launched, keys doesn t reply, I don t know how to use them in SFML


You can find .NET examples in the SFML .NET download.
Also make sure you call DispatchEvents() in your main game loop. It needs to be called every loop to clear the event queue.
Here is an example of how the handling should work.

static void Main()
        {

            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

           
            while (window.IsOpen())
            {
               
                window.DispatchEvents();
                // Draw Here
                window.Display();
            }
        }

        static void OnClosed(object sender, EventArgs e)
        {
            //close here
        }

        static void OnKeyPressed(object sender, KeyEventArgs e)
        {
            //key pressed
        }

        static void OnResized(object sender, SizeEventArgs e)
        {
            //view port resized
        }



Quote
Have you seen my game? I know it isn t the most professional, and I can t draw very well, ... but I think it s quite interesting ... What s your opinion?

I haven't had time to look at it yet, with it being my last week of school and having a lot to work on at my job. You should make a thread for it in the projects section to share it with everyone  :D
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: My Mario game crashes if I click the mouse
« Reply #9 on: May 11, 2013, 05:43:52 pm »
I used the event handling as you told me and now the problem disappeared  :), you were right that Windows thought my app wasn t responding cos of the stack up of events, so I thank you, and all those who replied, and also those who have viewed this post (or thread), I see it has more views than most ... I don t know if many ladies and guys from SFML would have been seing my Super Mario game  8) ... I ll never know ... anyway, get ready for the next version, it s much better  ;)

There s another problem, that happened 2 times to me, on other persons' PCs, and don t know on how many others could happen, cos I want to distribute my game:
The application crashes and the command shell says:
"Unhandled exception: System.IO.FileNotFoundException: Unable to load file or assembly ´sfml-graphics-2´, Version 0.0.0.0, PublicKeyToken = null, neither one of its dependencies. System can t find the file.
.......
AVS: The assembly linking register is disabled.
To enable the assembly linking error register, set the register value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) as 1.
Note: Exists a performance decrease related to assembly linking error register.
To disable this issue, delete the register value [HKLM\Software\Microsoft\Fusion!EnableLog]."

This nice letter is in Spanish, I hope my translation is Ok.

The OS in what this occurs is Windows 7. Mine is W 7 too, and here my program runs fine. I know very little about OS s ... I think I should enable or disable something, as it says in the letter, but don t know what nor where, nor how ... Could you help, once again?  ;D