OGRE No suitable conversion function exists - c++

I'm having a hard time trying to get an app to compile in Visual Studio 2013. I've solved a good amount of errors but I can't find a solution for the last one.
here it is:
void Application::setupRenderSystem() {
mState->dumpValues();
String val = mState->getStringValue("renderSystem");
RenderSystemList *renderSystems = mRoot->getAvailableRenderers();
RenderSystemList::iterator r_it;
bool renderSystemFound = false;
for (r_it = renderSystems->begin(); r_it != renderSystems->end(); r_it++) {
RenderSystem *tmp = *r_it;
std::string rName(tmp->getName());
// returns -1 if string not found
if ((int)rName.find(val) >= 0) {
mRoot->setRenderSystem(*r_it);
renderSystemFound = true;
break;
}
}
if (!renderSystemFound) {
OGRE_EXCEPT(0, "Specified render system (" + val + ") not found, exiting...", "Application")
}
}
Visual Studio indicates that the line RenderSystemList *renderSystems = mRoot->getAvailableRenderers(); is the problem, especially mRoot
Here is the error I get:
error C2440: 'initializing' : cannot convert from 'const Ogre::RenderSystemList' to 'Ogre::RenderSystemList *'

The getAvailableRenderers method doesn't return a pointer to a RenderSystemList. You'd want to have the value stored in a reference to a RenderSystemList:
RenderSystemList const& renderSystems = mRoot->getAvailableRenderers();

The Ogre API says:
const RenderSystemList & getAvailableRenderers (void)
So it returns a const reference and not a pointer.
Modify your code like this
const RenderSystemList &renderSystems = mRoot->getAvailableRenderers();

Related

Sprite::create(“file.png”) return null on Cocos2d-x C++ Visual Studio

I'm trying to create a Sprite with SonarFrameworks, and get a null although my file is well integrated into the project.
I tried to add :
FileUtils::getInstance()->addSearchPath("res/");
And try with Content property set to "True" and "False" (default), but still same problem.
Any idea ?
Thanks to GandhiGandhi I found the solution :
In the function FileUtils::fullPathForFilename located in the file CCFileUtils.cpp, a added this
std::string search = searchIt;
int tail = search.size() - 10; // For replace /Resources
search.replace(tail, 9, "res");
After the first "for(...){", so like that I replaced the path to find my resources.
for (const std::string& searchIt : _searchPathArray)
{
std::string search = searchIt;
int tail = search.size() - 10; // For replace /Resources
search.replace(tail, 9, "res");
for (const auto& resolutionIt : _searchResolutionsOrderArray)
{
fullpath = this->getPathForFilename(newFilename, resolutionIt, search);
if (!fullpath.empty())
{
// Using the filename passed in as key.
_fullPathCache.emplace(filename, fullpath);
return fullpath;
}
}
}

why does cocos2d-x version 4.0 not have macro CCARRAY_FOREACH?

I can't find macro CCARRAY_FOREACH but i found CCARRAYDATA_FOREACH. Are those the same ? I mean can i use CCARRAYDATA_FOREACH instead?
And i tried but visual studio gives me an error of expression must have pointer type when i was using CCARRAYDATA_FOREACH and i can't solve. Any help would be appreciated.
Here is part of my code
void BaseManager::update(float dt){
auto visibleSize = Director::getInstance()->getVisibleSize();
Ref* obj = NULL;
Coin* coin = NULL;
int setNum = 0;
CCARRAYDATA_FOREACH(m_coinArr,obj){ // this line produces error: expression must have pointer type
coin = (Coin*)obj;
if(coin->getPositionX() < -coin->getConSize().width/2){
coin->setVisible(false);
}
if( !coin->isVisible() ){
setNum ++;
}
coin->setPositionX(coin->getPositionX()-map_speed);
}
................

Resolve c++ pointer-to-member error in VS 2003

I have a c++ program that I'm trying to port from VS98 to VS2003 (incremental steps). One error that occurs throughout is "Error 2275"
For instance: k:\RR\chart\chartdlg.cpp(2025): error C2475: 'CRrDoc::cFldFilter' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
The offending code is shown below:
void CDataPage::OnBtnLabelField()
{
FLDID fid ;
LPMFFIELD f ;
CRrApp *pApp = (CRrApp *)AfxGetApp();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CRrDoc *pDoc = (CRrDoc *)pFrame->GetActiveDocument();
CSelectFieldDlg dlg;
//**************************************************
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter;
//dlg.ck = CRrDoc->*zcFldFilter;
//**************************************************
dlg.ck = pDoc->cFldFilter ;
dlg.TitleTextID = IDS_2676;
fid = (FLDID)dlg.DoModal();
if (fid != NOID)
{
f = pDoc->m_pComposite->mfbyndx(fid);
// find index
int i, iCount;
iCount = m_lboxLabel.GetCount();
for (i = 0; i < iCount; i++)
{
if(fid == m_lboxLabel.GetItemData(i))
{
m_lboxLabel.SetCurSel(i);
OnSelchangeComboLabel();
}
}
}
}
I tried handling it according to a Microsoft page: But that just generated a set of other problems (the commented code between the asterisks). Note that I also commented out the following line:
dlg.ck = pDoc->cFldFilter
Unfortunately, this leads to a new error: k:\RR\chart\chartdlg.cpp(2022): error C2440: 'initializing' : cannot convert from 'BOOL (__cdecl )(LPMFFIELD)' to 'BOOL CRrDoc:: '
The definition in the .H file looks like:
public:
static BOOL cFldFilter(LPMFFIELD f);
Any ideas how to handle the pointer-to-member issue?
since you have:
static BOOL CRrDoc::cFldFilter(LPMFFIELD f);
its type is not a member variable but a function:
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter; // doesn't work
BOOL (*zcFldFilter)(LPMFFIELD) = &CRrDoc::cFldFilter; // works
Since dlg.ck is of a correct type, you should do
dlg.ck = &CRrDoc::cFldFilter;

EXC_BAD_ACCESS issue after refactoring

The following code works in a the Marmalade simulator (I'm on OSX using x-code)
bool PictureDictionary::OnTableSelect(CTable* table, int tab){
//if something is selected, look up the item, and display it
//also change the search to the selected item
if(-1 < tab){
// if a term is selected, set the search text field to the term
CString term = m_SearchResults.GetString(tab);
if(m_currentWord != (char*)term.Get()){
m_currentWord = (char *)term.Get();
m_searchTextField->SetAttribute("text", term);
char* normalizedTerm = (char *)term.Get();
char* imagePath;
sprintf(imagePath,"images/%s.jpg", normalizedTerm);
if(m_ImageAttached){
m_Image->SetAttribute("image", (const char*)imagePath);
} else {
m_Image = CreateImage(CAttributes()
.Set("name", "picture")
.Set("x1", "0")
.Set("x2", "0")
.Set("y1", "50%")
.Set("image", (const char*)imagePath)
);
m_SearchView->AddChild(m_Image);
m_ImageAttached = true;
}
}
}
return true;
}
When I run the simulator, and select an item from the table, the image appears, and changes when I select a different item. When I go to refactor, I get a EXC_BAD_ACCESS (code=1…..) Error
bool PictureDictionary::OnTableSelect(CTable* table, int tab){
//if something is selected, look up the item, and display it
//also change the search to the selected item
if(-1 < tab){
// if a term is selected, set the search text field to the term
CString term = m_SearchResults.GetString(tab);
if(m_currentWord != (char*)term.Get()){
m_currentWord = (char *)term.Get();
m_searchTextField->SetAttribute("text", term);
char* normalizedTerm = (char *)term.Get();
char* imagePath;
sprintf(imagePath,"images/%s.jpg", normalizedTerm);
UpdatePictureView(imagePath);
}
}
return true;
}
void PictureDictionary::UpdatePictureView(char* imagePath){
if(m_ImageAttached){
m_Image->SetAttribute("image", (const char*)imagePath);
} else {
m_Image = CreateImage(CAttributes()
.Set("name", "picture")
.Set("x1", "0")
.Set("x2", "0")
.Set("y1", "50%")
.Set("image", (const char*)imagePath)
);
m_SearchView->AddChild(m_Image);
m_ImageAttached = true;
}
}
Any suggestions on how to clean up the code without getting these issues?
Edit RE Comments about uninitialized variables:
m_ImageAttached was initialized to false in the constructor, unless I'm doing something wrong. Also, changing the condition to check if m_Image!=NULL also throws the same error.
main.cpp:
PictureDictionary pictDict(myApp, &dictionary);
Constructor for PictureDictionary:
PictureDictionary::PictureDictionary(CAppPtr app,Dictionary::Dictionary* dictionary){
m_App = app;
m_Dictionary = dictionary;
m_currentWord = "";
m_ImageAttached = false;
}
imagePath is an unitialized pointer, in both snippets. Any attempt to dereference is undefined behaviour. It just appeared to work in the first snippet. Use an array or populate a std::string instead:
std::string imagePath(std::string("images/") + normalizedTerm + ".jpg");
And use std::string::c_str() if access to the underlying const char* is required.

error C2663: overloads have no legal conversion for 'this' pointer

please help me for this errors
code:
u16 ip_defragment(){
u16 result;
fragip_set::iterator i;
IP_FRAGMENTED new_defrag;
IP* pcurpack = (IP*) malloc(cur.len);
memcpy(pcurpack, cur.data, cur.len);
new_defrag.saddr = cur.saddr;
new_defrag.daddr = cur.daddr;
new_defrag.protocol = cur.ip.ppack->protocol;
new_defrag.id = i2i(cur.ip.ppack->id);
i = ip_frags.find(new_defrag);
if(i != ip_frags.end()){
i->packets.insert(pcurpack);
const_cast<u16&>(i->cur_len) += cur.ip.len - cur.ip.hlen;
const_cast<u32&>(i->last_time) = time();
if(!(cur.ip.bmore_fr) && (i->tot_len == 0)){
const_cast<u16&>(i->tot_len) = cur.ip.fr_offs + cur.ip.len;
}
if(i->cur_len == i->tot_len){
for(set<IP*>::iterator k = i->packets.begin(); k != i->packets.end(); k++){
// must copy to another buffer
if(i2i((*k)->frag_off) & IP_OFFMASK){
memcpy(ip_defrag_buffer, *k, (*k)->ihl<<2);
} else {
memcpy(ip_defrag_buffer + (i2i((*k)->frag_off) & IP_OFFMASK) * 8,
*k + ((*k)->ihl<<2), (i2i((*k)->tot_len))-((*k)->ihl<<2));
}
}
IP* defr_ip = (IP*) &ip_defrag_buffer;
defr_ip->tot_len = i2i(i->tot_len);
defr_ip->frag_off = 0;
result = i->tot_len;
ip_frags.erase(i);
return result;
}
return 0;
}
if(!(cur.ip.bmore_fr)){
new_defrag.tot_len = cur.ip.fr_offs + cur.len;
} else {
new_defrag.tot_len = 0;
}
new_defrag.cur_len = cur.ip.len; // with header size
new_defrag.last_time = time();
i = ip_frags.insert(new_defrag).first;
if(i != ip_frags.end())
i->packets.insert(pcurpack);
return 0;
}
compiled project and view only 2 errors similar
line 15 : i->packets.insert(pcurpack);
end line : i->packets.insert(pcurpack);
error with 2 lines : error C2663: 'std::_Tree<_Traits>::insert' : 4 overloads have no legal conversion for 'this' pointer
IntelliSense: no instance of overloaded function "std::set<_Kty, _Pr, _Alloc>::insert [with _Kty=IP *, _Pr=std::less<IP *>, _Alloc=std::allocator<IP *>]" matches the argument list and object (the object has type qualifiers that prevent a match)
please help me?
I had exact same error with std::set, while passing it to a lambda expression:
C2663 'std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert': 5 overloads have no legal conversion for 'this' pointer
lambda expression prototype was:
[se1, ele1](auto val) {
/* here I was editing se1 set, but above se1 is passed value type */
}
I have changed to:
[&se1, ele1](auto val) {
/* now since se1 set is sent as reference type above, it is good to edit
changes stays as I expect it to be
*/
}
Now compilation succeeds.
I used with count_if function, which calls the lamda expression for eac element, so the compiler knows that modifications should persist in set se1, which is perfectly logical.
If you desire to have the original set unchanged, then send a copy of it.