DevIL reading an invalid extension - c++

So I've been using the DevIL library for a while now (along with ILU and ILUT) and have had few problems with it after I got it working. That is, until now. All of a sudden it does not seem to work with any image of any format. I'm using this code:
GLuint myTex;
void Init() {
myTex = ilutGLLoadImage(L"img.tga");
}
void Draw() { // 2D Drawing
glBindTexture(GL_TEXTURE_2D, myTex);
draw::TwoD::Textured::Rectangle(100, 100, 200, 200);
}
The rectangle appears blank white. I checked the function and it seems like it should work fine, so I tried calling ilGetError(). It returned IL_INVALID_EXTENSION for nearly every different image I tried. I've tried putting the whole directory and even made sure that I was using the right version of DevIL (unicode) and still it returns this. Any idea what's going on?
Thanks in advance!
Edit:
I've also notices that DevIL returns this even if the file specified does not exist. This makes me think something is wrong with DevIL itself instead of my code.
Edit 2:
So I found out that I placed the unicode DLLs in the project directory (as necessary) but it turns out I linked to the library directories for multi-byte chars. Even after fixing it, the problem continued. I'm stumped by this one.
Edit 3:
Okay sorry for so many edits but I also just found out that the DevIL setup I had in my previous projects still work perfectly. It seems to only be the project I'm using now. All the relevant code is the same (copy/pasted), so I think it has to do with the project properties, but I can't find any differences. Do you know of any way to copy the properties of one project to another in VS2015?

Related

SFML : drawing from different files

I'm working on a SFML project that contains several different files and classes. The problem is : in every file, there is some drawing, and the sf::RenderWindow* defined in the main file seems to be out of scope here, therefore I can't link these drawing with the main window. I've tried to redefine sf::RenderWindow in every header files, and it doesn't work as well (a black screen appear and disappear promptly). The error was : Access violation reading location. But when I group everything in one file, things work well but it looks really messy.
I also found this question asked on another forum, and the answers were "using reference and external method", which is a bit vague to me. Any help on this linking problem would be appreciated :(
I think that answer meant something like:
void draw_in_class (sf::RenderWindow* window){
window->draw(...);
}
in class, and then you can use 'draw_in_class' in main:
#include"class.h"
... // Define sf::RenderWindow here
draw_in_class(&window);

wxWidgets include image during compile time

I've been trying to make a simple wxWidgets program with just a button with a picture on it. I've been able to make the button with the image on it easily enough, but my problem arises when including it.
So far, I've only been able to fetch the image during run-time (the image has to be in the same folder as the .exe file; otherwise, I get error 2: the system cannot find the file specified). With this method, I have no problems -- the program works just fine. What I'm trying to do, however, is to #include the file so that it is embedded during compile-time, so that it doesn't need to be available during run-time.
I've tried #including the file (both as .png and as .xpm), and I've also tried adding it to the resource includes (this is on Visual Studio 2017). Neither of these worked -- the first method still required the image to be in the same folder, and the second failed during compilation (as far as I can tell, it wasn't able to read the .xpm file).
Here is the relevant code, if it helps:
/*relevant includes*/
#include "happyFace.png" //this isn't working. the file is still needed
||
#include "happyFace.xpm" //ditto
/*I have also tried putting these lines in the resource includes.*/
/*code*/
wxInitAllImageHandlers();
wxBitmap bitmap("happyFace.xpm", wxBITMAP_TYPE_XPM); //only works in same directory at run-time
||
wxBitmap bitmap("happyFace.png", wxBITMAP_TYPE_PNG); //ditto
wxButton *button = new wxButton(this, ID_BMP_BUTTON);
button->SetBitmap(bitmap);
//the rest of the button programming and stuff
Sorry if I haven't provided enough information; I can provide more if necessary. I would really appreciate any help. Thanks!
Two possibilities... Number 1 is simplest. It's been a long time since I wrote the code I'm looking at, so the details are fuzzy.
In Visual Studio, Solution Explorer, add the image into the resource files. Assume the name of the resourse is sample.rc. Then it can be used like so to set the main icon...
SetIcon(wxICON(sample));
Method 1 must be used in order for MS Windows Explorer to display the main icon. I do not remember how to use .rc resources for other things, but it should be easy to figure out.
I did it this way before I discovered VS resource (.rc) files. Compile the file-image into the program "by hand." In other words, write a program that will read an image file and produce bit-for-bit copy in a .cpp file. Then compile that .cpp into the program. Here I have the file-image in memory as an object named dj::main_cursor. Note that the in-memory version is a bit-for-bit copy of a .cur file.
dj::captured_file &c1file(dj::main_cursor);
wxMemoryInputStream cistr(c1file.contents, c1file.size);
cursor1 = wxCursor(wxImage(cistr, wxBITMAP_TYPE_CUR));
FYI, I defined the structure dj::captured_file like so:
struct captured_file {
const char *name;
const unsigned long size;
const void *contents;
captured_file(const char*fn, size_t sz, const void*c)
: name(fn)
, contents(c)
, size(sz)
{}
};
See also, Embedding PNG Images into Windows RC Files
I found some other documentation.
Resources and Application Icon All applications using wxMSW should
have a Windows resource file (.rc extension) and this file should
include include/wx/msw/wx.rc file which defines resources used by
wxWidgets itself.
Among other things, wx.rc defines some standard icons, all of which
have names starting with the "wx" prefix. This normally ensures that
any icons defined in the application's own resource file come before
them in alphabetical order which is important because Explorer
(Windows shell) selects the first icon in alphabetical order to use as
the application icon which is displayed when viewing its file in the
file manager. So if all the icons defined in your application start
with "x", "y" or "z", they won't be used by Explorer. To avoid this,
ensure that the icon which is meant to be used as the main application
icon has a name preceding "wxICON" in alphabetical order.
http://docs.wxwidgets.org/3.1.0/page_port.html
Here is how you should do it:
#include "happyFace.xpm"
wxBitmap bitmap = wxBitmap( happyFace ); // assuming the variable name is "happyFace" inside the xpm
Then you will use bitmap object just like usual. Assuming that the file happyFace.xpm is available for compilation.

Made a Text Browser in QT but the Code Acts Like it Doesn't Exist?

I'm pretty new to QT so maybe the answer to this question is simple. I'm making a terminal for our freescale car this year which is just a car that autonomously goes around a track. We're using line-scan cameras which give you a line of data 128 pixels long that you refine into either "white" or "black" (edges of the track) values. Last year the team made this terminal in QT which is used for modifying certain coefficients, stopping the motors, and all kinds of stuff through bluetooth. A text browser was used to display what the line cameras see.
Last year they combined the two cameras to create one image, but we're re configuring them this year, and they will produce two different images of the track. Naturally, I need to make two text browsers, one for each camera. Should simply be a case of copying code and changing some names right? Well apparently not.
I placed the text browser in the window using the design gui, named it, and made its settings match the other browser. I went into the code for the main window c file and adapted the code there. For every reference to the other browser I made sure one was an equal line of code for this one. When I was done and went to build the project, it told me that the browser wasn't a member of 'UI::MainWindow,' and pointed me to the ui_mainwindow.h file. So I went into that header and did the same thing in there. But when I built that, it gave me the error:
...\ui_mainwindow.h:1363: error: C2065: 'tb_camera_out_close' : undeclared identifier
How can that be? There doesn't appear to be any other reference to the other text browser and it works fine. How do I go about declaring this? Shouldn't the gui interface have done it for me when I placed it?
Here's the code from the main window's C file that is involved:
ui->tb_camera_out->setText(msgs_received[1] + '\n' + ui->tb_camera_out->toPlainText());
ui->tb_camera_out_close->setText(msgs_received[2] + '\n' + ui->tb_camera_out_close->toPlainText());
tb_camera_out is the old camera code(I am aware that the toplaintext() part won't work, I'm also attempting to get the text to scroll down instead of up like a track would if you were actually driving but I need to fix this major issue first)
Here's the code from the header that I added:
tb_camera_out = new QTextBrowser(centralWidget);
tb_camera_out->setObjectName(QStringLiteral("tb_camera_out"));
sizePolicy.setHeightForWidth(tb_camera_out->sizePolicy().hasHeightForWidth());
tb_camera_out->setSizePolicy(sizePolicy);
tb_camera_out->setMinimumSize(QSize(450, 0));
tb_camera_out->setMaximumSize(QSize(16777215, 16777215));
tb_camera_out->setStyleSheet(QLatin1String("background-color: rgb(0, 0, 0);\n" "color: rgb(31, 234, 0);"));
gridLayout_4->addWidget(tb_camera_out, 1, 0, 1, 5);
tb_camera_out_close = new QTextBrowser(centralWidget);
tb_camera_out_close->setObjectName(QStringLiteral("tb_camera_out_close"));
sizePolicy.setHeightForWidth(tb_camera_out_close->sizePolicy().hasHeightForWidth());
tb_camera_out_close->setSizePolicy(sizePolicy);
tb_camera_out_close->setMinimumSize(QSize(450, 0));
tb_camera_out_close->setMaximumSize(QSize(16777215, 16777215));
tb_camera_out_close->setStyleSheet(QLatin1String("background-color: rgb(0, 0, 0);\n" "color: rgb(31, 234, 0);"));
Again, the old code is at the top with the references to tb_camera_out. The stuff I added is associated with tb_camera_out_close.
I seem to have solved the problem. Strangely enough, to fix the errors that were showing up I not only had to edit that header, but I then had to delete it and run qmake to restore it. I then had to delete all the past builds to get the thing to even show up when I ran it.

What could be the cause for runtime "can't find linker symbol for virtual table..." error in Qt?

This question was asked in similar ways multiple times, for example at stackoverflow or forum.qt.io or qtcentre.org. The problem is that this error message is so vague that one solution cannot be applied to another scenario. Most of the threads are dead in the middle of the discussion though :-(
So the complete error message that I get in my Qt application is:
can't find linker symbol for virtual table for "OneOfMyClasses" value
found "QString::shared_null" instead
The OneOfMyClasses changes depending on various things, the QString::shared_null stays the same for all errors that I get. Here is a screenshot of my logging console:
Why is the font color pink, so who is printing this message?
Why do I only see this message when I set a breakpoint and step through my code? This message does not appear when simply running the application.
The point where it happens is in this function in the source line right before the current position (yellow arrow):
So according to the message I stepped into m_pStateWidget->insertNavLabel(...) and the error message is printed somewhere in the constructors inside Qt related to the QString class. So I tried the following, which moves the problem away from this code location:
When doing this I get the same error message a few code lines below with another class name in the message, note that the QString::shared_null stays the same.
It appears to me that I have some sort of corrupted memory.
How should I start investigating this issue? I'm afraid to change the code because this might hide the problem as described above.
What's up with the QString::shared_null? I have found that others often see the same in their error messages.
Thank you for any hint or help! :-)
Edit: It's becoming really interesting now. I have stepped into every single function just right before the message is printed and I ended up with these error messages:
at this location:
When I navigate through the call stack in QtCreator the error is printed again and again everytime I select another function in the stack.
Does this mean that the debugger is printing the message and that it is simply too stupid to resolve some sort of vtable stuff for me or does this mean that I have serious trouble going on?
Cause:
Somewhere in your code , you might have overrun the actual memory
Example 1 :
int elmArray[10];
for(int i = 0; i < 20; ++i)
{
elmArray[i] = 0;
}
In the above case, actual array size is 10 but we are assigning values to the index beyond 10.
Example 2:
char* cpyString;
strcpy(cpyString , "TEST");
These scenarios might end up in writing the values into other objects. Mostly could corrupt the virtual table.This gives the above warning.
Fix:
As you know, just correct the code as below.
Example :
int elmArray[10];
for(int i = 0; i < 10; ++i)
{
elmArray[i] = 0;
}
char cpyString[10];
strcpy(cpyString , "TEST");
In your case seems like, you are assigning the QTString::shared_null to some uninitialized string.
There are various threads on different websites where the
can not find linker symbol for virtual table
problem is discussed. Few explain why the problem exists, although some solutions are given to specific examples. Having experienced difficulty with this, I would like to share what I have learned.
First this error message only appeared for Linux builds, it did not show up for Windows builds.
In my case the problem was caused by a second call into a non-reentrant method from the same thread. Once I found the problem, it was easy to fix by using a static busy flag, and simply returning when busy was called a second time. In a nutshell that was the problem and solution. But how did I get into this mess?
Well the non-rentrant method was actually a Qt slot. Since I knew there was a possibility of the second call (actually an emit) being made from the first, the connect was set up with Qt::QueuedConnection. However, I later put up a splash screen QSplashScreen while the function was processing. Little did I realize that QSplashScreen::repaint() called QApplication::processEvents() which dispatched the second offending emit.
So I could have fixed the problem by removing the QSplashScreen and using a QLabel. However, while either works nicely in Windows, neither actually works in Linux, they put up a semi-transparent window and don't paint the contents (even repaint() and or processEvents() doesn't do it). So that is probably a Qt Linux bug, which is another story.

C++: Cannot instantiate a pointer directly

This is an SDL problem, however I have the strong feeling that the problem I came across is not related to SDL, but more to C++ / pointers in general.
To make a long story short, this code doesn't work (edited to show what I really did):
player->picture = IMG_Load("player");
SDL_BlitSurface(player->picture, NULL, screen, &pictureLocation);
I see nothing on the screen. However, when I do it like this, it works:
SDL_Surface* picture = IMG_Load("player.png");
player->picture = picture;
SDL_BlitSurface(player->picture, NULL, screen, &pictureLocation);
I can see the little guy just fine.
The real problem is that I cannot instantiate Player::picture directly. Even when I try
picture = IMG_Load("player.png")
in player.cpp, I end up with a nullpointer.
I am so stupid. Turns out like I forgot the file extension ".png" every time I tried to store the surface in Player::picture, and conveniently remembered to add it every time I stired it in an SDL_Surface declared in main.cpp.
I had the feeling I was overlooking something really simple here, but this is just embarassing. What's a fitting punishment for this?
What data type is player->picture? What type does IMG_Load return? It's really hard to come up with a scenario where saving an expression in a temporary variable changes the result, unless a type conversion is involved.
And I wouldn't call this pointer instantiation. You're instantiating an instance of some picture type and storing a pointer to it.
This is why you should always check to see what IMG_Load() returns...
SDL_Surface* picture = IMG_Load("player.png");
if (picture == NULL) {
// there was obviously some sort of error.
// what does SDL_GetError() say?
}
Some SDL functions return -1 if there is an error. Just check the documentation and make sure you're checking your function returns. These steps make debugging a lot easier.