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

fix err fileExt evoke panic #55

Closed
wants to merge 0 commits into from
Closed

fix err fileExt evoke panic #55

wants to merge 0 commits into from

Conversation

cnjack
Copy link
Contributor

@cnjack cnjack commented Jan 10, 2018

No description provided.

@cnjack
Copy link
Contributor Author

cnjack commented Jan 10, 2018

a better idea:(imgcodecs.go)

func IMEncode(fileExt FileExt, img Mat) (buf []byte, err error) {
	cfileExt := C.CString(string(fileExt))
	defer C.free(unsafe.Pointer(cfileExt))

	b := C.Image_IMEncode(cfileExt, img.Ptr())
	defer C.ByteArray_Release(b)
	if b.length == 0 {
		return nil, errors.New("encoder not found")
	}
	return toGoBytes(b), nil
}

@deadprogram
Copy link
Member

Hello @cnjack looks like the Windows version of the test you added failed:
https://ci.appveyor.com/project/deadprogram/gocv/build/216#L141

Perhaps it is more sensitive about the extension syntax .jpg?

@cnjack
Copy link
Contributor Author

cnjack commented Jan 10, 2018

catch(...)is not work in mingw?
I found something in https://stackoverflow.com/questions/29271714/catch-across-shared-library-boundary-on-gcc-mingw

@deadprogram
Copy link
Member

That figures... well options are to remove the try/catch entirely, or add some conditional platform specific code in the C++. What do you think?

@deadprogram
Copy link
Member

The Appveyor build appears to be using shared libs

-DBUILD_SHARED_LIBS=ON here:

https://github.com/hybridgroup/gocv/blob/master/appveyor_build_opencv.cmd#L13

@codecov-io
Copy link

codecov-io commented Jan 11, 2018

Codecov Report

Merging #55 into dev will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev      #55      +/-   ##
==========================================
- Coverage   96.93%   96.91%   -0.03%     
==========================================
  Files          12       12              
  Lines         913      907       -6     
==========================================
- Hits          885      879       -6     
  Misses         28       28
Impacted Files Coverage Δ
imgcodecs.go 100% <100%> (ø) ⬆️
dnn.go 100% <0%> (ø) ⬆️
core.go 100% <0%> (ø) ⬆️
highgui.go 75.51% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 482de6f...fa9d1ed. Read the comment docs.

@cnjack
Copy link
Contributor Author

cnjack commented Jan 11, 2018

maybe mingw can not use try-catch?

@deadprogram
Copy link
Member

I just commented here on this Go issue, seems like applies to this PR: golang/go#13672 (comment)

@cnjack
Copy link
Contributor Author

cnjack commented Jan 12, 2018

get it, may be it's ok in go1.10

@deadprogram
Copy link
Member

Hi @cnjack I do not think this will be fixed anytime soon in Go itself, from all the comments on those issues. However, thanks to replies from @ianlancetaylor a possible solution might be to simply not perform any operations that result in memory allocations taking place in the try/catch block. E.g. something like this:

struct ByteArray Image_IMEncode(const char* fileExt, Mat img) {
    std::vector<uchar> data;
    try{
        cv::imencode(fileExt, *img, data);
        return toByteArray(reinterpret_cast<const char*>(&data[0]), data.size());
    } catch(...) {
        // do not allocate memory here, just pass thru...
    }
    // the following line should only be reached in the case that an exception was encountered...
    return toByteArray(NULL, 0);
}

That might not be best way to structure the code, but it illustrates a technique that might work. Worth a try, I think.

@cnjack
Copy link
Contributor Author

cnjack commented Jan 15, 2018

I will try soon

@cnjack
Copy link
Contributor Author

cnjack commented Jan 15, 2018

sadly, it's not work

@deadprogram
Copy link
Member

Oh well. At least we tried that, thanks for making the effort.

@cnjack
Copy link
Contributor Author

cnjack commented Jan 15, 2018

is ok, wait the go fix the problem, the last pr #54 may avoid problems such as these

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

Successfully merging this pull request may close these issues.

3 participants