LoadFrame (MFC) failing only in Australia - c++

Our team has a bug that has stumped us.
The following code returns false:
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
{
AfxMessageBox(GetStr(IDS_MAINFRM_FAIL_TO_LOAD));
ASSERT(FALSE);
return FALSE;
}
We're compiling using VS2010, and we do have the RogueWave Stingray component installed. The CMainFrame is a CBCGPMDIFrameWnd which is based off of a CMDIFrameWnd and made by BCGSoft.
We have our software running on about 100 machines globally with no issues. Its running on Windows 7-10 x86 & x64. It always worked, until this week. A small group of people in Mildura, Australia have reported an issue. For all of them, running WIN7x86Enterprise and Win10x64Home, the code snippet above returns false. I personally inspected one of their machines (Win10x64Home) and everything seems to be in order.
I've tried deleting the RES and APS files for the project. That didn't help.
Does anyone know what the problem might be? I'm open to educated guesses.
Thanks in advance!
PS: New Info:
It looks like its a time issue. On the computer, everything UTC+ fails, and UTC0 & UTC- pass. We aren't sure why. Any help would be appreciated. Thanks!

We were doing TimeDate calcs on an elapsed timestamp using the epoch as a starting point. MFC doesn't allow dates before the epoch, so all UTC+ failed the date creation. This bug has been fixed. Thank you to everyone.
Here is the code that was causing the issue (fixed). We added one day on for everything to work. CTime::CTime(1970,1,1,0,0,0) w/ UTC+ ,making it before 1/1/1970 in London, fails.
Thanks!
CTime t1 = CTime::CTime(yearInt,monthInt,dayInt,0,0,0);
CTime t2 = CTime::CTime(1970,1,2,0,0,0);
CTimeSpan timeSpan = t1-t2;
versionDate = timeSpan.GetDays() + 1;

Related

PdhAddCounter no longer works in Windows 10 with new SDK 10.0.22621.0

C++, Visual Studio 2019, Windows 10, SDK 10.0.22621.0
As part of my app's log file, I have collected a few bits of information about the user's computer.
I would start the query with:
static PDH_HQUERY cpuQuery;
static PDH_HCOUNTER cpuTotal;
PDH_STATUS status;
status = PdhOpenQuery(NULL, NULL, &cpuQuery);
and then get the bits of information starting with:
status = PdhAddCounter(cpuQuery, L"\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal);
if (status != ERROR_SUCCESS) {
csData += _T("GetCPURAMStatsinThread - status Add Counter Processor Time Error 2 and return *********\n");
log_write(csData);
return -1;
}
I just noticed that I am now getting the error from PdhAddCounter as:
0xC0000BB8 (PDH_CSTATUS_NO_OBJECT) The specified object is not found on the system.
The only thing that I can think of that has changed since this used to work was that I updated to SDK 10.0.22621.0. I believe that it worked with 10.0.17763.0.
I have not been paying attention to these lines in the log file, but when a customer had a problem that had to do with how many cores his CPU had, and how many virtual processors it had, then that is when I realized that these lines have been erroring out.
I have a laptop that had Windows 7, but I upgraded it to Windows 10, and ran the app on that, and it did not error out. So, does this mean an issue with the Windows 10 update, or the SDK update?
Per my comments above with #Tony Lee I used the MS sample code to browse the counters on my local computer. There was a Processor Information selection vs my original Processor under which there was a Processor Time selection. In the choice box below that there was an all instances choice and a _Total choice. When I selected the _Total choice the buffer in the sample code stayed as NULL but if I selected the all instances the buffer filled with:
L"\Processor Information(*)\% Processor Time"
Plugging that string into PdhAddEnglishCounter() worked...
Edit it also worked with PdhAddCounter()
Using Processor instead of Processor Information and (_Total) Instead of (*) used to work in Windows 10. No telling why things have changed at least on some computer.
Ed
EDIT Important note. First is that the new code above also works on the laptop on which the original code worked. Second note is that I just realized that the desktop on which the original code failed is Windows 10 Home whereas the laptop on which the original code worked is Windows 10 Pro. That maybe the difference. Regardless, the new code works on both Home and Pro.
EDIT 2 The new code also ran fine on Windows 11 Home. I also see that my customer in whose log file I noticed the error line was on Windows 11 Home. That would insinuate that the Pro version still works with the legacy (see next comment by Tony Lee) Processor while the Home versions do not work with the legacy Processor but only with the new Processor Information

Visual Studio C++ : same program using different amounts of RAM under different executable names

This might be a general question, but this problem is really getting me confused.
I have two different C++ applications, compiled with Visual Studio 2012, needing an instance of the same object. I have put a breakpoint before the creation of each object to measure the RAM usage by stepping my programs. The first one takes approximately 2.5 MiB more RAM after creating the object, while the second app is taking 30 MiB!
Both objects are created using a simple call to new with the same parameters. The code behind the constructors is the same.
As a detail: the first project contains much fewer .cpp files than the second one. So I thought it might be a problem of internal fragmentation of the exe. Plus, I've also tried to break BEFORE any code was executed inside the main function, and the memory usage was already much different (6 MiB for the first app, 35 MiB for the second one).
Does anyone have any idea what might be going on?
EDIT : The said object is a DirectX context, with a constructor creating a Direct3D instance and a device. Both the instance AND device are created the same way, but both have different RAM usage between the two apps.
Here is the code for the D3D device creation :
d3d_presentParams = new D3DPRESENT_PARAMETERS; ZeroMemory( d3d_presentParams, sizeof(D3DPRESENT_PARAMETERS) );
d3d_presentParams->Windowed = !window->isFullscreen();
d3d_presentParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
d3d_presentParams->hDeviceWindow = window->getHwnd();
d3d_presentParams->MultiSampleType = antiAlias;
d3d_presentParams->EnableAutoDepthStencil = true;
d3d_presentParams->AutoDepthStencilFormat = D3DFMT_D32F_LOCKABLE;
d3d_presentParams->PresentationInterval = (info.m_vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE);
{
d3d_presentParams->BackBufferCount = 1;
d3d_presentParams->BackBufferFormat = D3DFMT_A8R8G8B8;
d3d_presentParams->BackBufferWidth = m_viewportSize.x;
d3d_presentParams->BackBufferHeight = m_viewportSize.y;
}
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
window->getHwnd(),
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
d3d_presentParams,
&d3d_device);
EDIT 2 : Problem has been "solved" for now. See the answer below.
Alright, I "solved" it, kind of. You're not going to believe what the problem was.
TL;DR : Renaming the executable lowers the RAM usage from 80 MiB to 28 MiB. It seems that Windows is suspicious of non-verified applications, as I discovered a directory full of logs inside C:/Users/<Me>/AppVerifierLogs/.
It seemed that RAM usage was linked to how many sources files it contained. Thus, I tried copying one of my projects entirely. I had to rename it, because a solution cannot have two projects with the same name... And guess what, memory usage was down to 7.3 MiB at the beginning of main(), instead of 30 MiB previously.
Later, I found out that it was a specific executable name that caused it to use more memory. I simply renamed the .exe file, and the problem was gone. I even tried to rename Firefox's exe by my app's name, and it made it crash.
And finally, I discovered in C:/Users/<me>/AppVerifierLogs/ at least 3000 files named after my application. This immediately made me think about the way Windows tries to verify applications (e.g. in order to see if they're not viruses).
I have no idea where this is coming from, nor how to turn off this verfier, but it's really annoying as a dev to have Windows panicking about an application you're developping, and injecting (possibly useless) stuff inside it.
The fix for now is just to rename the executable. If anyone knows about which application might have access to this "AppVerifierLogs" directory, please mention it, because even Google searches dont't seem to be able to help at this point...

GPSD delivering wrong time

I'm currently having some fun with the gspd library and noticed that the time I get switches between two values - The actual value (today) and some date in 1991.
When displayed gpsmon it normally shows the right time. Using cgps -s displays the wrong time, with the absurdly huge offset.
The (so far) only possible problem I've found online is that the sys-time isn't up to date which mixes up the gps-time, but that isn't the case here.
We are accessing gpsd via the following code:
{
gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
if(gps_waiting(&gps_data, timeout)) {
if(gps_read(&gps_data) == -1) {
return false;
}
}
return true;
}
All the other values (location, altitude etc) are correct. Only the time is off.
Anybody got an idea on why this could be happening? Thanks in advance!
We actually found the answer! The RaspberryPi we ran this is on apparently had some issues with it's OS, so a using an old image worked out perfectly.

c++ local variable gets overwritten (but only on some notebook)

I am facing some strange behaviour appearing only on some notebook.
I am developing in c++ using msvc 2012 and the qt framework.
I will try to sum up the problem and i am hoping that someone has any idea what the problem could be or what i could try to find out..
Generally it's the following problem:
void myclass::foo()
{
const double value1 = 100.0;
double value2;
value2 = some_function_returning_double();
if(value1 > value2)
{
//__ do something
}
}
The problem is that the condition fails as the local variable gets overwritten.
If I do some debug output i can see that variable value1 is not 100.0 anymore but some random value .. so that the comparison randomly fails ..
One thing i figured out is that everything just works fine if i don't use local variables. If i set up value1 and value2 as member variables of my class everything works without problems, but that can't be the solution.
Now the strange thing is that this error does only occur on some notebook (some mobile i5 cpu).
On my machine (i5) and on many other notebooks (even other mobile i5) everything just works fine.
I know that you won't be able to solve my problem with this little information i can offer here, but maybe some of you has any hint what the problem could be and what i could try to solve this.
Many thanks in advance.
In visual studio 2012, add a data breakpoint (debug->new breakpoint->new data breakpoint) on the address of the variable that gets overwritten.
First, break at the start of the function.
Then set the data breakpoint: just type &value1 in the "New breakpoint` the input box.
Then it should break just after the value has been modified, and you should see the culprit.
Data breakpoints are a very powerful tool, that helped me found nasty bugs very quickly.

Infinite loop during debugging

I am working with a STM32 eval2 board and trying to debug it. It used to work fine, and I haven´t changed anything, but for the last week or so I am always getting stuck in this loop while I am in debugger mode, but when I am not, the program runs fine.
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR))
{
if(__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXDAVL))
{
*(tempscr + index) = SDIO_ReadFIFO(hsd->Instance);
index++;
}
}
I even tried running the sample project code provided for the board by ST, did not change anything about it, and I am stuck in the same while loop in their code as well.
Does anybody know what I am doing wrong here? It doesn´t make sense because nothing changed.
The errors that are defined by the variables in the while loop are (respectively):
Received FIFO overrun error
Data block sent/received (CRC check failed)
Data timeout
Data block sent/received (CRC check passed)
Start bit not detected on all data signals in wide bus mode
and it looks like in this while loop it is getting stuck in the if statement for a "Data available in receive FIFO" flag, if that makes sense. I cannot step over that if statement.
I am using keil v5 and programming in c++
Well, I have been struggling with this for a week and almost right after I posted this I figured it out.
I had the SD card in, and for some reason taking it out fixed it. So I will leave this in case anyone else ever has this stupid problem.
Well, I have been struggling with this for a week and almost right after I posted this I figured it out.
I had the SD card in, and for some reason taking it out fixed it. So I will leave this in case somebody else has this stupid problem.