I got an error while debuging a program i wrote down from a tutorial online, it is a sound synth made by the one lone coder on youtube. I'm not sure what caused it or how to fix it. I disabled pre-compiled headers witch was the first problem i encounterd.
I have tried searching online, leading me here to awnsers about code of others, i have tried going on multiple discord servers and asking there.
No luck so far. Also this is just as a little exercise to help me get back on track.
Main.cpp
#include <iostream>
#include "olcNoiseMaker.h"
using namespace std;
double MakeNoise(double dTime) {
return 0.5 * sin(540.0 * 2 * 3.14159 * dTime);
}
int main() {
wcout << "onelonecoder.com - synth part 1" << endl;
//Get all sound hardware
vector<wstring> devices = olcNoiseMaker<short>::Enumerate();
//Display finding
for (auto d : devices) wcout << "Found output device:" << d << endl;
//Create sound machine
olcNoiseMaker<short> sound(devices[0], 44100, 1, 8, 512);
//Link noise function whit machine
sound.SetUserFunction(MakeNoise);
return 0;
}
olcNoiseMaker.h is just to get acces to the sound chip and bla bla.
you can see his video here: https://www.youtube.com/watch?v=tgamhuQnOkM&t=134s
Running the program should result in a contenious sine wave of 540 KHz
instead it plays it only once and gives me this error:
Unhandled exception thrown: write access violation.
_Tgt was 0xA4EFF82C. occurred
Late to answer, but I had this issue (Visual Studio 2019). When I built and ran the program, there was just one short beep before the program exited. The issue was that I was in the x64 Debug configuration, and that was causing the error. Once I changed to x86 Debug, it was working perfectly.
Edit: Also, in your code, you are missing the while(1) {} after the sound.SetUserFunction(MakeNoise); statement which would be needed to get the code working according to the video.
Related
Using C++/WinRT, Win10, VS2019, SDK 10.0.22621.0, NuGet CppWinRT 2.0.220608.4
I'm trying to get the RequestPreferredConnectionParameters to work. At this point I am wondering if maybe I have the syntax wrong or maybe something else about it that I am not aware of. The MS docs for the function are here and the link to the various parameters are here.
The command line, as I have it, with pubDevice being the BLE device object, is:
BluetoothLEPreferredConnectionParametersRequest rcoConnect = pubDevice.RequestPreferredConnectionParameters(BluetoothLEPreferredConnectionParameters::ThroughputOptimized());
Just to mention, I am able to run
auto statusTest = co_await pubDevice.RequestAccessAsync();
before the RequestPreferredConnectionParameters without problems so, obviously, the device object is good and can be connected to.
What is happening is this. I have a function, OpenDevice(), that opens the device based on the address. If, after getting the device object, I issue the command above while still in the OpenDevice function, the code will not crash but it will immediately jump to the end of the OpenDevice() function bypassing all other lines of code below it and there will be no connection at all after that.
If I run the RequestPreferredConnectionParameters outside of the OpenDevice() function it errors out with a
An unhandled exception was encountered during a user callback and the line referenced is in base.h line 4942 if (result == impl::error_changed_state)
I had assumed that the callback refered to was the Rx Characteristic ValueChanged Callback that is set in OpenDevice(). So I tested by first revoking that callback with
pubRxCharacteristic.ValueChanged(etValueChangeToken);
and then running the RequestPreferredConnectionParameters but I still got the An unhandled exception error.
The only other callback that I have is the BluetoothLEAdvertisementWatcher advert received callback but that was stopped after the device was found.
Can anyone verify that my syntax seems correct and/or have any clue as to what is causing my problems?
EDIT to show more code in a console app------------
#IInspectable
Again for the record:
Using C++/WinRT, Win10, VS2019 - Console App, SDK 10.0.22621.0, NuGet CppWinRT 2.0.220608.4
Pertinent includes in the pch.h file:
// 2022/9/10 -- for WHCAR and apparently GUID
#include <Windows.h>
#include <tchar.h>
#include <winrt\Windows.Foundation.h>
#include <winrt\Windows.Storage.Streams.h>
#include <winrt\Windows.Devices.Bluetooth.h>
#include <winrt\Windows.Devices.Bluetooth.Advertisement.h>
#include <winrt\Windows.Devices.Bluetooth.GenericAttributeProfile.h>
// 2022/9/10
#include <winrt\Windows.Devices.Enumeration.h>
#include <winrt/Windows.Foundation.Collections.h>
Pertinent name spaces at top of Main.cpp:
using namespace winrt;
using namespace Windows::Foundation;
using namespace winrt::Windows::Foundation;
using namespace Windows::Storage::Streams;
using namespace Windows::Devices::Bluetooth;
using namespace Windows::Foundation::Collections;
using namespace Windows::Devices::Bluetooth::Advertisement;
using namespace Windows::Devices::Bluetooth::GenericAttributeProfile;
// 2022/9/10 for RequestConnectionAsync
using namespace Windows::Devices::Enumeration;
I assume that the code to watch for and find the device is not pertinent here. Needless to say the device is found and the address is passed to OpenDevice to create the device object.
Here is the top portion of OpenDevice:
IAsyncAction OpenDevice(unsigned long long deviceAddress)
{
auto device = co_await BluetoothLEDevice::FromBluetoothAddressAsync(deviceAddress);
// 2022/9/10 test code
auto statusTest = co_await device.RequestAccessAsync();
// Allowed, DeniedBySystem, Unspecified
if (statusTest != DeviceAccessStatus::Allowed) {
std::cout << "Access to device is not allowed...." << std::endl;
}
else {
std::cout << "Access to device is allowed...." << std::endl;
}
// Next line ends without error but immediately goes to the end of OpenDevice()
std::cout << "Asking for ThroughputOptimized...." << std::endl;
auto statusConnection = device.RequestPreferredConnectionParameters(BluetoothLEPreferredConnectionParameters::ThroughputOptimized());
std::cout << "Line after Request ThroughputOptimized...." << std::endl;
Beep(500, 500);<br/> // function never gets to this cout or Beep<br/>
// More code follows to get Rx and TxCharacteristics etc.<br/>
} // end OpenDevice
Here is the console output:
Notice the last cout is the line Asking for ThroughputOptimized.
No cout for Line after Request ThroughputOptimized and no Beep.
Trying to locate the TENS device: Waiting for device:
AdvertisementReceived:
LocalName: []
AdvertisementType: [ConnectableUndirected]
BluetoothAddress: [0x300000e59630]
RawSignalStrengthInDBm: [-60] ServiceUUID: [0000fff0-0000-1000-8000-00805f9b34fb] Found TENS Device Main
Service.... TENS device found. Access to device is
allowed.... Asking for ThroughputOptimized....
WinRTBle.exe (process 15576) exited with code -1073740791. Press
any key to close this window .
Barring a problem in syntax or a missing header. the only other thing that I can think of is that it needs Win11. The docs for RequestPreferredConnectionParameters Method say
Windows requirements Device family Windows 11 (introduced in
10.0.22000.0)
Does that mean that regardless of the SDK it needs Win11?
#IInspectable As much as I was dreading this, apparently the answer is that it needs Win11. The console app code mentioned above in the edit to the original question was compiled into an exe. I have Win11 on a VM VirtualBox and I ran that exe on that Win11 and the code continued past the ThroughputOptimized() line in question and finished the rest of the app as expected. So that's ashamed. I don't have Win11 on a real box yet (call me paranoid) but I guess I could bracket the code for the Win11 OS and only run it when a user happens to be running Win11
Always something.......
EDIT 2 ...............................
And the "Always something" comes up immediately. As far as I can tell from what I have been able to find, there is no way to tell if the OS is Win10 or Win11. It was recommended to use RtlGetVersion but that returned 10 for both Win10 and Win11. Another poster suggested to use the File version of the System32 kernal32.dll file but they also both reported major number 10 and minor number 0. The MS docs for adding a version manifest had the UUIDs for both OSs as the same.
This is ridiculous that MS would come up with a function that only runs in Win11 and then not have to ability to tell you which OS you are running in....Jeeeeeeze.....
EDIT 3.........................
Spoke too soon. I was messing around with the console app and forgot that in my MFC app I use the WMI IWbemClassObject Caption property to get the OS.
For Windows 10 I get
Microsoft Windows 10 Pro
and for Win11 I get
Microsoft Windows 11 Home
So apparently that is really the only way to do it.
I am new to C++.I am following freeCodeCamp.org tutorial on C++.
The program looks like this-
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int luckyNums[] = {4,8,15,16,23,42};
cout << luckyNums[2];
return 0;
}
since I had VS code already installed I did not install code blocks.
Every time I run the above program I get an error "Access is denied". Also at the same time McAfee pops up saying "we just stopped a virus". I couldn't find a solution to this on Google anywhere.
When I was trying to do something with the code, in line 6 I did
cout << luckyNums[2] << endl;
and it worked and returned 15 but now the problem was I didn't understand why it worked because Mike got the result without doing this in code blocks.
Mike is the person giving the tutorial on freeCodeCamp.org
I have this strange problem and I do not know why this happens. Since yesterday I get this problem message this declaration has no storage class or type specifier for my code in VS Code (Version 1.34.0, OS: Windows 10, Compiler: MinGW). Yesterday I was trying to learn how to write with fstream (I don't know if this is relevant I thought maybe that could be the source of the problem because of some strange behavior of fstream.). The code compiles and I can run the exe file without any problems. This problem message (the problem message is pointing to the last line) persists even if I remove the whole body of the main function.
#include <iostream>
int main(void){
int sum{0};
std::cout << "Why?\n";
std::cout << "sum = " << sum << '\n';
return 0;
}
This is a screenshot with an empty body of the main function.
It seems that this problem message is a bug in VS Code. Restarting VS Code didn't help. But restarting Windows solved the issue.
I wrote a C++ program that uses opencv, I compiled it in VisualStudio 2010 using release mode as Win32 application, the opencv library is dynamically linked so I just copied the needed dll's to the root folder of the program(so I can run it on other computers), the program is tracking people in a video and works fine when I run it on my computer, however when I run it on other machines it works but 65% slower, at first I thought that its the machine it self that is slow, but then I wrote another small program(the code is below) whose only purpose is to read a video file and play it approximately at the original video speed. Unfortunately I have the same issue with it as well, it runs fine on my computer but when I run it on other computers it slows down by 65%(more or less), I am new to c++/opencv and I have no real idea why this is happening I'm hoping some one can enlighten me, was the dynamic linking a bad idea? and I should compile opencv as a static library(which I don't yet know how to do and will appreciate any help on the issue). or is it something else?
#include "opencv\cv.h"
#include "opencv\highgui.h"
int main(){
cv::VideoCapture vidBuffer;
if(!vidBuffer.open("res/test.mp4")){
std::cerr << "Cant find \"res/test.mp4\"\n";
system("pause");
return -1;
}
int fps = vidBuffer.get(CV_CAP_PROP_FPS);
int frameTime = 1000/fps;
//video loop
cv::Mat frame;
for(char c=-1;;c=cv::waitKey(frameTime)){
if(!vidBuffer.read(frame)||c==27)
break;
cv::imshow("Vidoe test", frame);
}
//loop emd
vidBuffer.release();
return 0;
}
I am developing a Gtk application using gtkmm on Windows Vista with Visual Studio 2005. The application works fine on the development machine but I have received crash reports after it has been run on Windows XP machines (both Service Pack 2 and 3). I distribute the app with the directory structure described in http://live.gnome.org/gtkmm/MSWindows and it had given me no problems so far.
The crash gives no error messages except for Windows asking whether I want to report the error.
In order to solve the problem, I tried to compile the program against different versions of gtkmm (a recent stable version gtkmm-win32-devel-2.16.0-4 and an older version gtkmm-win32-devel-2.10.11-1) but the problem persisted.
I hunted down the problem to a call to window->create_cairo_context() inside the on_expose_event of a Gtk::DrawingArea. When I commented out this call, the problem would disappear. So I wrote the following minimal program, which still crashes:
#include <gtkmm.h>
#include <iostream>
class MyWindow : public Gtk::Window {
bool on_expose_event(GdkEventExpose* event) {
std::cout << "expose" << std::endl;
Glib::RefPtr<Gdk::Window> window = get_window();
if(window) {
std::cout << "win" << std::endl;
std::cout << "Get cairo" << std::endl;
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
std::cout << "Get cairo done" << std::endl;
} else {
std::cout << "no win" << std::endl;
}
return true;
}
};
int main (int argc, char *argv[]) {
Gtk::Main m(argc,argv);
MyWindow w;
m.run(w);
return 0;
}
This minimal app may run and display the window without problem, but if I move the window off the screen limits or if I minimize/maximize it enough times (thus triggering calls to on_expose_event), it will eventually crash. It may also be the case that it won't crash the first time, but it will crash after restarting the app and triggering multiple calls to on_expose_event as described above. One thing I've noticed is that the app crashes after printing "Get cairo done". When I comment out the call to create_cairo_context, the problem dissapears, so I'm pretty sure there is something wrong with this line.
The error happens on clean installed Windows XP machines. I have tested both apps (original and minimal) on a colleague's notebook, which also has Windows XP, but it doesn't crash there. I suppose there is some dependency that is available/up to date in our computers but not in the computers where the application crashes. I have updated DirectX and installed Visual Studio C++ 2005 Redistributable on one of the problematic machines, but the problem persists.
The original app, which draws a graph on the DrawingArea, doesn't necessarily crash the first time either. It may work fine the first time after rebooting, but is more prone to fail the second time.
I am thinking about compiling and testing with MinGW to see if that solves the problem. I'll also try to compile a debug version and try to use a debugger. I have suspected the version of gdi32.dll might have something to do, seeing that libcairo-2.dll depends on this dll according to Dependency Walker, but until now it's just an speculation. Other than that, I'm out of ideas.
I'll be trying these ideas for the time being. Hopefully someone has more suggestions or knows what is going on with the code above.