<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Bad File Descriptor</title>
		<link>http://www.allegro.cc/forums/view/618741</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 24 Oct 2022 22:54:22 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi all:<br />  I am having problems with textures returning &#39;Bad File Descriptor&#39;.<br />It used to only happen when using Allegro5, but now it happens even<br />using the GLUT library. Does anyone have an answer for this problem?</p><p>Thanks for your time!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Fri, 07 Oct 2022 21:47:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>We can&#39;t guess what you&#39;re doing. Show some code, like where you load your textures, any init code, etc...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 08 Oct 2022 22:11:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Edgar:<br />  Hope all is well.<br />  Please find cube.zip file above.<br />  I sent two different C files.<br />  The one cube.c compiles and displays perfect.<br />  The one cubeX.c compiles and is screwed up.<br />  Both files return &#39;Bad File Descriptor&#39;.<br />  The only difference between the two:<br />  cubeX.c shows the code moved on the right side of the<br />  braces in the drawCube function. Exactly the same files<br />  except for that.</p><p>  These are both done in Ubuntu Linux in Allegro5 using codeblocks compiler.</p><p>  I get the same results using MX Linux 19.4.</p><p>  I quit using Allegro because of this problem, but now it shows the<br />  same problem in GLUT.</p><p>  I checked the Internet and found this problem occurs in many programs.<br />  Seems it is a kernel problem in applying a non negative number to files<br />  being open or corrupt files. I have used these files for many years with<br />  no problems until now.</p><p>  Be interesting to see what you find out. I really need to use Allegro5<br />  for this project.</p><p>  As always, thanks for your time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Sun, 09 Oct 2022 20:55:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Scooter - please explain a little more by what you mean when the files display &quot;Bad File Descriptor&quot;. When does that happen? During compilation? During al_load_bitmap? During display code? You could try saving your files as UTF-8 in code blocks and see if that fixes it. I&#39;m not sure where the error is coming from, as you say your first c file compiles and displays perfectly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 09 Oct 2022 22:01:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Edgar:<br />  Did you compile and run the two C files?<br />  On both files codeblocks returns 0 warnings and 0 errors.<br />  I uploaded an image showing the &#39;Bad file descriptor&#39; message<br />  from codeblocks. Hope this helps.<br />  Have a great day!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Mon, 10 Oct 2022 16:39:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It sort of works on Windows. No mention of any &#39;bad file descriptor&#39; message. After fixing your includes and making it use OpenGL, cube.c displayed perfectly and ran fine. No compilation warnings or errors. cubeX.c (after the same fixes) displayed only 4 of the 6 colors, but otherwise ran fine.</p><p>I haven&#39;t tried it on Linux yet, but I will shortly.</p><p>It should be noted that you&#39;re both leaking memory and have dangling pointers. You overwrite the value of bmp without storing the old value to destroy later. Also, you shouldn&#39;t be calling glDeleteTextures, but rather al_destroy_bitmap. What&#39;s more, you haven&#39;t checked ANY return values to see if anything fails. Start there, save the file as UTF-8 and get back to me.</p><p><b>UPDATE</b><br />I tried it on Linux and it works exactly the same there. No mention of any &#39;bad file descriptor&#39;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 10 Oct 2022 17:56:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Edgar;<br />  I am running thru your last post! Very concerning about dangling pointers.<br />  I declare (4) pointers: display, timer, event_queue and bmp. I set them all.<br />  Where is the memory leak coming from?<br />  Also, you say I did something with a bitmap and did not delete it later.<br />  Please advise me on these items.</p><p>  By the way, what is wrong with this site? I had to post this twice. The<br />  first time it said it could not connect. Just wondering.</p><p>  Anyway, Have a great day.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Tue, 11 Oct 2022 17:08:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This site is old and neglected. Talk to Matthew about it. ;/</p><p>Don&#39;t call glDeleteTextures. Allegro will take care of the textures by itself when the bitmap is destroyed. Allegro also destroys all bitmaps when the last display is destroyed. You can manually de-allocate the bitmaps using al_destroy_bitmap. This is where the memory leak is coming from. I was incorrect about dangling pointers.</p><p>Look at this example :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"green.jpg"</span><span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"blue.jpg"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
The first value stored in the &#39;bmp&#39; variable is overwritten and lost, hence the memory leak. If allegro wasn&#39;t tracking it in the background anyway.</p><p>I think the real problem is that you&#39;re calling glDeleteTextures. It means allegro will also try to destroy the textures when the display is destroyed. This is a double free, and leads to memory corruption.</p><p><b>UPDATE</b><br />In fact, it all makes sense. A GLuint is an unsigned non-negative number and in this case is a texture id. When allegro double destroys the texture, that is probably why it says bad file descriptor.</p><p><b>APPEND</b><br />Scooter, did this solve your problem?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 24 Oct 2022 18:24:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Edgar:<br />  This has been quite a job! My programs are fine as written. I happened to go to<br />Synaptic to download a program and it said I had broken files on the computer. I<br />clicked on &#39;Fix broken files&#39; and nothing happened. So I stripped the computer and<br />loaded everything back on and things seem to be fine now. I brought out some older<br />computers and ran the files on them and all is well. This computer that gave me problems is fairly new to me. I started using it because it is much faster than the<br />one I was using. It came loaded with Windows 11, so I thought I was moving up, but<br />apparently that was NOT the case! I agree my programming needs much work but I think<br />it is still fun to try. Thanks for your help on this problem.</p><p>Have a great day!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Mon, 24 Oct 2022 22:54:22 +0000</pubDate>
	</item>
</rss>
