Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Strange program crash
Strange program crash [message #39157] Wed, 20 February 2013 20:57 Go to next message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
I am facing strange program crash.

System windows 7 64 bits, UPP5800, MSC10,

Test code.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyApp : TopWindow {
	Image image;
		#define MAX_COL 750
		#define MAX_ROW 750
		
		struct Node
		{
			struct Node *Header;
			struct Node *Left;
			struct Node *Right;
			struct Node *Up;
			struct Node *Down;
			char IDName;
			int  IDNum;
		} ;

		struct Node  Root;
		struct Node Roots[MAX_COL];
		
		char Data[MAX_COL][MAX_ROW];
		
//		struct Node Matrix[MAX_COL][MAX_ROW];

	void Paint(Draw& w) {
		w.DrawRect(GetSize(), Cyan());
		w.DrawImage(10, 10, image);
	}

	MyApp() {
		ImageDraw iw(100, 40);
		iw.Alpha().DrawRect(0, 0, 100, 40, GrayColor(0));
		iw.Alpha().DrawEllipse(0, 0, 100, 40, GrayColor(255));
		iw.DrawEllipse(0, 0, 100, 40, Yellow());
		iw.DrawText(26, 10, "Image", Arial(16).Bold());
		image = iw;
	}
};

GUI_APP_MAIN
{
	MyApp().Sizeable().Run();
}


This code runs ok.

When I uncomment line with
struct Node Matrix[MAX_COL][MAX_ROW];
Program crashes on run.

Crash report
Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	Test1.exe
  Application Version:	0.0.0.0
  Application Timestamp:	51252483
  Fault Module Name:	Test1.exe
  Fault Module Version:	0.0.0.0
  Fault Module Timestamp:	51252483
  Exception Code:	c00000fd
  Exception Offset:	002c4207
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	2057
  Additional Information 1:	3a6e
  Additional Information 2:	3a6e02c22fcc91129d3773f5deb0f79b
  Additional Information 3:	39ad
  Additional Information 4:	39ad623814f92b971a57f1c746b1a539

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt


What can be the mistake ?



Warm Regards

Deepak
Re: Strange program crash [message #39158 is a reply to message #39157] Wed, 20 February 2013 21:17 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
It seems you have a stack overflow.

The MyApp object with the line uncommented is pretty big. When your program tries to create it on the stack, it may cause a stack overflow. You should generally avoid to allocate objects with this magnitude of size on the stack as stack is more limited than the heap.
Re: Strange program crash [message #39176 is a reply to message #39158] Fri, 22 February 2013 20:06 Go to previous messageGo to next message
deep is currently offline  deep
Messages: 263
Registered: July 2011
Location: Bangalore
Experienced Member
Hi Lance,

Thank you for your response.

Now I converted the Array struct Node Matrix[MAX_COL][MAX_ROW];
to Vector of Node. Changed declaration to

struct Node : Moveable<Node>

and

Vector< Vector<xNode>> Matrix;

This is working. I initialize this in for loop.

Now I have another problem.
Actually I am converting some c code to upp.

code in c
struct node *RowHeader[MAX_ROW];


I have declared it as vector.

Vector<Node> *RootHeader;


Now how do I set size to MAX_ROW for this vector?

I tried

RootHeader->Add() in for loop
(*RootHeader).Add() in for loop
RootHeader->SetCount(MAX_ROW);

What is correct syntax.

Program crashes here with following

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	Test1.exe
  Application Version:	0.0.0.0
  Application Timestamp:	5127b75d
  Fault Module Name:	Test1.exe
  Fault Module Version:	0.0.0.0
  Fault Module Timestamp:	5127b75d
  Exception Code:	c0000005
  Exception Offset:	00026a9c
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	2057
  Additional Information 1:	0a9e
  Additional Information 2:	0a9e372d3b4ad19135b953a78882e789
  Additional Information 3:	0a9e
  Additional Information 4:	0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt


Warm Regards

Deepak
Re: Strange program crash [message #39177 is a reply to message #39176] Sat, 23 February 2013 05:06 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
code in c
struct node *RowHeader[MAX_ROW];


more likely translates to

typedef struct node Node;
// actually, in C you need the struct, in
// c++, it can be opted out
// so
// typedef node Node; 
// is the same
 Vector<Node*> RootHeader;


However, you may want to put the dynamically allocated node* into some smart pointer so that they will be delete'd (free'd).

or you can do it yourself


class MyNodeContainer : public Vector<node*>
{
public: 
     ~MyNodeContainer()
     {
           for(int i=0; i<GetCount(); ++i)
               delete (*this)[i];
               // or free((*this)[i]); if the nodes are malloc'ed
      }
      and other method, eg, constructors,..
}

[Updated on: Sat, 23 February 2013 05:29]

Report message to a moderator

Re: Strange program crash [message #39178 is a reply to message #39177] Sat, 23 February 2013 05:18 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
You don't need to set the size in front.

If you know you will need that many nodes, you may want to Reserve(MAX_ROW);

If for some reason you want the vector to be with that many nodes, you can use the At() method of Upp::Vector, but be advised that your Vector of node pointers will be filled with uninitialized pointers; that's something you don't necessarily want.

C++ containers, eg. std::vector<T> and Upp::Vector<T>, unlike C array, can change its size dynamically to accommodate more elements with ease and with high performance (amortized constant speed). So you can safely ignore the MAX_ROW etc part when you translate C code into C++.
Re: Strange program crash [message #39179 is a reply to message #39178] Sat, 23 February 2013 05:25 Go to previous message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Vector<Node> *RootHeader;


Here RootHeader is a pointer to a Vector<Node> object. eg.

Vector<Node> nodes;

Vector<Node>* RootHeader=&nodes;

//or

Vector<Node>* p=new Vector<Node>();




while
Vector<Node*> RootHeader;
// here on the other hand, RootHeader if a Vector of pointer to Node objects. Vector can be thought of as dynamic array.



Previous Topic: MSVC and code size
Next Topic: NaCl office
Goto Forum:
  


Current Time: Thu Mar 28 12:31:20 CET 2024

Total time taken to generate the page: 0.01669 seconds