dimanche 26 avril 2015

Why the variable in the library class project value is changing but in the windows application project the variable value is all the time 0 ?

I have a solution with two projects.

The first one is class library the second one is windows forms application.

I added a variable to the class library project class, i will not add here all the class code since it's long.

namespace Capture.Hook
{
    public class DXHookD3D9: BaseDXHook
    {
        public DXHookD3D9(CaptureInterface ssInterface)
            : base(ssInterface)
        {
        }

        LocalHook Direct3DDevice_EndSceneHook = null;
        LocalHook Direct3DDevice_ResetHook = null;
        LocalHook Direct3DDevice_PresentHook = null;
        LocalHook Direct3DDeviceEx_PresentExHook = null;
        object _lockRenderTarget = new object();
        Surface _renderTarget;
        public static int framespersecondtodisplay = 0;

        protected override string HookName
        {
            get
            {
                return "DXHookD3D9";
            }
        }

The variable i added is: framespersecondtodisplay.

And i'm using the variable in this DXHooKD3D9 class in this place:

if (this.FPS.GetFPS() >= 1)
                        {
                            font.DrawText(null, String.Format("{0:N0} fps", this.FPS.GetFPS()), 5, 5, SharpDX.Color.Red);
                        }

                        if (this.TextDisplay != null && this.TextDisplay.Display)
                        {
                            font.DrawText(null, this.TextDisplay.Text, 5, 25, new SharpDX.ColorBGRA(255, 0, 0, (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f))));
                            framespersecondtodisplay = (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f));
                        }

Then in the form1 of the windows forms application project i'm using the variable like this:

txtDebugLog.Invoke(new MethodInvoker(delegate()
                {
                    fps.Frame();
                    ggg = fps.GetFPS();
                    string s = ggg.ToString("R");
                    txtDebugLog.Text = String.Format("{0:00.0}\r\n{1}", ggg.ToString("N14"), txtDebugLog.Text);
                    txtDebugLog.Text = String.Format("{0}\r\n{1}", DXHookD3D9.framespersecondtodisplay.ToString(), txtDebugLog.Text);

                })               
            );

txtDebugLog is a TextBox

Then what i'm doing is running the windows forms application project and then in the visual studio menu make Debug > Attach to Process and added two breakpoints one in the DXHooKD3D9 class in the library class project on this line:

framespersecondtodisplay = (byte)Math.Round((Math.Abs(1.0f - TextDisplay.Remaining) * 255f));

It stop on this line first and i make F5 continue and i see a value in this variable for example framespersecontodisplay is now with the value 24

I make continue then it stop in the form1 breakpoint on the line:

txtDebugLog.Text = String.Format("{0}\r\n{1}", DXHookD3D9.framespersecondtodisplay.ToString(), txtDebugLog.Text);

But here the value of framespersecondtodisplay is all the time 0.

If the breakpoint first stop in the DXHooKD3D9 class and the value there is 24 or 48 or 244 or 100 why in form1 it's all the time 0 ? Why it's not passing the current value as it is in the DXHooKD3D9 ?

Since it didn't work i tried to change in the library class project the variable to this:

public static byte framespersecondtodisplay = 0;

But still in form1 the variable show 0 all the time. I also tried to change it from static only to public:

public byte framespersecondtodisplay = 0;

And then in form1 to create instance for the DXHookD3D9:

CaptureInterface ci;
DXHookD3D9 dxd9;

In constructor:

ci = new CaptureInterface();
dxd9 = new DXHookD3D9(ci);

Then:

txtDebugLog.Text = String.Format("{0}\r\n{1}", dxd9.framespersecondtodisplay, txtDebugLog.Text);

But framespersecondtodisplay still showing 0 all the time.

Aucun commentaire:

Enregistrer un commentaire