SFML community forums

General => SFML projects => Topic started by: Tigre Pablito on September 23, 2013, 07:06:18 am

Title: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 23, 2013, 07:06:18 am
Hello, Ladies and Guys from SFML

I'm working on a Sonic the hedgehog game, cos I'm a fan of it, and Mario, since I was a child
By now, it works fine, has 4 Zones, 2 Acts each one, and has an interesting memory problem

Here's the link to download my poor Sonic (exe, dlls, and data files, in a .rar)

My system is Windows 7 Ultimate, 32 bit, and the program is written in C#

I would need to know these:
* Should I post a link to the source code? (I would have no problem)
* There's a problem in the app, it throws an Exception of the OutOfMemoryException class, when loading Zone3Act1; Is it allowded to ask help about that here? If it's not, please tell me where it is (I already asked in the Help->General, and nobody knew how to solve my bug); if it is, then I explain it below;

On each game level, the program calls the LoadZone?Act?() method, which loads 2 Images (.jpg that are there in the LEVELS subfolder), the level's foreground and background ... in some levels, by now the background is null ... the Images are local variables, that are passed to 2 Sprites[,] splitted into 1000x1000 Textures
First I built the Images in runtime, and saved them to files (Image.SaveToFile()) ... when the app runs with the 1st option, it works fine (excepting for a casual SEHException - that I don't know what it means), ... but when it loads the Images directly from the .jpg files, it throws a disgusting OutOfMemoryException when attempting to load Zone3Act1.jpg ... I don't know how much RAM my program needs, but my system has 2 GB, ... then I ran the game, starting on Zone3Act1, and it ran up to 4-1, where occured the same problem

I tried Image.Dispose(), Texture.Dispose(), etc, etc ..., reallocating the objects with "new" ...

Perhaps if you see the code, someone will find the bug ... there are many files, but those where the problem could be are 3 or 4, and they aren't too long

If it isn't the correct place to talk about this, I'm sorry, and please tell me where should I do

(Bs As Argentina)
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 23, 2013, 07:27:25 am
I think I tested and posted in your prevous thread too, but your Sonic game still crashes on startup for me.

I have no experience with C# so I can't help any more directly, but you should definitely consider posting all of the source code, and posting a debug build of your game so people who know what they're doing can at least try to use a debugger on it.  It can't hurt.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 23, 2013, 11:40:54 am
It's O.K., MiLord!

Here's the link to my poor Sonic's source code files

These files just generates the executable, that needs the SFML DLLs and the DATA FILES folder to run
(if someone has difficulties in understanding the code, just inform, and I'll try to make it more legible, in all ways, such as longer variable names so they can be caught the idea what they are/do)

I think you (Ixrec) told me you were using Windows 8 64 bit ... I supose there must be a way to adapt a SFML app from 32 bit to 64 bit, I'll ckeck out, I think I remember that there is a SFML library version for both 32 and 64 bit ... but is it needed to recompile the program, or just copy the 64 bit DLLs to the folder where the exe is, to be able to run my game on a 64 bit system?

Maybe if you try to run my poor Sonic on a 32 bit system, it will run properly ...

* Please, if someone runs my program, tell me in what way it crashes
* If someone can help to solve my game's memory trouble, I will appreciate it very much
* So I will if you tell me how to adapt my poor game to different PCs, and OSs
* Welcome critics and suggestions to improve the app

The crash cause should be in the LEVEL subfolder files



PS: I know very well I'll have to improve the graphics, and all the game; remember the power of each bubble/shield you can get from the TV items (the fire bubble impedes fire to hit your character, the magnetic one lets you jump higher)
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: AlexAUT on September 23, 2013, 01:23:16 pm
Same here, Windows8 64bit.

Error message in the cmd:
Unbehandelte Ausnahme: System.BadImageFormatException: Die Datei oder Assembly "
sfmlnet-graphics-2, Version=, Culture=neutral, PublicKeyToken=null" oder
eine Abhängigkeit davon wurde nicht gefunden. Es wurde versucht, eine Datei mit
einem falschen Format zu laden.
Dateiname: "sfmlnet-graphics-2, Version=, Culture=neutral, PublicKeyToken
   bei SonicTheHedgehog.Program.Main()

Sadly I'm not able to change the language of this error message. But it says something like it can't load (Bad format) sfmlnet-graphics2 or one of it's dependencies.

I'm not used to C# but in c++ you can always open a 32bit application with a 64bit OS.

Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 23, 2013, 02:12:22 pm
Maybe what was wrong was that I used the DLLs in the folder x86 from SFML.NET ... because my system is 32 bit, then in my PC it works
Now, I compiled a new copy of my program, with the DLLs that are in x64 folder ... (Oremos para que funcione en las PCs de 64 bit, en la mia de 32 NO lo hizo, quizas es una buena señal)

So, please, I invite those Ladies and Guys who have a 64 bit system to test my poor "Sonic 64 by Pablito" Version for 64 bit


Then, we just were missing to solve the crash because of OutOfMemoryException,
from what I would appreciate your help,
Thank you
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Superdude on September 23, 2013, 09:06:09 pm
I select my player, then get a purple screen with:

Used memory: xxxxxxxxxxx

Is this an error?
The game does not continue after this.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: AlexAUT on September 23, 2013, 09:38:33 pm
Now the game starts.

Then i select a character (there you shouldn't use sf::Key::isKeyPressed or implement your own system on top of it, because I can't select the hero in the middle) then i get the same screen as Superdude described but my screen is blue  :o

Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 23, 2013, 10:12:48 pm
Same for me, it does actually start up and play now.

I also get the blue Used Memory: xxxxxxx screen (the number's different every time) after character select, but to my surprise it actually gets through that and continues to the level after several seconds.  I played the whole first level plus boss and made it to the second level before writing this post (the Used Memory thing happens again between levels).

A few things had me very very confused for a while, but after a whole level it's clear to me that certain things simply aren't getting drawn.  In particular, some kind of trampoline or jump pad is invisible, and the first boss' attacks are all invisible.  You can imagine how confused I was by these at first.  I would say the movement and jumping physics feel extremely glitchy but I have no idea how much of that is caused by more invisible stuff.

Also, when I press Esc to try and quit, the game crashes.  Windows did not provide any useful error message for this crash.

By the way, I was under the impression that compiling for 32-bit windows made stuff work on both 32-bit and 64-bit systems.  Does anyone know of some strange property of C# or SFML.net that breaks this compatibility?
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Sub on September 24, 2013, 12:19:06 am
The first link you had crashed for me, second link work was slightly better.  I got to the point where you could select a character (which, btw, you need to put that on a delay, you almost instantly skip over the middle character) and then the game goes blue with a memory used message, at which point I alt tabbed and it crashed.  It seems to crash whenever I alt tab, actually.

The music was also way too loud, but maybe that's just me.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 24, 2013, 10:18:48 pm
Hi Ladies and Guys

Now I fixed the Alt + Tab crashing issue, as you told me, I tested it myself;
Also I fixed the Esc pressing (To quit the app) matter, now if you press Esc you return to Start screen, where if you press Esc you exit ... ( It seems to me or we re missing a SFML QuitApplication function? )

Ixrec, you saw the springs (or jumping pads) were invisible? and the flames the first boss throws too? It s very strange that ... on my PC, no object is invisible in my poor game ... Could it be a failure on the image files?

About porting SFML apps from 32 to 64 bit, I found out that what I needed to change was the SFML DLLs, the C# code is the same, actually I compiled the 32 bit version with x86 DLLs, and the 64 bit version with x64 DLLs,

32 bit download


64 bit download


Source Code (fixed) (for both 32 and 64 bit)


Those who want to compile the code, remember to add the SFML.NET DLLs to the References node, on the Solution Explorer, but the x86 if the system is 32 bit, or the x64 if it is 64 bit ... there they are in each game version, in the exe's folder

What I would like is that someone goes along up to the Zone 2 Act 2, beats it (Eggman at the end), and then tells me why, while trying to load Zone 3 Act 1, my hedgehog runs with a OutOfMemoryException ... obviously it is not a lack of memory, because I have 2 GB, ... and the blue screen, I put them to inform about the used memory (on each level, whose sizes are different), without success as seen ... as seen at finishing 2-2

The code about loading levels and that stuff can be found in the LEVEL subfolder from the source code
(I also tried using the GC, but no effect ... it should be a lost reference that remains anywhere, or a failure in the Image class (the Zone image files are quit big, and JPG), or a failure on the image files, ... or I don t know what)

Thank you all

Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 24, 2013, 10:54:39 pm
I don't recall seeing any zone/act names or any method of saving my progress, so assuming I'm not missing something, how long do you think it'd take me to get to Eggman?

Edit: This version locks up for me.  After the used memory screen I get a white screen with blue text that says it failed to load an image (the filename flies off the screen so I have no idea which one) and gives another used memory number.  It never seems to recover from that.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Sub on September 24, 2013, 11:13:48 pm
It's an improvement over the older build, but I'm still having issues.

Sorry man.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 25, 2013, 12:36:05 am
It's OK, come on everybody!  :)
I don't know why, a few files had gone, now I restored them, removed the "memory used" messages, and reuploaded the 3 rar files, that are

Sonic 32 bit Version

Sonic 64 bit Version

Sonic Source Code both 32 and 64 bit

It would take you about 5 or 6 minutes to reach Eggman on the Zone 2 Act 2, ... that is where it launches an OutOfMemoryException, on trying to load Zone 3 Act 1 ... The problem should not be that there's no more memory in my system, I have 2 GB, then I think now it's all fixed excepting that ...  :(

(at act 1 ends, you have a mini boss, at act 2 ends, comes Dr Eggman (Robotnik))
(you hit enemies with Sonic become a spinball, jumping or rolling, if not, or if touch fire or a hog, you are hit)
(to pass over the ramps, do the spindash: hold down Down key, then press Space once and again, to gain impulse, then release both and press forward key(Right or Left, depending))

The issue of the bars in the initial screen, the invisible stuff, etc, I supose they don't have to do with my C# code ... perhaps it's the 64 bit system

Thanks for your patience  :D

PS please don't select Tails the Foxhog, there's another bug by now, she can't run on the ramps nor fly ... I'll fix that  8)
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 25, 2013, 01:23:31 am
Man, so many things to check and report on...

The blue used memory screens are still there.  The loading level screen now has a used memory number on it.
The springs and boss flame are now visible.
Most pieces of scenery have some weird purple stuff around them.
The main menu is sometimes pure white, and sometimes has several flickering black bars over it.  I think this was the case in some but not all of the previous builds, not sure anymore.
Alt+tab does absolutely nothing (this has been the case for me in all builds, it's never crashed it for me).  I have to ctrl+alt+delete in order to escape the game.  Can you please make a windowed version so it's less annoying to test?
Escape seems to sort of work but the main menu remains glitchy and sometimes it doesn't respond and I have to kill the program.
Why is there a console window anyway?  You don't seem to be doing anything with it.

I'll edit this once I get through more levels.  Gonna try to get to Eggman like you asked.

I tried to take screenshots of some of these things but all I get are blank images.

Gotta be honest, this whole thing is giving me an extremely bad impression of C#/.NET/SFML.net.  I've never had to deal with anything resembling a single one of these problems for my C++ SFML program. 
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Sub on September 25, 2013, 01:37:09 am
Another improvement, I was actually able to play it this time  :)

I'd echo everything Ixrec has said, but in addition to that, there was a spot on level 2 where I became stuck.  There was a completely vertical hill that I fell down, so I was caught between a hill that was too tall to get back up on, and one of the loops that you have to run around.  I couldn't gain enough speed to get through the loop.  I would have taken a screenshot, but printscreen doesn't seem to work with the game?
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 25, 2013, 01:57:46 am
That happened to me too.  I tried a lot of things but I'm pretty sure it's just not possible to get through those loops.  Not sure if it was a level design error or a physics error.  I was able to wall climb out of that area (is that ability unique to Knuckles?) so I managed to get farther.

I'm going to have to ignore your zone/area numbers since the game never provides any, but I got through five levels.  Two and four had Eggman fights.  After I finished level five it crashed on the blue screen for me.
I think the terrain for the loops is invisible since it's just a green circle with no grass, some purply stuff and the direction I came out of them (on the levels where they worked) didn't make any sense.
The health system was very confusing, since I've been hit with 0 health without dying (in fact I don't think I ever died) and sometimes failed to lose health even when I had more than 0 health.  Also, during the level 5 double boss battle there was only one health bar, which I'm pretty sure represented my health, one boss' health and the other boss' health at different points in time for no apparent reason.
The physics got significantly worse after level two.  The beginning of level 3 (and I think 5, not sure) had a big lag spike which resulted in me warping around for a few seconds and getting hit by something I couldn't see.  Behavior on curved surfaces and slopes also felt even glitchier than in previous levels, causing so much oscillation I had to do significantly more gliding, jumping and wall jumping than the level intended.
I only recently noticed it always says "Sonic x 3" even when playing as Knuckles.
Some bosses can be jumped on three times for extra damage (which is a good thing) but the third bounce gets you hurt instead of the boss because you fall so far through it before the collision registers (which is clearly a bug).

I'm still hoping a SFML.net expert will show up and explain why your 32-bit build doesn't work on 64-bit machines.  Everything I've ever seen says that's only possible if you (or SFML.net) did something extremely bad.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 25, 2013, 02:11:58 am
Oh wow I'm an idiot.  I completely forgot I managed to get a screenshot of an error in your console window before Windows finished killing your program (this was after the crash between levels 5 and 6).


I should also mention that the used memory number did seem to be constantly rising (would you expect that, or does that imply stuff isn't getting freed?).  Since there's no window mode I couldn't use the task manager to confirm I had memory left, but I usually have a gig or two of RAM free so it should be fine.
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 28, 2013, 01:43:12 am
Hi, Nice Ladies and Guys
Very very sorry for the delay, I just have been working hard to fix the errors and bugs you detected in my poor Sonic ; Actually I thank your critics very much
Here are the fixed versions

Sonic 64 bit Download (Fixed)

Sonic 32 bit Download (Fixed)

Source Code (Fixed)

What I found out, is that the C# Code is the same, but to port my program to a 64 bit system, I just have to compile it with the SFML.NET DLLs that are for 64 bit, those in the x64 subfolder in the SFML.NET pack, then what changes between 32 and 64 bit systems, is the DLLs ; actually I built both a 32 and a 64 bit version of my poor Sonic game

* Now the character name is Ok;
* Now when the Lifebar is 0 you die, when your lives == 0, you are game over
* Now the slopes or gradient terrains effect is correct
* Now the "memory used" messages have gone
* Now the error on Level 6 (Zone 3 Act 2) is fixed, (it was a bad file)
* Now when starting a level, displays a letter "ZONE # ACT #"
* Now you can exit normally with the Esc key

To gain impulse and pass through the loops and curve ramps, you have to do the SPINDASH,
that is this: You croach (hold down Down arrow key) and then you become an electric round saw, or spinball (press once and again the Space bar); then release the bar, then release down key, and then hold down Right or Left key, depending you re going forward or backward
Though I increased the maximum speed of the SPINDASH (rolling forward), it already worked before

* perhaps there are still any bugs, but I m sure now there are less 
* in my system, I run on an OutOfMemoryException when trying to load Zone3Act1 level image, that is thrown by the Image object (maybe I wasn t able to free previous stuff properly?)
* I know very well I have to get better graphics and better level designs
* I forgot to separate the bosses' lifebars from the players' one
* The glitchy movement on the curves

Yes, Knuckes is the only who can glide and wall climb, Tails can fly and attack with her helix (the 2nd not yet implemented), and Sonic can do different movements at jumping if he has a bubble shield

I ask you about how to solve the memory crash, and also, if you see more errors and bugs, it will be apreciated
Meanwhile I ll continue working, but think the memory crash is the most important thing ... I don t know if it could be a bug on my system ...

Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 28, 2013, 02:05:37 am
Looks like everything you said is fixed is indeed fixed.  Here's the stuff that still jumps out to me:

(playing Tails this time)
The purple junk around most of the images is still around.
The main menu isn't solid white now but it's still flickering. It sort of seems intentional but it also hurts my eyes so not sure what to say about that.
   Edit: Okay, this time it wasn't flickering.  No idea what's going on there.
The spindash thing makes sense now.  Before I was just hitting down while running, which made me accelerate and roll.  But standing perfectly still, then hitting space and releasing it does seem to go much faster and get me through those loops.  However, it feels unintuitive and finicky, especially since pressing right or left while holding space prevents the move, but you say I should be using left and right to acclerate after the move starts.
The loops and other curved terrain still feels very glitchy.  I'm still getting the occasional oscillating warps, when doing loops my energy shield (?) sprite disconnects with my character, and I still see no terrain/grass/whatever inside loops.
There should really be a way to make Tails stop hovering.  Sometimes I have to wait forever for her (really? Tails is female?) to fall all the way down.  Actually her movement in general just feels inconsistent and annoying.
I didn't get around to complaining about it before, but the Zone 2 Act 1 boss is the most tedious thing ever.  I don't feel like doing that again right now.

Oh hey screenshots work now.  Here's that purple stuff I was talking about:
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Tigre Pablito on September 28, 2013, 05:18:52 am
Well,  :)
(*) I'll try to reprogram the Zone2Act1 boss, so that it's easier and quicklier to defeat, ... cos I'd like to know why (in my PC at least) my app crashes out of memory(on 3-1), and if this occurs on other PC's  :(

(*) The level images were drawn (or can be redrawn by modifying code) in runtime by the same program, then saved to .bmp files with Image.SaveToFile() function ; I can swith weather it redraws and save the image or if it loads the existing one from the file (the versions I posted load the images from files, that is faster)

as the bmp's where extremely big, I saved them as .jpg files ... I don't know why that purple stuff remained at the ground and trees contour  :o
Is it possible that converting .bmp to .jpg has distorted the image? I used Paint ... I guess you won't agree with that ... well, I'll try some things and as a last resource I'll try using GIMP

Please some advise for fixing the images files?  ;D

(*) About the oscillation, two things:
* - that part of Zone 2 Act 1, which is like a cavity where join 2 curved ramps, if it is the place you mention, the error (or imprecission) there, is that when you walk on the ramp (all the quarter ellipse line), the hero is controlled most by inertia and a preset trajectory than by the user input, ... that is quite sophisticated, but I will try to improve its physic  8)
* - the error (or imprecission) in the level design is that both curved ramps are too close each other

(what you didn't reach to see is the slopes, in 2-2, they are very well now, not glitchy and also the hedgehog inclinates normal to the terrain ... definitively trigonometry, curves, etc, are more tedious than 2-1 boss ... but result is nice  ;)

I'm going to do the list of things that need to be corrected, work on that, try to improve the level design, check out some words' meaning in the online dictionary, and then post again with all bugs(listed up to now) fixed  :P
Title: Re: My Sonic the Hedgehog game (goes fine, but need help)
Post by: Ixrec on September 28, 2013, 05:33:21 am
Regarding images, just use .png.  If you think you need to use a lossy format like .jpg for performance reasons, then you're better off just making a lower-rez image in a non-lossy format like .png so you at least have control over how it looks (instead of letting .jpg compression just add artifacts randomly).  And .png is a better lossless format than .bmp partly because it has an alpha channel/transparency, but also because .png's are compressible (without loss).  The only real disadvantage to .png's is that they take longer to load, but I've yet to see that cause any noticable lag in my program, despite using very high-rez .png's, so I don't think that's much of a problem on modern computers.

For the record, using MS Paint to convert .bmp to .jpg is probably fine.  The problem with MS Paint is that it's incapable of operating on formats like .png that have alpha channels.  The artifacts you're seeing ought to be a result of using the .jpg format and its lossy compression, rather than a massive bug in MS Paint.  And personally, I'd recommend trying Paint.net before GIMP because GIMP is extremely unintuitive, while Paint.net shouldn't even require a tutorial for anyone familiar with regular MS Paint.