Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public D3DContext getContext() {
@Override
public void update(MediaFrame frame, boolean skipFlush)
{
if (!resource.isValid()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related - D3DTextureResource line 40 is

    public void free() {
        if (resource != null) {
            resource.dispose();
        }
    }

should there be resource = null; after resource.dispose() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could add another layer of safety and make any potential future NPEs more easy to track - I'll add this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In looking more closely at the code, it looks like adding resource = null in free() is redundant, since every caller of free() already does it right after calling it. It doesn't seem harmful, though.

return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these the only two places where we need the check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as far as I know other Prism-backend-specific resources already do similar checks, either Java side or Native side.


if (frame.getPixelFormat() == PixelFormat.MULTI_YCbCr_420) {
// shouldn't have gotten this far
throw new IllegalArgumentException("Unsupported format "+frame.getPixelFormat());
Expand Down Expand Up @@ -138,6 +142,10 @@ public void update(Buffer pixels, PixelFormat format,
int srcscan,
boolean skipFlush)
{
if (!resource.isValid()) {
return;
}

checkUpdateParams(pixels, format,
dstx, dsty, srcx, srcy, srcw, srch, srcscan);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public D3DTextureResource(D3DTextureData resource) {
public void free() {
if (resource != null) {
resource.dispose();
resource = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not set the resource to null for any classes like D3DTextureResource, MTLTextureResource or ES2TextureResource. But the actual reference to native resource is set to 0 in the resource.dispose(); call ( i.e. in classes like, D3DTextureData, MTLTextureData, ES2TextureData ). So the actual dispose of resource is already guarded.

Setting null only for D3D may cause confusion, as to why is it not done for other pipelines.
So, I would recommend to remove, as current code is safe. Or
add the same for other pipelines as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a comment that the resource is freed natively so there's no need to dereference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a good idea (for all pipelines).

Copy link
Contributor Author

@lukostyra lukostyra Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make more sense, I noticed that we also often check resource.isValid() but we don't precede it with resource == null which would cause another potential NPE.

I'll revert this and add a comment in all backend-specific *TextureResource classes

EDIT: I got the resource instances mixed up - the checks I was thinking of would be for an instance of D3D/ES2/MTLTextureResource, not its underlying D3D/ES2/MTLTextureData instance that is also referred to as resource variable.

Still, the ManagedResource class that we extend in the backends will handle the resource = null set, so this addition is redundant.

}
}

Expand Down