segmentation fault

Started by
8 comments, last by Serapth 17 years, 6 months ago
Every time I try to run my program(using the debugger)it gives a segmentation fault. What does that mean?
Sylvarant @www.gamedesign.be
Advertisement
Probably that your program is trying to access memory that it shouldn't be.

Out-of-bounds array access is one common cause of this, or attempting to derefence a null pointer is another.
Show your code and I will take a look at it. Like EasilyConfused said, you are probably out of bounds.
thanx for the replies
here's the code
Error_check.h
 // Adriaan Larmuseau // Sylvarant Studios // Project-Mage version 0.1  //------------------------------------------------------------------------------// ERROR_CHECK HEADER VERSION 0.1//------------------------------------------------------------------------------#include "Windows.h"class Error_check {public:// set window propertiesvoid Win_prop();// update function void Window_status();// constructorError_check(char* error_report);// destructor~Error_check();}; 


Error_check.cpp
 // Adriaan Larmuseau // Sylvarant Studios // Project-Mage version 0.1  //------------------------------------------------------------------------------// ERROR_CHECK SOURCE CODE VERSION 0.1//------------------------------------------------------------------------------ #include "Error_check.h"void Error_check::Win_prop(){//create structure for window properties  WNDCLASSEX wac; // set size   wac.cbSize = sizeof(WNDCLASSEX);        // set window style wac.style = CS_CLASSDC;                  // set message handler wac.lpfnWndProc = NULL;  // set extra bytes for structure wac.cbClsExtra = 0;                      // set extra bytes for window instance wac.cbWndExtra = 0;                      // set unique HINSTANCE wac.hInstance = GetModuleHandle ( NULL );  // set cursor wac.hCursor = LoadCursor(NULL, IDC_ARROW);   // set background wac.hbrBackground = HBRUSH (COLOR_BTNFACE);                // set windows Icon wac.hIcon = LoadIcon(NULL, IDI_APPLICATION); // set Icon Sm wac.hIconSm = LoadIcon(NULL, IDI_APPLICATION);// set class wac.lpszClassName = "Error_check";              // set menu  wac.lpszMenuName = NULL;  // register structuur  RegisterClassEx(&wac); } void Error_check::Window_status(){// define window handleHWND window_handle;  // windows shows window ShowWindow(window_handle,SW_SHOW); // windows updates window UpdateWindow(window_handle); // windows shows the cursor      ShowCursor(TRUE);  }  Error_check::Error_check(char* error_report){ // create window properties Win_prop(); // create window handle HWND window_handle; // create window window_handle = CreateWindow("Error_check","Error_check",WS_POPUPWINDOW,                300,200,200,200,NULL,NULL,GetModuleHandle ( NULL ),NULL);//error message box MessageBox(window_handle,error_report, "Project-Mage error!", MB_OK|MB_ICONSTOP);     // update window statusWindow_status(); }  




Sylvarant @www.gamedesign.be
I don't know windows programming, but the function Window_status looks fishy, aren't you using an uninitialized local variable?
Quote:Original post by Iftah
I don't know windows programming


Same here, but Window_status looks fine to me. Since you are using a pupup window, try cutting CreateWindow("Error_check","Error_check",WS_POPUPWINDOW, 300,200,200,200,NULL,NULL,GetModuleHandle ( NULL ),NULL); down to CreateWindow("Error_check","Error_check",WS_POPUPWINDOW, 300,200,200,200);

Not sure if this will help since I don't program windows, but I'm pretty sure you can just use the default parameters here.

EDIT -

wac.lpszClassName = "Error_check";

According to http://windowssdk.msdn.microsoft.com/en-us/library/ms633577.aspx, lpszClassName should be null terminated.
What are you compiling this under btw? On VS 2k5 I needed to make a number of changes ( mostly revolving arounds strings ) to get it to compile.

However, here is a line that will definatly cause a seg fault:

HWND window_handle;  // windows shows window ShowWindow(window_handle,SW_SHOW); // windows updates window UpdateWindow(window_handle); 


You passing a handle to nothing into a call to ShowWindow. You need to call ( or have called ) CreateWindow to get a valid HWND to pass into ShowWindow().

Right now, its trying to call ShowWindow() on a NULL HWND value, which will cause it to go kaploowy!
Quote:wac.lpfnWndProc = NULL;

This should be causing your crash; you need a valid message handler.
Also, fix what the poster above pointed out.
Thanx for the answers
@Serapth in dev-c++ , I don't like VS
Sylvarant @www.gamedesign.be
Quote:Original post by lmb
wac.lpszClassName = "Error_check";

According to http://windowssdk.msdn.microsoft.com/en-us/library/ms633577.aspx, lpszClassName should be null terminated.


Just a quick point, but a const string like "Error_check" is null terminated automatically.

This topic is closed to new replies.

Advertisement