Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


deepDweller

Member Since 12 Feb 2011
Offline Last Active Jul 09 2013 11:07 PM

Topics I've Started

[AS3] Dynamically loading files from a webserver

31 March 2012 - 02:50 PM

Hi gamedev. I want to clarify something here before I attempt to implement it. I'm making a flash RPG, and in order to avoid long loading times, I want to make use of the LoadExternal and URLRequest classes provided with the Flex API in order to dynamically load music and level layouts from an outside source, rather than embedding them in the .swf file itself. With this in mind, can anyone tell me the downsides of storing the required music/level files on a web server, and having the swf dynamically load them via URL? Will this cause strain on the web server, considering there will, ideally, be many people playing the game at the same time?

Thanks in advance!

[ C++ ] Declaring an ifstream corrupts unrelated list<object>

06 May 2011 - 01:22 PM

Hi gamedev.net, my name is james and I usually only come here in moments of dire need, as I like to think of myself being perfectly capable of solving most programming problems on my own with a little google-fu and common sense. However, for the past two weeks, the project I've been tirelessly working on for the past five months has been put on hold because of a mind-boggling problem that has completely shut down my program and eluded any of my attempted fixes.

The problem takes place when the program calls a login validation function that has been working perfectly fine for about three months:
int validateLogin(string inputName, string inputPass, list<USER> &userList)

Now I know that people are going to tell me that if my function has been working for three months and only recently started malfunctioning without any changes, then it must mean that the problem lies elsewhere in my program. I know that's probably the case, and I don't expect you guys to be able to fix my problem just by looking at this one function itself. I came here because I'm completely at a loss for what to even look for. My program is a shredded, bloody mess - I've ripped out and reverted nearly two months of progress trying to find anything that could have possibly been causing the crash, to no avail. I'm at my wits end, and all enthusiasm for this project is dwindling. My last hope is that someone reading this post will give me some sort of hint as to what other parts of my program I can eradicate to find the source of the problem.

Anyway - the problem. The purpose of this validateLogin function is to check a text file where all the account information is held, and match it up with the inputName and inputPass arguments provided from the user, and then, if the name and password match up with a user described in the text file, the function will create a USER object with that information and add it to the userList. The userList (an std::list<USER> container) is passed by reference to this function so other classes are able to access it after it adds the new USER object. That's where the problem comes in. Whenever the validateLogin function declares an ifstream to read from the file, the list<USER> userList becomes unaccessable from any other part of the program without causing a crash.

I know the ifstream is causing the problem because I've tested the function with EVERYTHING commented out except for this line:
int validateLogin(string inputName, string inputPass, list<USER> &userList)
{
ifstream fromFile;
};

When trying to cout the userList.size() after calling this function, the program still crashes, a windows box popping up to alert me that the program needs to close.

Before I came here I tried making a new piece of code just to test lists and ifstreams working together, to make sure I hadn't missed anything obvious, and to see if a simplified replication of my original code would work without any crashing:
#include <iostream>
#include <list>
#include <fstream>

using namespace std;

class Foo
{
  	public:
 			int number;
 			Foo() { number = 1; };
};

class Derp
{
  	public:
 			int number;
 			
 			Derp() { number = 2; };
 			int performActionsWithList(list<Foo>  &fooList) 	{ ifstream fromFile("db_accounts.txt",  ifstream::in);   fromFile.close();   return 1; };
 			void passListHere(list<Foo>  &fooList)   			{  int hello =  performActionsWithList(fooList);  cout << fooList.size() <<  endl;  };
};





int main()
{
	Foo fooOne;
	Foo fooTwo;
	Derp derp;
	
	list<Foo> fooList;
	fooList.push_back(fooOne);
	fooList.push_back(fooTwo);
	
	derp.passListHere(fooList);
	return 0;
};
It works fine, outputting the number 2.

I know this isn't very much information about my code itself, so it will probably be difficult to give me any good advice on what to do next. I'm hoping that someone just has some kind of general knowledge about ifstreams and lists that could point me in the right direction. ie: have you experienced ifstreams crashing a program before? Could there be something wrong with the text file? Is the std::list the problem? Could the problem be something completely unrelated to both ifstreams and lists?

Thanks for reading my long post - any help is appreciated; even throwing out a little comment could potentially give me an idea to help solve the problem.

-james

Crazy crashing problems with std::vector<object*>

12 February 2011 - 05:31 PM

Hi GameDev.net. I've been working on a project and have been making a lot of progress, but for the past few days I've been stuck and haven't been able to find a solution. It seems like I'm lacking understanding of how vectors of pointers to objects work, because my program crashes whenever I try to push back new pointers to the vector. I'll illustrate my problem with this example code:

#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Thing
{
  	public:
 			string m_name;
 			Thing(string name)   {m_name = name;};
};

class GroupOfThings
{
  	public:
 			vector<Thing*> mp_thingVector;

 			string pointerNames();
};

//pointerNames(): Returns an easy to read list of the names of elements pointed to in the mp_thingVector.
string GroupOfThings::pointerNames()
{
   	string newString;
   	vector<Thing*>::iterator itr = mp_thingVector.begin();
   	
   	while ( itr != mp_thingVector.end() )
   	{
 			newString += ( (*itr)->m_name + "\n" );
 			++itr;
   	};
return newString;
};


int main()
{
vector<Thing> thingVector;
GroupOfThings newGroup;

string line;
getline(cin,line);
while (line != "EXIT")
{ 	
  	Thing newThing(line);
  	thingVector.push_back(newThing);
  	
  	newGroup.mp_thingVector.push_back( &thingVector.back() );
                                  	
                                  	cout << "Element names stored in thingVector: " << endl;
                                  	for (int b = 0;  b < thingVector.size();  b++)
                                  	{
                                  	cout << thingVector[b].m_name << endl;
                                  	};
                                  	cout << endl;
                                  	
                                  	
                                  	//Outputs the elements in the newGroup.mp_thingVector
                                  	cout << "Element names stored in newGroup.mp_thingVector: " << endl;
                                  	cout << newGroup.pointerNames();

  	getline(cin,line);
};

return 0;
}



What happens: I input one string. A "Thing" object is created with my string as its m_name. The Thing is added to the thingVector that was declared earlier in main(). A pointer to thingVector.back() is added to newGroup.mp_thingVector. The program outputs the m_name of all of thingVector's elements, and the m_name of all the elements referenced in newGroup.mp_thingVector. The important part (I would assume) is that the program works on the first iteration, but crashes on the second. It correctly outputs the content of both vectors for the first iteration, but during the newGroup.pointerNames function on the second iteration, it crashes. Can anybody get to the bottom of this for me? I've spent days on this and am running low on sanity. Thanks in advance!

(Quick edit: I suppose it would help clarify things to say that, yes, my intention is to have a vector of pointers that reference objects within another vector. Am I doing it wrong?)

PARTNERS