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

Debug assertion thrown when trying to get values from XLRow, MSVC 2022, MFC #222

Open
rmmales opened this issue Jul 14, 2023 · 3 comments
Open

Comments

@rmmales
Copy link

rmmales commented Jul 14, 2023

Working in VS Community Edition 2022, I have successfully built OpenXLSX through CMake and DOxygen docs, run all demo programs as console apps.

I need to use OpenXLSX in an existing legacy MFC application. In Debug I can successfully open a workbook and worksheet and iterate through the rows and can view the contents of XLRow. However, as soon as I change the code to read the values in a row, a debug assertion is thrown.

Here is the code snippet:

void  CBeckyDlg::ReadExcelFile(const CString sExcelFileName)
{
	CString sTemp;
	XLDocument doc;
	// need to convert from CString to std::string
	std::string s((LPCTSTR)sExcelFileName);
	doc.open(s);
	// open the worksheet note hard-wired name, need to fix
	auto wksDE = doc.workbook().worksheet("AllDEData_7_9_2023"); 

	int column_count = wksDE.columnCount();
	int row_count = wksDE.rowCount();
	// write the worksheet size to the output file
	sTemp.Format("Excel File %s Rows %d Columns %d\n", sExcelFileName, row_count, column_count);
	gOutputFile.WriteString(sTemp);
	gOutputFile.Flush();

	int rowcounter = 0;
	XLRow tempXLRow;
	std::list<XLCellValue> writeValues;
	// iterate through the first 10 rows of the worksheet
	for (auto& row : wksDE.rows()) {
		rowcounter++;
		tempXLRow = row;
		//writeValues = tempXLRow.values();  // PROBLEM HERE IF I UNCOMMENT
		if (rowcounter > 10)
			break;
		sTemp.Format("Excel Row %d\n", rowcounter);
		gOutputFile.WriteString(sTemp);
		gOutputFile.Flush();
		}
	doc.close();
	return;
}`


This code, when run with the writeValues=tempXLRow.values() line commented out, generates output as it should:

Excel File C:\ProgramData\Beachfx\Data\AllDEData_7_9_2023.xlsx Rows 1075 Columns 27
Excel Row 1
Excel Row 2
Excel Row 3
Excel Row 4
Excel Row 5
Excel Row 6
Excel Row 7
Excel Row 8
Excel Row 9
Excel Row 10

The error that is thrown is:
Program: C:\Projects\BeachFx\BeachFxCodeWorkingCopy\Debug\BeachFx.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 996

Expression: __acrt_first_block == header

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
The thread 0x1488 has exited with code 0 (0x0).
The thread 0x3a94 has exited with code 0 (0x0).
The thread 0x60c has exited with code 0 (0x0).
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in BeachFx.exe.

Debug Assertion Failed!

Program: C:\Projects\BeachFx\BeachFxCodeWorkingCopy\Debug\BeachFx.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 996

Expression: __acrt_first_block == header

I just need a workaround so that I can extract the non-homogeneous row data (columns are variously numbers, strings, dates) from the returned std::list.

Note that I have tried various attempts from the demo examples, the above code snippet is the simplest I have found that allows the needed iteration through the rows.
@CEXT-Dan
Copy link

I’m also running this code inside a MFC app, with no issues.
Could it be compiler settings?
https://learn.microsoft.com/en-us/answers/questions/240332/assert-when-using-mtd-dynamic-library

@rmmales
Copy link
Author

rmmales commented Jul 16, 2023

Thank you for this suggestion. I am still trying to work through it, not there yet.

Do you know if it is also necessary to modify the build of OpenXLSX through CMake for debug? I am building as a static library, would this be better as a shared library?

@CEXT-Dan
Copy link

it’s been some time, I used visual studio cmake tools to generate CMakeSettings.json. for debug and release
I am also using a static library, which I think it’s better because of whole program optimization

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

No branches or pull requests

2 participants