Author Topic: Error when trying to run a graphical code  (Read 339 times)

Offline Tomi

  • Single posting newcomer
  • *
  • Posts: 3
    • My website
Error when trying to run a graphical code
« on: July 18, 2019, 11:42:49 am »
Hello everybody!

I'm still new here and I began to use C::B only few weeks ago. But I have a big problem: when I try to run my graphical code, C::B gives the following error message:
Process terminated with status -1073741819 (0 minute(s), 7 second(s))
What means this and how can I solve this problem?
My code is the follow in C++:

Code: [Select]
#include <math.h>
#include <graphics.h>

int main() {
const unsigned XMAX = 1200, YMAX = 500;

initwindow(XMAX, YMAX, "First Sample");
//printf("window: %u %u\n", getmaxx(), getmaxy());

circle(100, 50, 40);
line(0, 0, getmaxx(), getmaxy());
putpixel(10, 20, GREEN);
rectangle(0, 0, getmaxx(), getmaxy());
ellipse(200, 200, 90, 180, 100, 50);

while (!kbhit())
delay(200);
closegraph();

return 0;
}

I added the graphics.h file as follow: right click on it in Management tab/Projects and Add files. Is this correct? Previously I added in the Linker Settings:
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
and the way to libbgi.a.
But I don't know that these lines are needed to graphical works or adding graphics.h is enough to this? (Unfortunatelly I don't know the meaning of these 6 lines.)
Somebody can explain that how should I set the graphics mode in C::B with various graphical tools (BGI, SDL, SFML)? Is it enough to attach the graphics.h in the Management tab or I need to always add those 6 lines too?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2492
Re: Error when trying to run a graphical code
« Reply #1 on: July 18, 2019, 01:34:17 pm »
if this error is during compiling:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

if this error is during running your application this is not a codeblocks error.
Normally a negative status does mean that your application crashed and you made an error in your code, or some dll is missing...
graph.h is quite old and normally used by the borland c compiler. I do not know if you can use this header with gcc and mingw... Or even if this still works on windows > 7 without some fancy compatibility mode...

You can try to run the application with the debugger (read arrow) and look if you get some more information...

Offline Tomi

  • Single posting newcomer
  • *
  • Posts: 3
    • My website
Re: Error when trying to run a graphical code
« Reply #2 on: July 18, 2019, 02:03:34 pm »
Thanks, BlueHazzard!
I ran the code with the debugger and I got this message:
Program received signal SIGSEGV, Segmentation fault.
In std::string::assign(char const*, unsigned int) () ()

What should I do? Trying use other graphical tools (e.g. SDL, SFML) instead of this old graphics.h?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2492
Re: Error when trying to run a graphical code
« Reply #3 on: July 18, 2019, 02:18:28 pm »
Quote
What should I do? Trying use other graphical tools (e.g. SDL, SFML) instead of this old graphics.h?
Would be more complicated but i think this is the better way. With this you are also platform independent and this will work in the future...
The question is what do you want to do with it...

Quote
Program received signal SIGSEGV, Segmentation fault.
In std::string::assign(char const*, unsigned int) () ()
Well now we know that it is not a codeblocks problem, but one of your program and so this is the wrong forum to ask this kind of questions...
Btw. this line alone does not tell anything. You need a stack trace for more information:
Debug->debugging windows->call stack
There you see exactly where the error happens (the root of the function)

I think in your case it is because you build a c programm with the c++ compiler. Try to rename the your file extension from "cpp" to "c" and try again. (this is a wild guess in the blue.... I have no idea what went wrong in your case...)