I tried to make the classes hold RAII standards (as I get it .. I'm a hobby programmer), but the compiler/debugger complained about missing constructors (with empty brackets), so I added them + set_value() functions.
The point of elaborating so much on a simple rectangle is to lift the cloudiness of integrating GUI-types (top-down types like buttons and text-fields) from the foreground problem I'm trying to handle: openGL 2D & 3d graphics living in a lower-left coordinatesystem.
enum class eAnker:int{
high_left,
high_right,
low_left,
low_right,
}
class anker
{
friend node_handler;
public:
anker(){};
anker(glm::dvec2 Vec2):pPoint( new glm::dvec2(Vec2) ){};
anker(glm::dvec2 Vec2, eAnker ea):pPoint( new glm::dvec2(Vec2) ),anker_type(ea){};
virtual ~anker(){ delete pPoint; };
void set_value(glm::dvec2){pPoint=new glm::dvec2(v);}
void set_anchor_type( eAnker ea){ anker_type=ea; }
bool operator<( anker& a ){ return (pPoint->x<a.pPoint->x)<(pPoint->y<a.pPoint->y); };
protected:
glm::dvec2* pPoint;
eAnker anker_type;
};
class nRect:public anker
{
friend node_handler;
public:
nRect(){};
nRect(glm::dvec2 p):anker(p){};
nRect(glm::dvec2 p,double lineHeight, double letterWidth):anker(p),plHeight( new double(lineHeight)), plWidth( new double(letterWidth) ){};
virtual ~nRect(){
delete plHeight;
delete plWidth;
};
void set_dims( double Ww, double Lh ){
plWidth= new double(Ww*LETTER_PIXEL_WIDTH);
plHeight=new double(Lh*LINE_PIXEL_HEIGHT);
}
protected:
double* plHeight;
double* plWidth;
};
class node:public nRect
{
friend node_handler;
public:
node(){};
node(glm::dvec2 p):nRect(p){};
node(glm::dvec2 p, double wW, double lH):nRect(p,wW,lH){};
virtual ~node(){};
void mouse_up(){
on_click();
};
virtual void on_click(){
/*
bool b = !set_bit::is_closed(myBits);
set_bit::as_closed(myBits,b);
*/
};
protected:
vector<node>::iterator iParent;
bitset<32> myBits;
string string_data;
double my_ratio;
glm::dvec2 cursor_old;
};
class node_handler
{
public:
node_handler(){}
~node_handler(){};
void set_root( glm::dvec2 anker, double pixel_width, double pixel_height ){
if(!root_lock){
node n(anker,pixel_width/25.0d,pixel_height/12.0d) ;
n.string_data="root";
n.iParent = nodes.end();
nodes.resize(10);
nodes.at(0) = n ;
current=nodes.begin();
root_lock=true;
node_counter++;
}
else{
//cout << "BEEP nodes.root-error\n" << char(7);
}
}
void split_current( double ratio, bool as_horizontal ){
pair<node,node> res = split(current,ratio,as_horizontal);
res.first.string_data="-closer";
res.first.iParent=current;
res.second.string_data="-farther";
res.second.iParent=current;
if(node_counter<int(nodes.size()) ) {
nodes.at(node_counter)=res.first;
current=nodes.begin()+node_counter;
node_counter++;
nodes.at(node_counter)=res.second;
node_counter++;
}
else{
cout << "no handler-space for more nodes\n" ;
}
//no errors so far. when leaving split_current(..), the execution halts with a SIGSEGV
}
protected:
int node_counter=0;
private:
pair<node,node>split( vector<node>::iterator& this_node, double ratio, bool as_horizontal ){
this_node->my_ratio=ratio;
double firstW, firstH;
double secW, secH;
glm::dvec2 afirst, asecond;
if(as_horizontal ){
// set values
}
return make_pair<node,node>( node(afirst ,firstW, firstH), node(asecond ,secW, secH) ) ;
}
vector<node>::iterator current;
vector<node> nodes;
bool root_lock{false};
};
/////////////////////
test in main:
node_handler nh;
glm::dvec2 minor=glm::dvec2(0.0d, 0.0d);
double width=800.0d;
double height=600.0d;
nh.set_root(minor,width,height);
nh.split_current( 1.0d/10.0d , true );
//see nh.split_current() where SIGSEGV happens
The debug error-trace leaves 10 lines, noone pointing to a specific line in my code:
ntdll!RtlAnsiSringToUnicodeString()
??()
std::basic_Ostream<.....
std::clog()
std::clog()
??()
msvcat!_iob()
vtable for ct::anker
std::piecewise_construct
link is a follow-up, on the same code, that probably contain the proper answer to the erratic behavior described. In short (as I understand it): classes with pointer-members needs customized copy/assignment operators these they are at work, without your notice, behind the code you write .. the default ones won't work.
I didn't provide them.
Related
I'm currently trying for a game project to get rid of a dangling reference when a plane crashes before reaching the terminal it was booked to reach.
I would like to go through <algorithm> functions only to better understand how they work.
At the moment I've tried going through the map that contains all the planes associated with a terminal, comparing it with the list of all the planes and checking if a plane that is in the map is no longer in the vector then delete it from the map to free the associated terminal.
void remove_crashed_aircraft(std::unordered_map<const Aircraft*, size_t>& reserved_terminals, std::vector<std::unique_ptr<Aircraft>>& aircrafts)
{
auto it = std::all_of(reserved_terminals.begin(), reserved_terminals.end(),
[aircrafts](const Aircraft* a1){ return std::find_if(aircrafts.begin(), aircrafts.end(),
[a1](std::unique_ptr<Aircraft> a2){ return a1==a2.get();});});
reserved_terminals.erase(it);
}
And this is my Aircraft class:
class Aircraft : public GL::Displayable, public GL::DynamicObject
{
private:
const AircraftType& type;
const std::string flight_number;
Point3D pos, speed; // note: the speed should always be normalized to length 'speed'
WaypointQueue waypoints = {};
Tower& control;
bool landing_gear_deployed = false; // is the landing gear deployed?
bool is_at_terminal = false;
int fuel = 0;
// turn the aircraft to arrive at the next waypoint
// try to facilitate reaching the waypoint after the next by facing the
// right way to this end, we try to face the point Z on the line spanned by
// the next two waypoints such that Z's distance to the next waypoint is
// half our distance so: |w1 - pos| = d and [w1 - w2].normalize() = W and Z
// = w1 + W*d/2
void turn_to_waypoint();
void turn(Point3D direction);
// select the correct tile in the plane texture (series of 8 sprites facing
// [North, NW, W, SW, S, SE, E, NE])
unsigned int get_speed_octant() const;
// when we arrive at a terminal, signal the tower
void arrive_at_terminal();
// deploy and retract landing gear depending on next waypoints
void operate_landing_gear();
void add_waypoint(const Waypoint& wp, const bool front);
bool is_on_ground() const { return pos.z() < DISTANCE_THRESHOLD; }
float max_speed() const { return is_on_ground() ? type.max_ground_speed : type.max_air_speed; }
bool is_paused = false;
Aircraft(const Aircraft&) = delete;
Aircraft& operator=(const Aircraft&) = delete;
public:
Aircraft(const AircraftType& type_, const std::string_view& flight_number_, const Point3D& pos_,
const Point3D& speed_, Tower& control_, int fuel_) :
GL::Displayable { pos_.x() + pos_.y() },
type { type_ },
flight_number { flight_number_ },
pos { pos_ },
speed { speed_ },
control { control_ },
fuel { fuel_ }
{
speed.cap_length(max_speed());
}
const std::string& get_flight_num() const { return flight_number; }
float distance_to(const Point3D& p) const { return pos.distance_to(p); }
bool is_circling() const
{
if (!has_terminal() && !is_at_terminal)
{
return true;
}
return false;
}
bool has_terminal() const
{
if (waypoints.empty())
{
return false;
}
else
{
return waypoints.back().type == wp_terminal;
}
}
bool is_low_on_fuel() const
{
if (fuel<200)
{
return true;
}
else
{
return false;
}
}
void display() const override;
bool move() override;
void refill(int& fuel_stock);
friend class Tower;
friend class AircraftManager;
};
The code of the function generates errors that I can't understand unfortunately.
use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = Aircraft; _Dp = std::default_delete<Aircraft>]’
static assertion failed: result type must be constructible from value type of input range
If anyone has an idea of how I can achieve this, I would be very grateful!
First, you have to use std::remove_if, because std::all_of returns bool, not iterator. But std::remove_if does what you want, it removes all instances that match bool predicate.
Second, your compile errors appear because you pass by value everywhere, so instead of (std::unique_ptr<Aircraft> a2) pass reference (std::unique_ptr<Aircraft> const & a2), instead [aircrafts] and [a1] pass [&aircrafts] and [&a1].
Third, inner predicate should not just return result of std::find_if (which returns iterator) but return bool, i.e. compare result of find_if to aircrafts.end().
Speed-wise your algorithm can be optimized if needed, for that you have to convert std::vector to std::unordered_set and then iterate through first map and check containment inside second set. If you don't have too many elements and speed is not of much importance then your algorithm is alright.
Final working code below:
void remove_crashed_aircraft(
std::unordered_map<const Aircraft*, size_t>& reserved_terminals,
std::vector<std::unique_ptr<Aircraft>>& aircrafts
) {
std::remove_if(reserved_terminals.begin(), reserved_terminals.end(),
[&aircrafts](auto const & a1){
return std::find_if(aircrafts.begin(), aircrafts.end(),
[&a1](auto const & a2){ return a1.first == a2.get(); })
== aircrafts.end();
}
);
}
I have a basic example of adding a class to a vector:
std::vector<AudioFile> audioList;
DllExport void add_audio(const char* srcFile, double startSecInSrc, double fromSecInMovie, double toSecInMovie, long id)
{
AudioFile a(id, srcFile, startSecInSrc, fromSecInMovie, toSecInMovie);
audioList.push_back(a);
}
at the end of the function I get the stack corrupted around variable a
What am I doing wrong?
class AudioFile
{
long _id;
std::string _fileLocation;
double _startSecInSrc, _fromSecInMovie, _toSecInMovie;
double _duration;
public:
AudioFile(long _id, std::string _fileLocation, double _startSecInSrc,double _fromSecInMovie, double _toSecInMovie);
~AudioFile();
static bool ComparePredicat(AudioFile first, AudioFile second);
};
bool AudioFile::ComparePredicat(AudioFile first, AudioFile second)
{
if (first._startSecInSrc <= second._startSecInSrc)
return true;
return false;
}
AudioFile::AudioFile(long id, std::string fileLocation, double startSecInSrc, double fromSecInMovie, double toSecInMovie)
{
_id = id;
_fileLocation = fileLocation;
_startSecInSrc = startSecInSrc;
_fromSecInMovie = fromSecInMovie;
_toSecInMovie = toSecInMovie;
_duration = toSecInMovie - fromSecInMovie;
} AudioFile::~AudioFile()
{
}
Thanks.
There may be more going on, but to make a new object and save it, yuou should declare a variable and then initialize it. Use the new keyword. I.e. AudioFile a = new AudioFile(...); in your add_audio() fuction.
Also you could make your function slightly shorter ( but style could dictate how you want to write it) as:
audioList.push_back(new AudioFile(id, srcFile, startSecInSrc, fromSecInMovie, toSecInMovie));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am working on a chess game in c++ .
I have the classes :
class piece
{
protected :
point position ;
char represent ;
bool colour; // true for player 1 = green , false for player 0 = blue
public :
virtual ~piece() ;
bool find_player(piece* to_check, int num);
char get_char() ;
bool get_colour() ;
virtual bool move_setup(point source, point dest, piece* arr[][SIZE] ) = 0 ;
virtual bool move(point source, point dest, piece* arr[][SIZE]) = 0;
bool same_player(point dest, piece* arr[][SIZE], int* num);
};
class board
{
private:
piece* arr[SIZE][SIZE] ;
public :
board();
void free_borad();
void set_piece(int x , int y , int type , bool colour );
void print_board();
void move(point source , point dest);
void set_colour(int i , int j , bool reset );
};
class pawn : public piece
{
public :
pawn(point position , bool colour );
~pawn();
virtual bool move_setup(point source, point dest, piece* arr[][SIZE]);
virtual bool move(point source, point dest, piece* arr[][SIZE]);
bool if_forward(point source, point dest);
bool if_diagonal(point source, point dest, int* offset);
};
I have a class for every piece in which I have implemented the move functions.
the classes are not relevant so I just put a pawn class for the example .
the board move function :
void board::move(point source, point dest)
{
if (arr[source.get_x()][source.get_y()]) // if not empty
{
int x = source.get_x(), y = source.get_y() ;
if (arr[x][y]->move_setup(source, dest, arr ) ) // if the piece can move there
{
delete arr[dest.get_x()][dest.get_y()];
arr[dest.get_x()][dest.get_y()] = arr[source.get_x()][source.get_y()];
arr[source.get_x()][source.get_y()] = NULL;
std::cout << " Succes! " << std::endl;
}
else
{
// error
}
}
else // empty
{
// error
}
}
my program crashes at the line
if (arr[x][y]->move_setup(source, dest, arr ) )
I have debbuged it using the VS debugger , and realized that the crash occurs when sending the array , error message :
Access violation reading location 0xFFFFFFFF.
I have tried to send it in many different ways , and nothing works ,
but this method is exactlly how a friend of mine did it , and it works just fine for him .
can anyone help ?
thank you .
Arrays in C++ are 0-based, which means the index of the first element is 0. If your coordinates are 1-based, it means you are accessing an element one row and one column off in the array. That in turn leads to breaching the bounds of the array and your crash. The solution is either to adopt a 0-based coordinate system or subtract 1 from the x/y coordinates when accessing the array.
I'm porting some code to another structure:
class EnvironObject
{
protected:
vector<float> mX, mY, mXSpeed, mYSpeed;
int mMaxObjects;
public:
virtual void init(int maxObjects);
virtual void setLimit(int limit);
virtual int getLimit();
virtual void update(float arg) = 0;
};
void EnvironObject::setLimit(int limit)
{
mMaxObjects = limit;
mX.resize(limit, 0); mY.resize(limit, 0);
mXSpeed.resize(limit, 0); mY.resize(limit, 0);
}
int EnvironObject::getLimit()
{
return mMaxObjects;
}
void EnvironObject::init(int maxObjects)
{
mX = mY = mXSpeed = mYSpeed = std::vector<float>(mMaxObjects);
fill(mX.begin(), mX.end(), 0);
fill(mY.begin(), mY.end(), 0);
fill(mXSpeed.begin(), mXSpeed.end(), 0);
fill(mYSpeed.begin(), mYSpeed.end(), 0);
/*mX.reserve(mMaxObjects * 1.5); mY.reserve(mMaxObjects * 1.5);
mXSpeed.reserve(mMaxObjects * 1.5); mYSpeed.reserve(mMaxObjects * 1.5);*/
mMaxObjects = maxObjects;
}
This is some basic class, now it's usage:
class Rain : public EnvironObject
{
public:
Rain(int maxDrops = 150);
void update(float windPower);
};
Rain::Rain(int maxDrops)
{
srand(time(NULL));
IEnvironObject::init(maxDrops);
}
void Rain::update(float windPower)
{
for (int i=0; i < mMaxObjects; i++)
{
mX[i] += mXSpeed[i];
mY[i] += mYSpeed[i];
mXSpeed[i] += windPower;
mYSpeed[i] += G;
// Drawing
}
}
The objects Rain creates with default constructor (so, each array is 150 elements size) and then I'm calling setLimit(50).
The problem is that code fails almost each running with exception:
terminate called after throwing an instance of 'std::bad_alloc'
And sometimes it segfaults at line:
mY[i] += mYSpeed[i];
I can't image what could it be, because the code is old and it worked. The new one is only base class.
And when I'm looking at RAM usage when starting app, I see almost +600 mb!
Look again at that function of yours:
void EnvironObject::init(int maxObjects)
{
mX = mY = mXSpeed = mYSpeed = std::vector<float>(mMaxObjects);
// ^
// ...
mMaxObjects = maxObjects;
}
You're using a not yet initialized variable.
A big problem with your class is that you are doing what's called two-phase construction. Your class EnvironObject has a compiler-supplied default constructor that creates an object with random values for all POD types (mMaxObjects). Users then need to call the init() method to really initialize the object. But that's what constructors are there for!
void EnvironObject::EnvironObject(int maxObjects)
: mMaxObjects(maxObjects)
, mX(maxObjects), mY(maxObjects), mXSpeed(maxObjects), mYSpeed(maxObjects)
{
/* these aren't necessary, std::vector automatically does this
fill(mX.begin(), mX.end(), 0);
fill(mY.begin(), mY.end(), 0);
fill(mXSpeed.begin(), mXSpeed.end(), 0);
fill(mYSpeed.begin(), mYSpeed.end(), 0);
*/
}
Derived classes can then use this constructor:
Rain::Rain(int maxDrops)
: EnvironObject(maxDrops)
{
srand(time(NULL));
}
Regarding this crash in the subscription mY[i] += mYSpeed[i]:
This might happen when you are calling this function through a pointer that's pointing to nowhere.
You're using mMaxObjects in init() before initializing it. So it has a random value.
void EnvironObject::init(int maxObjects)
{
mX = mY = mXSpeed = mYSpeed = std::vector<float>(mMaxObjects); // you mean maxObjects here
I think you want to replace
void EnvironObject::init(int maxObjects)
{
mX = mY = mXSpeed = mYSpeed = std::vector<float>(mMaxObjects);
with
void EnvironObject::init(int maxObjects)
{
mX = mY = mXSpeed = mYSpeed = std::vector<float>(maxObjects);
Notice the replacement of mMaxObject to maxObjects in the vector creation.
One comment, though it won't likely fix your memory error, is that since the fields mX, mY, mXSpeed, and mYSpeed seem related and the vectors are all the same size, you should consider merging them into one structure with four members, and having a single vector containing several of those structure instances.
I have a few classes set up for a game, with XMapObject as the base, and XEntity, XEnviron, and XItem inheriting it.
MapObjects have a number of flags, one of them being MAPOBJECT_SOLID. My problem is that XEntity is the only class that correctly detects MAPOBJECT_SOLID. Both Items are Environs are always considered solid by the game, regardless of the flag's state. What is important is that Environs and Item should almost never be solid.
Each class has a very basic preliminary constructor, just initializing all varibles to zero or NULL. During the CreateX() phase, Objects are linked into the map, set into a linked linked list.
Both XItem and XEnviron are a tad sloppy. They are both new, and in the middle or my debugging attempts.
Here are the relevent code samples:
XMapObject:
#define MAPOBJECT_ACTIVE 1
#define MAPOBJECT_RENDER 2
#define MAPOBJECT_SOLID 4
class XMapObject : public XObject
{
public:
Uint8 MapObjectType,Location[2],MapObjectFlags;
XMapObject *NextMapObject,*PrevMapObject;
XMapObject();
void CreateMapObject(Uint8 MapObjectType);
void SpawnMapObject(Uint8 MapObjectLocation[2]);
void RemoveMapObject();
void DeleteMapObject();
void MapObjectSetLocation(Uint8 Y,Uint8 X);
void MapObjectMapLink();
void MapObjectMapUnlink();
};
XMapObject::XMapObject()
{
MapObjectType = 0;
Location[0] = 0;
Location[1] = 1;
NextMapObject = NULL;
PrevMapObject = NULL;
}
void XMapObject::CreateMapObject(Uint8 Type)
{
MapObjectType = Type;
}
void XMapObject::SpawnMapObject(Uint8 MapObjectLocation[2])
{
if(!(MapObjectFlags & MAPOBJECT_ACTIVE)) { MapObjectFlags += MAPOBJECT_ACTIVE; }
Location[0] = MapObjectLocation[0];
Location[1] = MapObjectLocation[1];
MapObjectMapLink();
}
XEntity:
XEntity *StartEntity = NULL,*EndEntity = NULL;
class XEntity : public XMapObject
{
public:
Uint8 Health,EntityFlags;
float Speed,Time;
XEntity *NextEntity,*PrevEntity;
XItem *IventoryList;
XEntity();
void CreateEntity(Uint8 EntityType,Uint8 EntityLocation[2]);
void DeleteEntity();
void EntityLink();
void EntityUnlink();
Uint8 MoveEntity(Uint8 YOffset,Uint8 XOffset);
};
XEntity::XEntity()
{
Health = 0;
Speed = 0;
Time = 1.0;
EntityFlags = 0;
NextEntity = NULL;
PrevEntity = NULL;
IventoryList = NULL;
}
void XEntity::CreateEntity(Uint8 EntityType,Uint8 EntityLocation[2])
{
CreateMapObject(EntityType);
SpawnMapObject(EntityLocation);
if(!(MapObjectFlags & MAPOBJECT_SOLID) { MapObjectFlags += MAPOBJECT_SOLID; }
EntityFlags = ENTITY_CLIPPING;
Time = 1.0;
Speed = 1.0;
EntityLink();
}
void XEntity::EntityLink()
{
if(StartEntity == NULL)
{
StartEntity = this;
PrevEntity = NULL;
NextEntity = NULL;
}
else
{
EndEntity->NextEntity = this;
}
EndEntity = this;
}
XEnviron:
class XEnviron : public XMapObject
{
public:
Uint8 Effect,TimeOut;
void CreateEnviron(Uint8 Type,Uint8 Y,Uint8 X,Uint8 TimeOut);
};
void XEnviron::CreateEnviron(Uint8 EnvironType,Uint8 Y,Uint8 X,Uint8 TimeOut)
{
CreateMapObject(EnvironType);
Location[0] = Y;
Location[1] = X;
SpawnMapObject(Location);
XTile *Tile = GetTile(Y,X);
Tile->Environ = this;
MapObjectFlags = MAPOBJECT_ACTIVE + MAPOBJECT_SOLID;
printf("%i\n",MapObjectFlags);
}
XItem:
class XItem : public XMapObject
{
public:
void CreateItem(Uint8 Type,Uint8 Y,Uint8 X);
};
void XItem::CreateItem(Uint8 Type,Uint8 Y,Uint8 X)
{
CreateMapObject(Type);
Location[0] = Y;
Location[1] = X;
SpawnMapObject(Location);
}
And lastly, the entity move code. Only entities are capable of moving themselves.
Uint8 XEntity::MoveEntity(Uint8 YOffset,Uint8 XOffset)
{
Uint8
NewY = Location[0] + YOffset,
NewX = Location[1] + XOffset;
if((NewY >= 0 && NewY < MAPY) && (NewX >= 0 && NewX < MAPX))
{
XTile *Tile = GetTile(NewY,NewX);
if(Tile->MapList != NULL)
{
XMapObject *MapObject = Tile->MapList;
while(MapObject != NULL)
{
if(MapObject->MapObjectFlags & MAPOBJECT_SOLID)
{
printf("solid\n");
return 0;
}
MapObject = MapObject->NextMapObject;
}
}
if(Tile->Flags & TILE_SOLID && EntityFlags & ENTITY_CLIPPING)
{
return 0;
}
this->MapObjectSetLocation(NewY,NewX);
return 1;
}
return 0;
}
What is wierd, is that the bitwise operator always returns true when the MapObject is an Environ or an Item, but it works correctly for Entities. For debug I am using the printf "Solid", and also a printf containing the value of the flag for both Environs and Items.
Any help is greatly appreciated, as this is a major bug for the small game I am working on. I am also very new at Object Oriented programming, anything tips, suggestions and/or criticism are also welcome.
Your problem appears to be that you never initialize MapObjectFlags in any classes other than XEnviron so, as a basic type, it will have an unspecified value in XItem, XEntity and other XMapObject derived objects. I suggest that, as a member of XMapObject you explicitly initialize it to a known value.
As a rule, it is generally a good idea to ensure that all members of basic type are explicitly initialized in the initializer list of every constructor that you define.
e.g.
XMapObject()
: MapObjectFlags(0)
, // ... other initializers
{
// Other initializations
}
You can't (legally) be calling XEntity::MoveEntity on a MapObject or Environ because they don't have such a method. If you're using static_cast to change your object pointer into an XEntity so you can call MoveEntity on it, then you really have no guarantees about how the bit operation will work. In some implementations, things may appear to work in MoveEntity, but what's actually happening is it's interpreting the other object's memory as an XEntity. When it tries to access the offset where it believes MapObjectFlags exists, it's not actually there and always has that bit set to 1.
I figured out the problem earlier today - It didn't have any relation to OO programming, inheritance, or bitwise; it was a simple scope error.
The problem was in the fact that during my quick test to get an Environ in game, I declared the new variable inside of the control switch sequence, so the next time any control was used, the Environ would act in unpredictable ways.
switch(Event.key.keysym.sym)
{
...
case SDLK_c: { XEnviron Environ; Environ.InitEnviron(...); }
...
}