Jump to content
  • Advertisement
Sign in to follow this  
Sylvarant

segmentation fault

This topic is 4312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Show your code and I will take a look at it. Like EasilyConfused said, you are probably out of bounds.

Share this post


Link to post
Share on other sites
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 properties
void Win_prop();
// update function
void Window_status();
// constructor
Error_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 handle
HWND 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 status
Window_status();
}





Share this post


Link to post
Share on other sites
I don't know windows programming, but the function Window_status looks fishy, aren't you using an uninitialized local variable?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Quote:
wac.lpfnWndProc = NULL;

This should be causing your crash; you need a valid message handler.
Also, fix what the poster above pointed out.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!