Graphics

 View Only
  • 1.  XPression "xpScene.GetRenderedFrame" method cause memory leak

    Posted 11-03-2019 03:48

    Hi,

    I'm writing a C# application which take snapshots of XPression scene output, and save it to TGA file by 5 second interval.

    I found that, when I use "xpScene.GetRenderedFrame(double, long, long, out xpImage)" to get the image, the memory usage will be increased by the "xpImage.Size", and keep accumulating.

    After the application runs several minutes, XPression log "Largest available memory block size" will become fewer and XPression Debug Monitor will show "Engine error on call GetRenderedFrame (failed rendering frame)".

    Is it possible to force XPression release the memory by calling a method?

    Moreover, if I use .NET library "xpTools.xpImageToFile(xpImage, IMAGE_TYPE, string)" to save the xpImage to Bitmap file, the memory can be released, but it does not release the memory by COM library "xpToolsInstance.ImageToFile(xpImage, IMAGE_TYPE, string)" as I want to save it as TGA or PNG with alpha channel.

    Thanks in advance.

    Nero



  • 2.  RE: XPression "xpScene.GetRenderedFrame" method cause memory leak

    Posted 11-04-2019 03:23

    What version number are you using?


    #XPression


  • 3.  RE: XPression "xpScene.GetRenderedFrame" method cause memory leak

    Posted 11-04-2019 04:19

    Hi Brian,

    I'm using Studio SCE 4.1 build 2141 and Studio SCE 9.0 build 4842 (32-bit), both version got the same issue.

     

    Here is the code snippet:

    private void snapshotTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
    takeSnapShot();
    }

    private void takeSnapShot()
    {
    Console.WriteLine("Take a Snapshot");

    string snapshotPath = Path.Combine(xpProjectPath, "Snapshots");
    string tgaExt = ".tga";
    int s = 0;
    int w = 1920;
    int h = 1080;

    if (!Directory.Exists(snapshotPath))
    Directory.CreateDirectory(snapshotPath);

    snapshotPath = Path.Combine(snapshotPath, DateTime.Now.ToString("yyyyMMdd_HHmmss"));

    xpScenes[curOnlineScene].GetRenderedFrame(s, w, h, out xpSnapshot);
    Console.WriteLine("Save File to: {0} - {1} - Size:{2}", snapshotPath + tgaExt, xpTool.ImageToFile(xpSnapshot, xpToolsLib.IMAGE_TYPE.IT_TGA, snapshotPath + tgaExt), xpSnapshot.Size);
    }

     

    Here is the XPression log:

    04-11-19 11:46:41.194: Loading project: D:\XPression Bug Test\LiveIn_Time\LiveIn_Time_v1.xpf
    04-11-19 11:46:41.196: Project LiveIn_Time_v1.xpf was saved using version . build .
    04-11-19 11:46:41.228: Projects loaded: 1, memory in use: 8.764 MB, delta: 180.8 KB, largest block available: 1.854 GB, efficiency: 19%
    04-11-19 11:46:41.231: Active project is now: LiveIn_Time_v1 (D:\XPression Bug Test\LiveIn_Time\LiveIn_Time_v1.xpf)
    04-11-19 11:46:41.259: Active scene is: LiveIn (1)
    04-11-19 11:47:00.250: Scene Online >>> "LiveIn" (1) on Framebuffer 1 Layer 0 Trans Cut
    04-11-19 11:47:14.211: Largest available memory block size: 1.847 GB Total Memory Allocated: 8.907 MB Process Memory Used: 971.7 MB
    04-11-19 11:48:14.213: Largest available memory block size: 1.847 GB Total Memory Allocated: 8.916 MB Process Memory Used: 1.181 GB
    04-11-19 11:49:15.212: Largest available memory block size: 1.684 GB Total Memory Allocated: 8.929 MB Process Memory Used: 1.414 GB
    04-11-19 11:50:16.213: Largest available memory block size: 1.451 GB Total Memory Allocated: 8.941 MB Process Memory Used: 1.646 GB
    04-11-19 11:51:17.214: Largest available memory block size: 1.211 GB Total Memory Allocated: 8.955 MB Process Memory Used: 1.889 GB
    04-11-19 11:52:17.216: Largest available memory block size: 1002 MB Total Memory Allocated: 8.973 MB Process Memory Used: 2.129 GB
    04-11-19 11:53:18.217: Largest available memory block size: 763.8 MB Total Memory Allocated: 8.985 MB Process Memory Used: 2.353 GB
    04-11-19 11:54:19.218: Largest available memory block size: 525.7 MB Total Memory Allocated: 8.998 MB Process Memory Used: 2.585 GB
    04-11-19 11:55:20.219: Largest available memory block size: 279.6 MB Total Memory Allocated: 9.011 MB Process Memory Used: 2.833 GB
    04-11-19 11:55:42.219: Largest available memory block size: 192.3 MB Total Memory Allocated: 9.017 MB Process Memory Used: 2.918 GB
    04-11-19 11:56:03.219: Largest available memory block size: 112.9 MB Total Memory Allocated: 9.021 MB Process Memory Used: 2.996 GB
    04-11-19 11:56:19.220: Largest available memory block size: 49.45 MB Total Memory Allocated: 9.025 MB Process Memory Used: 3.058 GB
    04-11-19 11:56:25.220: Largest available memory block size: 25.64 MB Total Memory Allocated: 9.026 MB Process Memory Used: 3.081 GB
    04-11-19 11:56:30.221: Largest available memory block size: 7.711 MB Total Memory Allocated: 16.94 MB Process Memory Used: 3.112 GB
    04-11-19 11:56:36.218: Largest available memory block size: 9.762 MB Total Memory Allocated: 9.028 MB Process Memory Used: 3.097 GB
    04-11-19 11:56:38.266: Scene Offline <<< "LiveIn" (1) on Framebuffer 1 Layer 0 Trans Cut
    04-11-19 11:56:38.304: Releasing 1 out of 1 allocated COM scenes.

     

    Here is the Debug Monitor log:

    04-11-2019 11:46:41 Notify: Loading project: D:\XPression Bug Test\LiveIn_Time\LiveIn_Time_v1.xpf
    04-11-2019 11:56:29 Error: Engine error on call GetRenderedFrame (failed rendering frame).
    04-11-2019 11:56:31 Error: Engine error on call GetRenderedFrame (failed rendering frame).
    04-11-2019 11:56:33 Error: Engine error on call GetRenderedFrame (failed rendering frame).
    04-11-2019 11:56:35 Error: Engine error on call GetRenderedFrame (failed rendering frame).
    04-11-2019 11:56:37 Error: Engine error on call GetRenderedFrame (failed rendering frame).

    #XPression


  • 4.  RE: XPression "xpScene.GetRenderedFrame" method cause memory leak

    Posted 11-04-2019 13:36

    Thanks for the details.  We will review and get back to you.


    #XPression


  • 5.  RE: XPression "xpScene.GetRenderedFrame" method cause memory leak

    Posted 11-05-2019 15:26

    I think the xpImage objects are holding on to the memory until the .NET garbage collector cleans them up. 

    Can you add a gc.collect() line to the bottom of the TakeSnapshot function to confirm that the memory is free'd when the .NET objects are cleaned up?

     

     


    #XPression


  • 6.  RE: XPression "xpScene.GetRenderedFrame" method cause memory leak

    Posted 11-06-2019 01:48

    Wow! The memory is really released by "GC.Collect()".

     

    Thank you very much, Brain.


    #XPression