Question

Is there a possibility to get the current call stack in windows store apps, without throwing an exception?

I found this answer but it doesn't apply to windows store apps.

Why do I need this

I need to get the call stack, because I have a DirectX texture memory leak.

I want to attach the call stack to my textures when I allocate them. After some program use I print the callstacks of all textures that have not been deallocated.

It should be very easy to see where I forgot to deallocate textures.

Était-ce utile?

La solution

There is no documented way for gaining access to the current stack like exists in .NET (like with StackFrame).

You could try to maintain a log or record of the execution yourself by creating a function which records the operations. It would require a little bit of pasting into functions:

[Conditional("DEBUG")]
void Log(string message, 
      [CallerMemberName] string member = "", 
      [CallerFilePath] string path = "", 
      [CallerLineNumber] int line = 0 ) {
    Debug.WriteLine(string.Format("{0}\t{1}:{3} ({2}) ", 
         message, member, path, line));
}

Using...

Log("hello!");

Would produce:

hello!  MainPage_Loaded:45 (c:\Dev\Projects\Win8AppTest\MainPage.xaml.cs) 

The above function uses several relatively recent attributes you can use. For example: CallerMemberName. That function obtains the method or property name of the caller.

The Conditional attribute just says to only compile the function in DEBUG builds.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top