Free Support Forum - aspose.com

Access violation in onexit.cpp when barcodes have been read

Hi

I’m getting an AV when closing my C++ application after having read barcodes with C++ lib 19.9 (installed via NuGet). The line that triggers exception later on is reader->Read().

Call stack;
aspose_cpp_vc141x64d.dll!00007ff9f08a68ee() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f08a6870() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f08a62cb() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f089ff11() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f0b3be74() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f0b3fedc() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f0b45f20() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f0b45ea0() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f0b4545b() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f0b3b2a1() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f27e6041() Unknown
> ucrtbased.dll!_execute_onexit_table::__l2::() Line 206 C++
ucrtbased.dll!__crt_seh_guarded_call::operator()<void (void),int (void) &,void (void)>(__acrt_lock_and_call::__l2::void (void) && setup, _execute_onexit_table::__l2::int (void) & action, __acrt_lock_and_call::__l2::void (void) && cleanup) Line 204 C++
ucrtbased.dll!__acrt_lock_and_call<int (void)>(const __acrt_lock_id lock_id, _execute_onexit_table::__l2::int (void) && action) Line 980 C++
ucrtbased.dll!_execute_onexit_table(_onexit_table_t * table) Line 231 C++
aspose_cpp_vc141x64d.dll!00007ff9f2626649() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f2628404() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f2628257() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f262854e() Unknown
aspose_cpp_vc141x64d.dll!00007ff9f2628641() Unknown
ntdll.dll!LdrpCallInitRoutine() Unknown
ntdll.dll!LdrShutdownProcess() Unknown
ntdll.dll!RtlExitUserProcess() Unknown
kernel32.dll!ExitProcessImplementation() Unknown
mscoreei.dll!RuntimeDesc::ShutdownAllActiveRuntimes(unsigned int,class RuntimeDesc *,enum RuntimeDesc::ShutdownCompatMode) Unknown
mscoreei.dll!CLRRuntimeHostInternalImpl::ShutdownAllRuntimesThenExit(unsigned int) Unknown
mscoreei.dll!_CorExeMain() Unknown
mscoree.dll!_CorExeMain_Exported() Unknown
kernel32.dll!BaseThreadInitThunk() Unknown
ntdll.dll!RtlUserThreadStart() Unknown

Code:

bool BarcodeHelper::barcodeExists(const unsigned char* filedata, const size_t filesize, const std::wstring& barcodetype, const std::wstring& barcodevalue)
{
	setLicense();

	System::SharedPtr<BaseDecodeType> decodetypes = DecodeType::AllSupportedTypes;
	if (barcodetype.empty() == false && barcodetype != L"Any type")
	{
		const auto x = DecodeType::AllSupportedTypes->GetSingleTypes();
		for (int idx = 0, count = x->get_Count(); idx < count; idx++)
		{
			const auto barcode = (*x)[idx];
			if (barcode->get_TypeName().ToWCS() == barcodetype)
			{
				decodetypes = barcode;
				break;
			}
		}
	}

	System::IO::MemoryStream::Ptr stream = System::MakeObject<System::IO::MemoryStream>();
	// TODO: is this really the best way of getting data into Aspose?
	for (size_t i = 0; i < filesize; i++)
		stream->WriteByte(*(filedata + i));
	stream->set_Position(0);

	bool found = false;
	System::SharedPtr<BarCodeReader> reader = System::MakeObject<BarCodeReader>(stream, decodetypes);
	while (reader->Read())
	{
		// check if optional value matches
		if (barcodevalue.empty() == true || reader->GetCodeText().ToWCS() == barcodevalue)
		{
			found = true;
			break;
		}
	}

	return found;
}

Can anyone spot any errors in my code or explain this?

Thanks,

@bleze,
You may share a simple console application which can be compiled and executed here without any missing reference along with the sample barcode files which are read for testing. We will reproduce the scenario here and share our feedback.

Thanks! Creating a console app, made it clear that I was needing;

System::AsposeCppLibrary::PrepareForUnload();

I have not seen this in the examples and my exception did not reveal this to me in a clear way.

@bleze,
We are glad to know that your issue is resolved. Please feel free to write us back if you have any other issue or query, we will try to assist you at the earliest.

Sure, maybe you can enlighten me about a better way to get data into your library than writing them byte by byte like in my code above? :slight_smile:

Here is project with helper functions. I will publish article with this functions later
ABGateway.zip (14.3 KB)

Thanks, but none of the example really show how to get for example data from a std::string/std::wstring into memorystream, or from a pointer+size. That would be useful to use library efficient with existing non-Aspose code

Thank you for ideas, I will add conversion from/to std::string and pointer+size. But I am not sure about std::wstring because memorystream in our library is used to load or save images and it requires byte sequence, but std::wstring has double bytes on element.