Skip to content
Open
Show file tree
Hide file tree
Changes from all 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,8 @@ public D3DTextureResource(D3DTextureData resource) {
public void free() {
if (resource != null) {
resource.dispose();
// resource.dispose() will free the native-side
// resource = null is not set here, ManagedResource will handle that when appropriate
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ public void update(Buffer pixels, PixelFormat format,
int srcw, int srch,
int srcscan,
boolean skipFlush) {
if (!resource.isValid()) {
return;
}

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

Expand Down Expand Up @@ -774,6 +778,10 @@ public void update(Buffer pixels, PixelFormat format,

@Override
public void update(MediaFrame frame, boolean skipFlush) {
if (!resource.isValid()) {
return;
}

Comment on lines +781 to +784
Copy link
Member

Choose a reason for hiding this comment

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

I see that you applied this to both D3D and ES2. The corresponding MTLTexture also has an update(MediaFrame frame, ...) method which does not have this check. For consistency, it might be worth adding it there, too.

if (!skipFlush) {
context.flushVertexBuffer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ES2TextureResource<T extends ES2TextureData>
public void free() {
if (resource != null) {
resource.dispose();
// resource.dispose() will free the native-side
// resource = null is not set here, ManagedResource will handle that when appropriate
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public void flushVertexBuffer() {
}

protected final void flushMask() {
// TODO: This solution might be only temporary
// maskTex gets occasionally disposed before we enter this area, entering update() throws NPE
// We should hold the maskTex lock long enough to push the update through and unlock it after renderQuads completes.
if (maskTex == null || maskTex.isSurfaceLost()) return;

if (curMaskRow > 0 || curMaskCol > 0) {
maskTex.lock();
// assert !maskTex.isSurfaceLost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ public void update(Buffer buffer, PixelFormat format,

@Override
public void update(MediaFrame frame, boolean skipFlush) {
if (!resource.isValid()) {
return;
}

if (frame.getPixelFormat() == PixelFormat.MULTI_YCbCr_420 ||
frame.getPixelFormat() != PixelFormat.BYTE_APPLE_422) {
// Shouldn't have gotten this far
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class MTLTextureResource<T extends MTLTextureData> extends DisposerManagedResour
public void free() {
if (resource != null && canDispose) {
resource.dispose();
// resource.dispose() will free the native-side
// resource = null is not set here, ManagedResource will handle that when appropriate
}
}
}