I'm not getting any error messages, simply my vector is not populating. Looking at the vector in the watch list, nothing is being copied. Why is this?
I've tried two ways.
The first
std::vector<Point3D*> hitpoints;
local_hit_point = sr.local_hit_point; //local_hit_point class Point3D
hitpoints.push_back(local_hit_point);
The second way I tried to use pointers
std::vector<Point3D*> hitpoints;
Point3D* hittingpoint_ptr = new Point3D;
local_hit_point = sr.local_hit_point;
hittingpoint_ptr = &local_hit_point;
hitpoints.push_back(hittingpoint_ptr);
I got vectors in other places in my code which work. Am I really just being daft, but I can't seem to figure out why its not working.
My best guess is that you have an issue with you debugger..
First Suggestion;
Clear everything in your watchlist because they can change the behaviour of the execution
check it again..
Second suggestion;
Create a new project and write a simple code like the one above and see whether your vector is populating..If this simple project works, you should provide us more code and details..
simply my vector is not populating.
It is populating. However
Looking at the vector in the watch list ...
I used hitpoint.size()
Results of function/method calls (size() is a method) are not automatically updated in visual studio watch list (because you haven't told what os/compiler you use I had to assume it is visual studio). I.e. if you enter function call into watch list, it'll calculate results, but will not call function again until you manually refresh it. Instead of function call, add vector itself into watch list.
Related
This is my first question ever posted, so please let me know if there is anything that needs changes in my post :)
I am currently working on a dialog that is supposed to let the user change the background-color for some signal plotting. The "wxColourPickerCtrl" seems to do exactly what I need. Since there are multiple plots/pictures to be manipulated, the ColourPickerCtrls are initialized in a loop with the chosen background color as the default value:
for (const auto& [signalName, signalProperties] : properties)
{
wxColourPickerCtrl* selectBackgroundColor = new wxColourPickerCtrl(this, signalProperties.first, signalProperties.second.backgroundColor, wxDefaultPosition, wxDefaultSize);
}
"this" is an object of type SignalPropertiesDialog, which is directly inherited from wxDialog.
I have left out all the necessary sizer stuff, since it's not relevant for the problem (at least imo). "properties" is structured as follows:
std::map<std::string, std::pair<int, GraphPicture::Properties>> signalProperties_;
where GraphPicture::Properties contains the properties I want to manipulate:
struct Properties
{
wxColour backgroundColor{ *wxWHITE };
wxColour lineColor{ *wxBLACK };
int linewidth_px{ 1 };
bool isShown{ true };
};
The application successfully builds but immediately crashes on startup while generating those color picker objects.
wxIshiko has uploaded multiple tutorials and code snippets as examples for various wxWidgets controls, including the wxColourPickerCtrl. So I downloaded the sample code and tried to run it. Surprisingly, it worked.
While running through the code step by step I noticed the following difference:
The wxColourPickerCtrl is based on wxPickerBase. The wxPickerBase is created by calling the constructor of wxColourPickerCtrl (what I am actually doing in my code). During the construction of the wxPickerBase, the desired color is called by the name wxColourDataBase::FindName(const wxColour& color) const where the wxColourBase itself is instantiated. This is where the difference is:
When running the code snippet by wxIshiko, wxColourDataBase is instantiated correctly including the member m_map of type wxStringToColourHashMap* which is set to be NULL.
When running the code written by myself, wxColourDataBase is not correctly instantiated, and thus the member m_map is not set to be NULL, which leads to to the crash.
I have the feeling that there is nothing wrong with the way I set up the wxColourPickerCtrls. I somehow think there is a difference in the solution properties of the projects. I checked those but was not able to find any relevant differences.
I would really appreciate any hint or help since I am completely stuck on that problem.
Thank you very much in advance and have a good one,
Alex
EDIT:
I attached a screeny of the call stack.
Call stack
When does this code run exactly? If it is done after the library initialization (which would be the case, for example, for any code executed in your overridden wxApp::OnInit()), then wxTheColourDatabase really should be already initialized and what you observe should be impossible, i.e. if it happens it means that something is seriously wrong with your library build (e.g. it doesn't match the compiler options used when compiling your applications).
As always with such "impossible" bugs, starting with a known working code and doing bisection by copying parts of your code into the working version until it stops working will usually end up by finding a bug in your code.
New to Go and building a simple LRU cache in Go to get used to syntax and Go development.
Having an issue with the MoveToFront list method, it fails on the following check in the MoveToFront body
if e.list != l || l.root.next == e
I want to move the element (e) to the front of the list when I retrieve it from cache , like this
if elem, ok := lc.entries[k]; ok {
lc.list.MoveToFront(elem) // needs fixing
return elem
}
return nil
The Code can be seen here on line 32 the issue occurs
https://github.com/hajjboy95/golrucache/blob/master/lru_cache/lrucache.go#L32
There seem to be two problems, to me. First, this isn't how the List data type is meant to be used: lc.list.PushFront() will create a List.Element and return a pointer to it. That's not fatal, but at the least, it is kind of annoying—the caller has to dig through the returned List.Element when using Get, instead of just getting the value.
Meanwhile, presumably the failure you see is because you remove elements in Put when the LRU-list runs out of space, but you don't remove them from the corresponding map. Hence a later Put of the just-removed key will try to re-use the element in place, even though the element was removed from the list. To fix this, you'll need to hold both key and value. (In my simple experiment I did not see any failures here, but the problem became clear enough.)
I restructured the code somewhat and turned it into a working example on the Go Playground. I make no promises as to suitability, etc.
I am new to C++ and I am trying to create a list of cv::Mat.
This could allocate quite a lot of memory, but I only have around ten small Mat's to load in the list.
I made this code, but not sure why it is not working.
void Utils::getFramesFromVideo(std::string file,std::list<cv::Mat>& listMatOutput) {
cv::VideoCapture* videoCapture = new cv::VideoCapture(file);
bool hasImage = false;
cvNamedWindow("WhileReading", 1);
do {
cv::Mat frame;
hasImage = videoCapture->read(frame);
if (hasImage) {
listMatOutput.push_back(frame);
imshow("WhileReading", frame);
waitKey(0);//give some time to see the frame (debug)
}
} while (hasImage);
cvNamedWindow("AfterReading", 2);
for (std::list<Mat>::const_iterator iterator = listMatOutput.begin();
iterator != listMatOutput.end(); iterator++) {
imshow("AfterReading", *iterator);
waitKey(0);//give some time to see the frame (debug)
}
videoCapture->release();
}
The first loading is displaying the frames correctly, but in the second window (AfterReading) the image is black with red stripes.
Could someone please give some advice?
The list format is an STL container, meaning that you've got some things to keep in mind to work with it. push_back() is the preferred method of adding instances to the container, much like using an iterator is the preferred method of accessing the elements of the list. If you try to directly set an element of the list to a cv::Mat() you're working on, then a) you need to know exactly what sort of wrapping the list is doing to each instance, so you can do it properly yourself, and b) you're defeating the purpose of using an STL container in the first place, which is to abstract away the details of the list.
You don't necessarily need to use the frame.clone() call in your code, as this creates a deep copy of the image and takes up precious resources. I know that I've used std::vector<cv::Mat> in the past without having to make deep copies for each element in the vector, so I assume that you should be able to pass the Mat itself to a list. Consult the C++ documentation on STL lists.
Another thing you might consider, if low memory usage and speed of access through the list is a concern, and your number of images is low, is a list of image pointers. Keep your images stored as individual cv::Mat instances, and make your list of type std::list<cv::Mat*>, passing the handle of the image to the push_back() call. Of course, with this method, your images will not be 'thread safe' because they will be stored in one place, but called and worked on from another. I hope this shed a little light on your inquiry.
I tried all sort of things, like changing to pointers or vectors and checking for code optimizations on GCC. Then after trying to clone cv::Mat it worked:
listMatOutput.push_back(frame.clone());
Would be glad if anyone could tell me why and suggest a better way of doing, so I can choose a better answer then my own.
So I'm trying to make use of a GtkSourceView in C++ using GtkSourceViewmm, whose documentation and level of support give me the impression that it hasn't been very carefully looked at in a long time. But I'm always an optimist :)
I'm trying to add a SourceView using some code similar to the following:
Glib::RefPtr<gtksourceview::SourceLanguageManager> source_language_manager = gtksourceview::SourceLanguageManager::create();
Glib::RefPtr<gtksourceview::SourceLanguage> source_language = Glib::wrap(gtk_source_language_manager_guess_language(source_language_manager->gobj(), file, NULL));
Glib::RefPtr<gtksourceview::SourceBuffer> source_buffer = gtksourceview::SourceBuffer::create(source_language);
gtksourceview::SourceView* = m_source_view = new gtksourceview::SourceView(source_buffer);
m_vbox.pack_start(*m_source_view);
Unfortunately, it spits out the warning
(algoviz:4992): glibmm-WARNING **:
Failed to wrap object of type
'GtkSourceLanguage'. Hint: this error
is commonly caused by failing to call
a library init() function.
and when I look at it in a debugger, indeed the second line above (the one with the Glib::wrap()) is returning NULL. I have no idea why this is, but I tried to heed the warning by adding Glib::init() to the begining of the program, but that didn't seem to help at all either.
I've tried Google'ing around, but have been unsuccessful. Does anyone know what Glib wants me to init in order to be able to make that wrap call? Or, even better, does anyone know of any working sample code that uses GtkSourceViewmm (not just regular GtkSourceView)? I haven't been able to find any actual sample code, not even on Google Code Search.
Thanks!
It turns out, perhaps not surprisingly, that what I needed to init was:
gtksourceview::init();
After this, I ran into another problem with one of the parameter to gtksourceview::SourceLanguageManager, but this was caused by a genuine bug which I subsequently reported and was promptly fixed. So everything's working great now!
I use gtkmm. Typically you have to initialize things with something like :
_GTKMain = new Gtk::Main(0, 0, false);
Of course do not forget :
delete _GTKMain;
Check here for details :
http://library.gnome.org/devel/gtkmm/2.19/classGtk_1_1Main.html
(Sorry but the link option does not work ...)
I'd like the user to be able to edit the number of recent files shown in the File menu of my MFC application. I've used two very good references:
http://www.codeproject.com/KB/menus/changemru.aspx
http://www.microsoft.com/msj/0899/c/c0899.aspx
It involves deleting and recreating the CRecentFileList object stored in CWinApp::m_pRecentFileList. Unfortunately, I find that the menu is not updated properly after replacing the CRecentFileList. See code snippet below:
void CMyWinApp::SetMRUListSize( int size )
{
// size guaranteed to be between 1 and 16
delete m_pRecentFileList ;
LoadStdProfileSettings( size ) ;
}
What can I do to ensure that what is drawn into the File menu is synchronized with m_pRecentFileList after I recreate the object?
My CApp derives from CWinApp. In initInstance, you have this line:
LoadStdProfileSettings(10);
At the end of InitInstance, add this code:
m_pmf->m_pRecentFileList = m_pRecentFileList;
Here m_pmf is my MainFrame class and I created a member CMainFrame::m_pRecentFileList of type CRecentFileList which is in the MFC source file filelist.cpp. m_pRecentFileList on the right is protected and CMainFrame doesn't have access to it from outside InitInstance, but you can make a functional copy here.
At the end of CMainFrame::OnClose, force a registry update by:
m_pRecentFileList->WriteList();
// Force registry update on exit. This doesn't work without forcing.
I don't even have to rebuild m_pRecentFileList, the MRU mechanism updates it correctly. Example: 5 MRU items, the first is moved to another directory and can no longer be found. Stepping through the code in the debugger shows that the bad entry is removed from the list. For some reason, the updated list isn't saved correctly unless I force it as explained above. I originally thought the problem might have something to do with privileges (64-bit Win7), but running the app as admin didn't help.
Some of Microsoft's documentation suggest you should call CWinApp::LoadStdProfileSettings from within InitInstance. This suggests to me that it's something done once during initialisation rather than at run time.
Have you tried fully implementing the second of the two links you provided? My guess is you need to add the second part instead of the call to CWinApp::LoadStdProfileSettings:
m_pRecentFileList = new CRecentFileList(0, strSection, strEntryFormat, nCount);
if(m_pRecentFileList)
{
bReturn = TRUE;
// Reload list of MRU files from registry
m_pRecentFileList->ReadList();
}
[Edit] Apparently m_pRecentFileList points to an CRecentFileList Class . Have you tried calling CRecentFileList::UpdateMenu?
There's another CodeProject example which might help too.