none
[UWP] Clearing frame content crashes the app on mobile RRS feed

  • Question

  • In my C++/CX app, I want to clear the frame content when user closes the hamburger menu. To do so, I set the frame content to nullptr:

    AppFrame->Content = nullptr;

    This works perfectly on desktop but it crashes the app on mobile with memory access violation exception. Do you know why and if not, do you know of any way to accomplish the same thing?

    Thank you.

    Tuesday, September 1, 2015 4:05 AM

Answers

  • Ok.

    You are getting that Access Violation (which is the equivalent of null references exception from .net) because at a latter time, something wants to access that frame content you just set to null. You need to figure out what is that something.

    You can try unloading all the UI elements of that frame, then set the frame to null. This should prevent that exception from happening. You will also probably need to stop fetching ads and do any activity in the content of that frame before setting it to null.

    Additionally, you can make the whole split view disappear by disconnecting it from the main frame. This will likely cause it to self destruct so be careful.

    One of the nasty things about the automatic memory management of c++/cx is that you can get object self destructing when you expect the least. It is possible that setting that frame content to null causes a chain reaction that causes many objects to dispose themselves and cause the error when something else tries to access them.


    Wednesday, September 2, 2015 6:03 AM

All replies

  • May I ask why you want to do that?


    You can achieve pretty much the same effect by adding an empty grid or something instead of null.
    • Edited by mcosmin Tuesday, September 1, 2015 6:44 AM
    Tuesday, September 1, 2015 6:44 AM
  • May I ask why you want to do that?


    You can achieve pretty much the same effect by adding an empty grid or something instead of null.

    I have a SwapChainPanel under a SplitView. The SplitView has a Frame as its content. When the user clicks the hamburger button, the Frame would navigate to a page to show some contents and ads. When the user clicks the hamburger button again, the SplitView would disappear. If I simply set Frame->Width to 0, the ads would still refresh in the background, so I want to destroy the Frame content. Of course, I can navigate the Frame to a blank page, but I want to see if there is a more elegant way to clear the frame content.

    Tuesday, September 1, 2015 3:27 PM
  • Ok.

    You are getting that Access Violation (which is the equivalent of null references exception from .net) because at a latter time, something wants to access that frame content you just set to null. You need to figure out what is that something.

    You can try unloading all the UI elements of that frame, then set the frame to null. This should prevent that exception from happening. You will also probably need to stop fetching ads and do any activity in the content of that frame before setting it to null.

    Additionally, you can make the whole split view disappear by disconnecting it from the main frame. This will likely cause it to self destruct so be careful.

    One of the nasty things about the automatic memory management of c++/cx is that you can get object self destructing when you expect the least. It is possible that setting that frame content to null causes a chain reaction that causes many objects to dispose themselves and cause the error when something else tries to access them.


    Wednesday, September 2, 2015 6:03 AM
  • Thanks. I just wonder why it does not crash on PC/desktop but only on mobile. I thought the whole thing about UWP is that they should work the same on all platforms...
    Wednesday, September 2, 2015 12:55 PM
  • You are likely a victim of circumstance.

    Or the libraries you are using are not really universal and behave differently.

    Wednesday, September 2, 2015 12:57 PM