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

Author Topic: PInvoke Stack Imbalance  (Read 5283 times)

0 Members and 1 Guest are viewing this topic.

WarHampster

  • Newbie
  • *
  • Posts: 4
    • View Profile
PInvoke Stack Imbalance
« on: July 05, 2010, 04:35:37 am »
Hey, I'm trying to get SFML set up with Visual C# 2010. I'm getting this warning when I run some simple test code:

Quote
A call to PInvoke function 'sfmlnet-graphics!SFML.Graphics.RenderWindow::sfRenderWindow_Create' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.


Here's the code, it's adapted from the example in the SFML dotnet documentation:

Code: [Select]
using System;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace Example
{
    class Program
    {
        static void OnClose(object sender, EventArgs e)
        {
            // Close the window when OnClose event is received
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void Main(string[] args)
        {
            // Create the main window
            RenderWindow app = new RenderWindow(new VideoMode(800, 600), "SFML window");
            app.Closed += new EventHandler(OnClose);

            // Start the game loop
            while (app.IsOpened())
            {
                // Process events
                app.DispatchEvents();

                // Clear screen
                app.Clear();

                // Update the window
                app.Display();
            }
        }
    }
}



If I turn off MDA warnings then everything runs fine, but I'm thinking that a stack imbalance is serious and that I should look into it. Any ideas?

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
PInvoke Stack Imbalance
« Reply #1 on: July 05, 2010, 04:46:21 am »
What version of SFML? This should be fixed in the latest revision of 2.0.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
PInvoke Stack Imbalance
« Reply #2 on: July 05, 2010, 08:13:32 am »
I don't know why the compiler thinks that the managed signature doesn't match the unmanaged one. It looks ok to me, but I'm not a .Net expert so I may miss something.

Quote
This should be fixed in the latest revision of 2.0.

Really? That's good news :lol:
Laurent Gomila - SFML developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
PInvoke Stack Imbalance
« Reply #3 on: July 06, 2010, 04:11:50 am »
Quote from: "Laurent"
I don't know why the compiler thinks that the managed signature doesn't match the unmanaged one. It looks ok to me, but I'm not a .Net expert so I may miss something.

Quote
This should be fixed in the latest revision of 2.0.

Really? That's good news :lol:


http://www.sfml-dev.org/forum/viewtopic.php?t=2529

WarHampster

  • Newbie
  • *
  • Posts: 4
    • View Profile
PInvoke Stack Imbalance
« Reply #4 on: July 06, 2010, 04:34:42 am »
Ah, I was using 1.6. I guess the latest 2.0 is stable? And if not, can I safely disable the warning?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
PInvoke Stack Imbalance
« Reply #5 on: July 06, 2010, 08:43:51 am »
Quote from: "Spodi"
http://www.sfml-dev.org/forum/viewtopic.php?t=2529

Wow, I had completely forgotten this one :shock:
thank you for the reminder.

Quote
Ah, I was using 1.6. I guess the latest 2.0 is stable?

It is stable, but still not complete (which means that changes will still happen before the final release).

Quote
And if not, can I safely disable the warning?

I think so. So far, everything always worked fine.
Laurent Gomila - SFML developer