External program gives std::bad_alloc()
-
I have an external project that I want to run within QT using a .bat file. The compilation is entirely separate from the QT project, when I run the project externally it works fine with no errors, but if I run it from my QT project (during run time) it gives me a memory error.
I've used system(), QProcess::execute(), QProcess::start(), QProcess::startDetached() but nothing seems to work. One thing to note is that when compiling I get a missing <GL/freeglut.h> header file, even though I don't get this error when I compile externally. -
I have an external project that I want to run within QT using a .bat file. The compilation is entirely separate from the QT project, when I run the project externally it works fine with no errors, but if I run it from my QT project (during run time) it gives me a memory error.
I've used system(), QProcess::execute(), QProcess::start(), QProcess::startDetached() but nothing seems to work. One thing to note is that when compiling I get a missing <GL/freeglut.h> header file, even though I don't get this error when I compile externally.@Hollow10
Hello and welcome.One possibility is that your host genuinely does not have enough free memory when Qt Creator (and your calling program) is in memory and hence the sub-process has insufficient memory. Have a look at free memory before you spawn the sub-process.
In principle running via
QProcess
orsystem()
in themselves should have no relevance.I would also sort out whatever you are saying about an include file not being found in some circumstances. However, that is a compile-time thing, it does not affect runtime.
-
Hi, thanks for the quick reply.
I really doubt that my host is incapable of running both processes, I just checked and it's in no way near running out of memory.
I added the following line to the .pro file 'QMAKE_CXXFLAGS += -Wl,--large-address-aware' but it doesn't seem to make that much of a difference either.
I also changed my kit's compiler to match mingw's (the one I'm using externally), it did seem to get rid of the library problem but the memory error is still persistent. Thank you for your time. -
Hi, thanks for the quick reply.
I really doubt that my host is incapable of running both processes, I just checked and it's in no way near running out of memory.
I added the following line to the .pro file 'QMAKE_CXXFLAGS += -Wl,--large-address-aware' but it doesn't seem to make that much of a difference either.
I also changed my kit's compiler to match mingw's (the one I'm using externally), it did seem to get rid of the library problem but the memory error is still persistent. Thank you for your time.@Hollow10
Then it looks like you have an external program which sometimes generates bad_alloc(). For unknown reasons this seems to occur when run from your Qt program, that might be "coincidence". That is going to be pretty hard to track down. It is the external program which generates the bad_alloc(), not your Qt program which spawns it, right? -
in the linux world this would be explained by child inheriting restricting ulimit values from the parent. In windoze, I have no clue.
freeglut is an open source opengl ui library. your Qt project build isn't including the header when you compile internally.
-
@Kent-Dorfman Correct. I also went out of my way to link the library to the project but still nothing. Like I said previously changing QT's compiler seems to get rid of the error when the external compilation happens. I'm assuming QT forces its own compiler selected in the kit when running external scripts that have absolutely nothing to do with the project, correct me if I'm wrong.
-
@Kent-Dorfman Correct. I also went out of my way to link the library to the project but still nothing. Like I said previously changing QT's compiler seems to get rid of the error when the external compilation happens. I'm assuming QT forces its own compiler selected in the kit when running external scripts that have absolutely nothing to do with the project, correct me if I'm wrong.
@Hollow10 said in External program gives std::bad_alloc():
when the external compilation happens. I'm assuming QT forces its own compiler selected
I am lost as to where "compilation" is involved/implicated in your issue. You are running an external program and that is throwing a
bad_alloc()
. I don't see how compilation, or anything about your Qt program which spawns the subprogram, is at issue.Also, fyi, when you talk about "QT's compiler" or "Qt forces compiler" you are talking about the Qt Creator IDE, where you edit, build and optionally run your application from. That is not "Qt". Qt is a library of C++ classes which you include into and link against your own Qt application.
-
@Hollow10
Then it looks like you have an external program which sometimes generates bad_alloc(). For unknown reasons this seems to occur when run from your Qt program, that might be "coincidence". That is going to be pretty hard to track down. It is the external program which generates the bad_alloc(), not your Qt program which spawns it, right?@JonB I'm truly sorry for the lack of clarification. I was indeed talking about QT Creator IDE. Now that that's out of the way I want to clarify how my external program/shell works. it's a .bat file that compiles and then run an external project. I only execute the .bat file from QT.
When I run the .bat file manually it compiles and runs the external project flawlessly.Here's a quick run of the errors I encountered and the things I tried:
When run from QT, it gives me a compile-time error (missing header) followed by a runtime error (memory error) - to be more specific, the external program crashes and then throws a
bad_alloc()
.When changing the QT Creator IDE's kit compiler (to mingw's), matching my system's compiler, I no longer get compiling errors but I still get the memory error.
Compiling the program externally and only running it from QT still gives me the memory error.
I appreciate everyone's help, sorry for my lack of clarity earlier.
-
@JonB I'm truly sorry for the lack of clarification. I was indeed talking about QT Creator IDE. Now that that's out of the way I want to clarify how my external program/shell works. it's a .bat file that compiles and then run an external project. I only execute the .bat file from QT.
When I run the .bat file manually it compiles and runs the external project flawlessly.Here's a quick run of the errors I encountered and the things I tried:
When run from QT, it gives me a compile-time error (missing header) followed by a runtime error (memory error) - to be more specific, the external program crashes and then throws a
bad_alloc()
.When changing the QT Creator IDE's kit compiler (to mingw's), matching my system's compiler, I no longer get compiling errors but I still get the memory error.
Compiling the program externally and only running it from QT still gives me the memory error.
I appreciate everyone's help, sorry for my lack of clarity earlier.
@Hollow10 said in External program gives std::bad_alloc():
When run from QT, it gives me a compile-time error (missing header) followed by a runtime error (memory error) - to be more specific, the external program crashes and then throws a bad_alloc().
If you have a "compile-time error (missing header)" that means/should mean that the compilation is aborted. No linking is performed, and no executable is generated. If the
.bat
file still continues and runs some executable, then it cannot be an executable generated just now, it can only (presumably) be some executable left over from some previously run successful compile+link?At a guess, changing compilers/kits in Qt Creator might put some variables into the environment for the target compiler/kit. These might be inherited when you run that executable from Creator, and might affect the compilation it performs. That's all I can think of.
Start out, I think, by ensuring that the compilation/link is identical whether performed from within Creator or outside it. Then you know you are building the same executable either way.
I still don't know why you get a
bad_alloc
when you run the built executable inside versus outside Qt Creator. It could be "coincidence", e.g. a fault is there but it only shows up in certain circumstances. You might test running some other executable from your Qt application to verify that works without thebad_alloc
error. You should also check in your various compilations whether you are building for debug or release.