Visual Studio 2008 debugger wrong instruction executed position (Qt4, XML) - c++

I have some part of code with which the debugger , when entering , starts stopping in lines with { braces.. suddenly jumps back to a blank line, and apparently is doing something (variables change), but the positions are different (there is some kind of weird offset back, skipping blank lines) and obviously i cannot see the contents of any variable.
Some facts:
I'm compiling on DEBUG
The code that fails falls inside more code which executes perfectly before.
The code does not work properly, but i double checked and it should. They are just 10 lines of code, exactly the same lines that the ones before, just changing variables names.
The debugguer stays crazy there, then out of the function in the caller function, and then returns to a normal state in the third parent function.
This code uses Qt 4.7 and QDomDocument functionality but works perfectly on other parts of the code. I added it to precompiled headers. (QXML)
I tried these with same errors:
Cleaning solution by hand or by visual
Cleaning all related Qt files (moc). Removed them, recompile, add again.
Changed the function to other part of the class.
Changed that piece of code to other part of the function.
Deleted file, removed from folder, compile, add it again and include the MOC.
Checked other threads. It is on the good thread.
Commenting the code makes it work perfect.
Here's the cursed code:
(...loaded file, check if worked)
// Assign file to dom document
QDomDocument doc("XML");
if (!doc.setContent(file)) {
file->close();
return;
}
// Root element (object)
QDomElement root = doc.documentElement();
QDomElement elt;
QDomElement elt2;
QDomElement elt3;
// NAME
elt = root.firstChildElement("name"); //-- works and debugs ok
if (!elt.isNull())
obj->setNameInfo(elt.text());
// TYPE
elt = root.firstChildElement("type"); //-- works and debugs ok
if (!elt.isNull())
obj->setTypeInfo(elt.text());
// REF NUMBER
elt = root.firstChildElement("ref"); //-- works and debugs ok
if (!elt.isNull())
obj->setRefNumberInfo( elt.text() );
// COLLECTION <collection><english>Text</english>...
elt = root.firstChildElement("collection"); //-- works and debugs ok
if (!elt.isNull())
{
elt2 = elt.firstChildElement("english");
if (!elt2.isNull())
obj->setCollectionInfo( elt2.text() );
}
// BRAND <mainBrand><id>id</id><web>url</web></brand>
elt = root.firstChildElement("mainBrand"); //-- works and debugs ok
if (!elt.isNull())
{
elt2 = elt.firstChildElement("id");
if (!elt2.isNull())
obj->setMainBrandIdInfo(elt2.text());
elt2 = elt.firstChildElement("web");
if (!elt2.isNull())
obj->setMainBrandUrlInfo(elt2.text());
}
// BRAND LIST <brands><brand><id>2</id><url>google</url></brand>...</brands>
elt = root.firstChildElement("brands");
{
QDomNodeList brands = elt.childNodes(); // AFTER THIS LINE, STARTS GOING WEIRD
if ( ! brands.isEmpty() )
{
elt2 = brands.at(0).toElement();
for ( ; !elt2.isNull(); elt2 = elt2.nextSiblingElement() )
{
QString id= "";
elt3 = elt2.firstChildElement("id");
if (!elt3.isNull())
id = elt3.text();
QString url= "";
elt3 = elt2.firstChildElement("url");
if (!elt3.isNull())
url = elt3.text();
obj->addBrandInfo(id, url);
}
}
}
// DESCRIPTION // THIS IS EXECUTED PERFECTLY BUT DEBUGGER IS STILL JUMPING AROUND
elt = root.firstChildElement("description");
if (!elt.isNull())
{
elt2 = elt.firstChildElement("english");
if (!elt2.isNull())
obj->setDescriptionInfo( elt2.text() );
}
... MORE CODE HERE. UNTIL THE END THE DEBUGGER WORKS WITH SOME WEIRD OFSET...

I discovered the answer after long hours of trials:
Reading the dissasembling of the code, we detected that Comment lines generated code, lines were not in the correct place, etcetera.
The problem comes with the encoding of the line breaks. The encoding of the file was not WINDOWS encoding. We had this set like this because we worked with MAC configurations, and we had some error messages concerning line breaks style. We choose one encoding that didn't fail since then, but now this error appeared.
The solution is to Save As... the file, selecting other options for the saving, and choose change encoding to Windows or whatever encoding you want to use.

Related

PrintDlgEx invalid argument, while PrintDlg works

Problem: I need to get PrintDlgEx working for my project, but no combination of options or arguments works for me. It gives E_INVALIDARG for any combinations of options, as the ones I copied from Microsoft samples or other online samples.
Replacing PRINTDLGEX with PRINTDLG and PrintDlgEx with PrintDlg (and eliminating the group of options only from PRINTDLGEX) works fine.
Unfortunately I need PrintDlgEx, because I really need the Apply button, to change printers or property sheet without printing, for design and preview.
Please help me find why I can't get the dialog to show.
Code: while I simplified pieces, like what should happen on successful return, or setting DEVMODE and DEVNAMES, I tried this function exactly, with the same result: Invalid Argument.
#include <QDebug>
#include <QWindow>
#include <windows.h>
void showPrintDialog()
{
// Simplifying the setup: real code passes in a QWidget *
QWidget *caller = this;
// Not returning a value or doing any work. I just want the dialog to pop up for now
// Create the standard windows print dialog
PRINTDLGEX printDialog;
memset(&printDialog, 0, sizeof(PRINTDLGEX));
printDialog.lStructSize = sizeof(PRINTDLGEX);
printDialog.Flags = PD_RETURNDC | // Return a printer device context. Without this, HDC may be undefined
PD_USEDEVMODECOPIESANDCOLLATE |
PD_NOSELECTION | // Don't allow selecting individual document pages to print
PD_NOPAGENUMS | // Disables some boxes
PD_NOCURRENTPAGE | // Disables some boxes
PD_NONETWORKBUTTON | // Don't allow networking (but it show "Find printer") so what does this do ?
PD_HIDEPRINTTOFILE; // Don't allow print to file
// Only on PRINTDLGEX
// Theis block copied from https://learn.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes?redirectedfrom=MSDN
// I have tried multiple combinations of options, including none, I really don't want any of them
printDialog.nStartPage = START_PAGE_GENERAL;
printDialog.nPageRanges = 1;
printDialog.nMaxPageRanges = 10;
LPPRINTPAGERANGE pageRange = (LPPRINTPAGERANGE) GlobalAlloc(GPTR, 10 * sizeof(PRINTPAGERANGE));
printDialog.lpPageRanges = pageRange;
printDialog.lpPageRanges[0].nFromPage = 1;
printDialog.lpPageRanges[0].nToPage = 1;
printDialog.Flags2 = 0;
printDialog.ExclusionFlags = 0;
printDialog.dwResultAction = 0; // This will tell me if PRINT
// Rest of options are also on PRINTDLG
printDialog.nMinPage = 1;
printDialog.nMaxPage = 10;
// The only options I really need
printDialog.nCopies = 1;
printDialog.hDevMode = Q_NULLPTR; // which will be better once this works
printDialog.hDevNames = Q_NULLPTR; // which will be better once this works
printDialog.hwndOwner = reinterpret_cast<HWND>(caller->windowHandle()->winId());
// Calling...
int result = PrintDlgEx(&printDialog);
qDebug() << (result == E_INVALIDARG ? "Invalid Argument\n" : "Success\n");
// It always is E_INVALIDARG
// Cleanup
if (printDialog.hDevMode)
GlobalFree(printDialog.hDevMode);
if (printDialog.hDevNames)
GlobalFree(printDialog.hDevNames);
if (printDialog.hDC)
DeleteDC(printDialog.hDC);
}
Platform: Windows 10, latest update;
Qt version: 5.12.7 or higher
(since in VM I have 5.15.1)
The fact that I am running in Qt should be irrelevant, since this is all WIN API, beyond the c++ version (11)
I can make your example work if I remove PD_NONETWORKBUTTON flag.
Please note that while it is documented for PRINTDLGA struct, it is NOT listed in PRINTDLGEXA
NOTE: I did get the same error with that flag.

New Sec-* headers in WebView2

Working with MS WebView2 in C++ I can see a number of "Sec-*"-headers if visiting https://manytools.org/http-html-text/http-request-headers/
Example of a few:
Sec-Fetch-Dest document
Sec-Fetch-User ?1
Sec-Fetch-Mode navigate
Sec-Fetch-Site none
Sec-Ch-Ua-Mobile ?0
Sec-Ch-Ua "Not A;Brand";v="99", "Chromium";v="100", "Microsoft Edge";v="100", "Microsoft Edge WebView2";v="100"
These new headers are mentioned in https://wicg.github.io/ua-client-hints/
Is there any way to access/edit those headers, preferably in C++?
It's possible to disable the Sec-Ch headers with a command line option:
--disable-features=UserAgentClientHint
and to do that from C++:
Microsoft::WRL::ComPtr<CoreWebView2EnvironmentOptions> options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
options->put_AdditionalBrowserArguments(L"--disable-features=UserAgentClientHint");
However, I want to be able to edit those values.
Further googling revealed this page which I guess answers this post:
https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
You are correct that the sec-* headers are part of the "forbidden header" lists. But they are forbidden for client code like the JS that runs on the user-agent. But user-agents like the browser can set those fields.
You can change some of the sec-* headers inside a callback added to add_WebResourceRequested. Some fields like Sec-Fetch-Site get overwritten afterwards, others like Sec-Fetch-Mode can be set, but can't be deleted because they will get a default value, if not set after the WebResourceRequestedEvent. But you can change most of the sec-ch ones like this:
NOTE: this code is only to demonstrate the approach, it's missing a bunch of error handling
EventRegistrationToken webResourceRequestedToken;
webviewWindow->AddWebResourceRequestedFilter(L"*", COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
webviewWindow->add_WebResourceRequested(
Callback<ICoreWebView2WebResourceRequestedEventHandler>([](ICoreWebView2* sender,
ICoreWebView2WebResourceRequestedEventArgs* args) {
COREWEBVIEW2_WEB_RESOURCE_CONTEXT resourceContext;
args->get_ResourceContext(&resourceContext);
ICoreWebView2WebResourceRequest* req = nullptr;
ICoreWebView2HttpRequestHeaders* headers = nullptr;
ICoreWebView2HttpHeadersCollectionIterator* iter = nullptr;
args->get_Request(&req);
req->get_Headers(&headers);
headers->GetIterator(&iter);
BOOL hasCurrent = FALSE;
iter->get_HasCurrentHeader(&hasCurrent);
std::vector<std::wstring> headersToDelete;
std::wstring secChPrefix = L"sec-ch";
while (hasCurrent) {
LPWSTR name = nullptr, value = nullptr;
iter->GetCurrentHeader(&name, &value);
if (secChPrefix.compare(0, secChPrefix.size(), name, secChPrefix.size()) == 0) {
headersToDelete.push_back(name);
}
iter->MoveNext(&hasCurrent);
}
for (auto header : headersToDelete) {
headers->RemoveHeader(header.c_str());
}
// Setting "Sec-Fetch-Site" will have no effect, will get overwritten afterwards
headers->SetHeader(L"Sec-Fetch-Site", L"same-origin");
// This will work, but removing this key will just make it take the default value
headers->SetHeader(L"Sec-Fetch-Mode", L"same-origin");
return S_OK;
}).Get(),
&webResourceRequestedToken);

question about VkPhysicalDeviceVulkan12Features

I ran into an issue when adding features to a physical device using bootstrap https://github.com/charles-lunarg/vk-bootstrap. Doing so gives me assertion failed
Assertion failed: m_init, file \vkbootstrap\VkBootstrap.h, line 132
I understand that this could indicate a bug within the vk-bootstrap source, but I wanted to rule out that it's my own fault. Here is the code snippet which im using to add (empty)VkPhysicalDeviceVulkan12Features into physical device and I wanted to know if I'm intializing it correctly
VkPhysicalDeviceVulkan12Features feat;
feat.pNext = nullptr;
feat.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
vkb::PhysicalDeviceSelector selector{ vkb_inst };
vkb::PhysicalDevice physicalDevice = selector
.set_minimum_version(1, 2)
.set_surface(_surface)
.set_required_features_12(feat)
.select()
.value();
You are not checking Results for errors.
Probably should be something like:
vkb::PhysicalDeviceSelector selector{ vkb_inst };
auto maybe_device = selector.select();
if( !maybe_device ) panic( maybe_device.error() );
vkb::PhysicalDevice device = maybe_device.value();

QString functions giving incorrect results on CentOS

I am using C++ Qt Library and following code is working perfectly on Windows but not working on CentOS :
if(line.startsWith("[", Qt::CaseInsensitive))
{
int index = line.indexOf(']', 0, Qt::CaseInsensitive);
QString subLine = line.mid(index+1);
subLine = subLine.trimmed();
tokenList = subLine.split("\t");
}
else
{
tokenList = line.split("\t");
}
I have a line [ x.x.x.x ] something ../dir/file.extension and I want to ignore the [x.x.x.x] part while breaking line into tokens. I am using VC9 on windows to debug and its working fine.
Edit: i have removed mid() and used right() still same problem persists, working on windows but not on CentOS.
Edit: after debugging on linux using QMessageBox i have concluded that control is never going inside if block, i tried using if(line.data()[0] == '[') but same results.
Your code can be simplified.
line.remove(QRegExp("\\[\\s+\\d+\\.\\d+\\.\\d+\\.\\d+\\s+\\]"));
tokenList = line.split("\t");

TaskDialogIndirect is returning an unusual error code

I'm using TaskDialogIndirect to display prompts to the user. Normally this works just fine, but sometimes, after the program has been running for a while, it begins returning an error code that the MSDN entry does not list as being one of the error codes this function can return.
0x80040001 OLE_E_ADVF "Invalid advise flags"
I have checked all the inputs to the function against previous successful calls in the same run. Aside from differences in the string to be displayed, they are identical. (the strings are even the same length.)
// create task dialog struct
TASKDIALOGCONFIG tdc;
ZeroMemory(&tdc, sizeof(TASKDIALOGCONFIG));
tdc.cbSize = sizeof(tdc);
tdc.dwFlags = (((dwMessageBoxFlags & MB_OKCANCEL) == MB_OKCANCEL) ? TDF_ALLOW_DIALOG_CANCELLATION : 0) | TDF_POSITION_RELATIVE_TO_WINDOW;
tdc.hwndParent = hwndOwner;
tdc.hInstance = LGetHInstance();
tdc.pszContent = usrText.wsz;
tdc.pButtons = _pButtons;
tdc.cButtons = nButtons;
tdc.pszMainIcon = pszTaskDialogIcon;
tdc.pszWindowTitle = usrCaption.wsz;
tdc.nDefaultButton = nDefaultButton;
// display it now
int iButton = 0;
BOOL b = 0;
HRESULT hResult = TaskDialogIndirect(&tdc, &iButton, NULL, &b);
NEW INFORMATION
At the same time that TaskDialogIndirect stops behaving correctly, ShellExecute also stops working, as does CreateFile.
This was actually caused by an event handle leak elsewhere. When the available handles ran out, no more API calls which needed to create a handle could succeed. They did return a rather odd set of error codes though, none of which was "out of handles".