Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crashes when using screen capture on mac. (ogre-next v2.3 and v3) #499

Open
taesoobear opened this issue Feb 22, 2025 · 2 comments
Open
Labels
Metal Issue affects Metal specifically. Don't use this tag if all RenderSystems are affected

Comments

@taesoobear
Copy link

taesoobear commented Feb 22, 2025

How to reproduce: modify any tutorial example.
void ShadowMapFromCodeGameState::update( float timeSinceLast ) { TutorialGameState::update( timeSinceLast ); mGraphicsSystem->getRenderWindow() ->getTexture()->writeContentsToFile("a.png",0,0); }

On linux, this works fine, but on mac, it crashes because srcTextureMetal->getFinalTextureName()==NULL. Is there any easy workaround?

It might be too much information, but…
I have been using macos's "CGWindowListCreateImage" method instead of writeContentsFile on Mac. But now that macos 15 deprecated the CGWindowListCreateImage method, there is no way to capture exactly one screenshot for each timestep. The Apple's new ScreenshotKit framework doesn't seem to work with C++/objective C.

Thank you!

frame #2: 0x0000000103e079a4 RenderSystem_Metal.2.3.4.dylib`Ogre::MetalAsyncTextureTicket::downloadFromGpu(this=0x0000600003fc80a0, textureSrc=0x00006000037d47e0, mipLevel='\0', accurateTracking=true, srcBox=0x0000000000000000) at OgreMetalAsyncTextureTicket.mm:139:13
   136
   137 	        for( NSUInteger i=0; i<srcTextureBox.numSlices; ++i )
   138 	        {
-> 139 	            [blitEncoder copyFromTexture:srcTextureMetal->getFinalTextureName()
   140 	                             sourceSlice:srcTextureBox.sliceStart + i
   141 	                             sourceLevel:mipLevel
   142 	                            sourceOrigin:mtlOrigin
(lldb) down
frame #1: 0x000000010425ef18 AGXMetalG15G_C0`-[AGXG15GFamilyBlitContext copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:] + 132
AGXMetalG15G_C0`-[AGXG15GFamilyBlitContext copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:]:
->  0x10425ef18 <+132>: ldr    x8, [x19, x20]
    0x10425ef1c <+136>: ldr    w9, [x8, #0x5fc]
    0x10425ef20 <+140>: str    w9, [x8, #0x604]
    0x10425ef24 <+144>: ldp    x29, x30, [sp, #0x70]
@taesoobear taesoobear changed the title crashes when using screen capture on mac. (ogre-next v2.3) crashes when using screen capture on mac. (ogre-next v2.3 and v3) Feb 22, 2025
@darksylinc
Copy link
Member

Hi!

To be able to take a screenshot to the Window you must call Window::setWantsToDownload( true ):

// Call only once.
window->setWantsToDownload( true );

workspace->_update();

if( window->canDownloadData() )
{
    Ogre::Image2 img;
    Ogre::TextureGpu *texture = window->getTexture();
    img.convertFromTexture( texture, 0u, texture->getNumMipmaps() - 1u );
}

This only works if you download before you or OgreNext calls Window::swapBuffers. If you want to download after Window::swapBuffers, you need to call setManualSwapRelease and performManualRelease. See documentation for an example.

This API may not be available in OgreNext 2.3. If you need this to work in 2.3, a workaround is to render to an offscreen RenderTexture and download that instead. The problem arises from Window being a special case in Metal due to how the swapchain is handled.

Our UnitTesting class shows this API in action.

Cheers

@darksylinc darksylinc added the Metal Issue affects Metal specifically. Don't use this tag if all RenderSystems are affected label Feb 22, 2025
@taesoobear
Copy link
Author

I tested and this works in v3, but I do need this to work in 2.3, so I will try the renderToTexture route. Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metal Issue affects Metal specifically. Don't use this tag if all RenderSystems are affected
Projects
None yet
Development

No branches or pull requests

2 participants