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

System unexplained termination #1716

Closed
mappedbyte opened this issue Nov 4, 2021 · 19 comments
Closed

System unexplained termination #1716

mappedbyte opened this issue Nov 4, 2021 · 19 comments
Labels

Comments

@mappedbyte
Copy link

When I'm using Java2DFrameUtils.toBufferedImage(mat); Method, an exception causes the service to exit. The exception information of the error is
`#

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007f3d4d55fa41, pid=21614, tid=0x00007f3c5c7e4700

JRE version: Java(TM) SE Runtime Environment (8.0_291-b10) (build 1.8.0_291-b10)

Java VM: Java HotSpot(TM) 64-Bit Server VM (25.291-b10 mixed mode linux-amd64 compressed oops)

Problematic frame:

J 6355 C2 org.bytedeco.javacv.Java2DFrameConverter.flipCopyWithGamma(Ljava/nio/ByteBuffer;IILjava/nio/ByteBuffer;IIZDZI)V (635 bytes) @ 0x00007f3d4d55fa41 [0x00007f3d4d55eee0+0xb61]

Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

An error report file with more information is saved as:`

@mappedbyte
Copy link
Author

This problem bothered me and made it impossible for me to continue

@mappedbyte
Copy link
Author

I want to know the solution and the cause of this exception

@saudet
Copy link
Member

saudet commented Nov 4, 2021

That probably just means that the memory of the Mat that you're trying to convert has already been deallocated. In that case, you'll need to find where in your code that happens and fix this.

@mappedbyte
Copy link
Author

BufferedImage image = Java2DFrameUtils.toBufferedImage(mat.clone()); When I use it like this, the exception still exists

@mappedbyte
Copy link
Author

这可能只是意味着您尝试转换的 Mat 内存已被释放。在这种情况下,您需要找到代码中发生的位置并解决此问题。

When I looked at the previous problem, I found that java2dframeutils is not thread safe. I read the source code and found that synchronized is added. I don't think it's the problem

@mappedbyte
Copy link
Author

这可能只是意味着您尝试转换的 Mat 内存已被释放。在这种情况下,您需要找到代码中发生的位置并解决此问题。

I didn't take the initiative to release the mat object. I think the JVM system took the initiative to recycle it. I don't know how to control it

@saudet
Copy link
Member

saudet commented Nov 4, 2021

Right, this should probably be protected by a PointerScope.
Could you try to make your call inside a try (PointerScope scope = new PointerScope()) { } block?

@mappedbyte
Copy link
Author

Right, this should probably be protected by a PointerScope. Could you try to make your call inside a try (PointerScope scope = new PointerScope()) { } block?

Do you use softreference to operate? When the memory is insufficient, the GC is triggered to reclaim the memory and release it

@mappedbyte
Copy link
Author

Right, this should probably be protected by a PointerScope. Could you try to make your call inside a try (PointerScope scope = new PointerScope()) { } block?

try (Mat c = mat.clone()) { image = Java2DFrameUtils.toBufferedImage(c); }

@saudet
Copy link
Member

saudet commented Nov 4, 2021

No, please try like this:

try (PointerScope scope = new PointerScope()) {
    image = Java2DFrameUtils.toBufferedImage(mat);
}

@mappedbyte
Copy link
Author

No, please try like this:

try (PointerScope scope = new PointerScope()) {
    image = Java2DFrameUtils.toBufferedImage(mat);
}

The parent class of mat object implements the autoclosable interface, and pointerscope object also implements the autoclosable interface. After try, the close() method will be called. Sorry, I don't know the difference between mat and pointerscope in this code

@saudet
Copy link
Member

saudet commented Nov 4, 2021

Ok, that's fine, please try like this:

try (Mat c = mat.clone(); PointerScope scope = new PointerScope()) {
    image = Java2DFrameUtils.toBufferedImage(c);
}

@mappedbyte
Copy link
Author

Thank you, but when I use mat to put it in the linkedblockingqueue and another thread consumes, the memory is still full and the JVM is killed by the system

@saudet
Copy link
Member

saudet commented Nov 4, 2021

Make sure to deallocate them manually with something like Mat.close().

@mappedbyte
Copy link
Author

Make sure to deallocate them manually with something like Mat.close().

I don't know munmap_ Chunk(): invalid pointer: the reason for this problem

@saudet
Copy link
Member

saudet commented Nov 5, 2021 via email

@mappedbyte
Copy link
Author

mappedbyte commented Nov 6, 2021

That probably means you're trying to use a Mat that is already deallocated.

Hello, when I use it like this

        while(true){



    SendRstpInfo sendRstpInfo = linkedBlockingDeque.poll(50, TimeUnit.MILLISECONDS);


  try (Mat mat = sendRstpInfo.getJpg(); Mat c = mat.clone(); PointerScope scope = new PointerScope()) {

          Frame frame = drawRect(mat, dataPack.getPacks());
                    if (frame != null) {
                        recorder.record(frame);
                              }

  }
 }

   public Frame drawRect(Mat mat, List<Pack> packs) {
        BufferedImage image = null;
        try {
            log.info("开始转换成BufferedImage!!")
            image = Java2DFrameUtils.toBufferedImage(mat) 
            log.info("转换BufferedImage 成功!!");
            return addSubtitle(image, packs);
        } catch (Exception e) {
            e.printStackTrace();
        }  
  }

@saudet saudet added the bug label Nov 6, 2021
saudet added a commit that referenced this issue Nov 6, 2021
@saudet
Copy link
Member

saudet commented Nov 6, 2021

I think I've fixed this issue in commit e0d0f5c. Please give it a try with the snapshots: http://bytedeco.org/builds/

If you're still experiencing a crash with JavaCV 1.5.7-SNAPSHOT though, please let me know! Thanks for reporting

@saudet
Copy link
Member

saudet commented Feb 10, 2022

The fix has been released with JavaCV 1.5.7. Please let me know if you're still having issues with this though, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants