<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>SIGSEGV when attaching shaders</title>
		<link>http://www.allegro.cc/forums/view/614442</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 09 Jul 2014 22:46:05 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello everyone. I&#39;ve recently started using Allegro, and was initially started out with Allegro 5.0.10. However, I needed shaders for my game, so I decided to port over to 5.1.8. I downloaded the windows binaries that someone in this forum had made for the same, and somewhat clumsily replaced the old header and lib files, although I&#39;m not entirely sure I did it the right way. One way or the other I got the library working and functions like al_get_shader_source that were earlier not working now worked. However, now I&#39;ve run into a strange problem.
</p><div class="source-code snippet"><div class="inner"><pre>    ALLEGRO_SHADER<span class="k3">*</span> shader <span class="k3">=</span> al_create_shader<span class="k2">(</span>ALLEGRO_SHADER_GLSL<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">if</span><span class="k2">(</span>shader <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
    <span class="k2">{</span>
        MessageBox<span class="k2">(</span>NULL, <span class="s">"Could not create shader!"</span>, <span class="s">"Error!"</span>, MB_OK <span class="k3">|</span> MB_ICONERROR<span class="k2">)</span><span class="k2">;</span>
        <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
    <span class="k2">}</span>
    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_attach_shader_source<span class="k2">(</span>shader, ALLEGRO_VERTEX_SHADER, <span class="s">"Assets\\shaders\\tempVert.vert"</span><span class="k2">)</span><span class="k2">)</span>
        std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> al_get_shader_log<span class="k2">(</span>shader<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
When I try attaching a shader, the program gives me a SIGSEGV (segmentation fault). Not sure where I&#39;m wrong, so any help would be appreciated.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Wed, 09 Jul 2014 12:09:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code">al_attach_shader_source</span> expects the source code for the shader, not a path to the shader.<br />The function you were thinking of is <span class="source-code">al_attach_shader_source_file</span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Wed, 09 Jul 2014 12:53:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh sorry, I got my source messed up.</p><p>Actually, I&#39;ve tried al_attach_shader_source_file, as well as later changed it to al_attach_shader_source while providing the shader code in the program itself, but it crashed either way. So I undo-ed the change, but I guess I didn&#39;t undo it completely. So I&#39;m pretty sure the problem is not with not being able to find the file or incorrect shader code - one way or the other, that would generate an error log, not crash my program with segsev.</p><p>EDIT : Could not linking to the correct libs (or linking only to some, and not all libs) result in this kind of a thing? I ask coz when I ported from 5.0.10 to 5.1.8, I didn&#39;t exactly link to all the lib files - I only linked to those that were present in 5.0.10. Is it possible that the 2 or 3 files that I failed to link to are causing this problem?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Wed, 09 Jul 2014 13:19:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you sure the crash is in al_attach_shader_source and not later on as a result of it failing when something expected it to have succeeded is called?<br />Either way it is a good idea to use a debugger to catch the exception, preferably when linking against a version of allegro with debug symbols so you can see exactly what goes wrong.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614442/1002920#target">brisingr123</a> said:</div><div class="quote"><p>Is it possible that the 2 or 3 files that I failed to link to are causing this problem?</p></div></div><p>
Not linking to something that is required will cause a linking error, not a runtime error, however if you linked against one library but another got loaded in its place (because they share the same name and one being in a place that puts it in a higher precedence than the other) it could cause all sorts of havoc. Also, if you linked against libraries of both 5.0.10 and 5.1.8 at the same time I don&#39;t know what would happen. Are you linking statically or dynamically?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Wed, 09 Jul 2014 15:19:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yup, pretty sure the crash is in attach_shader, since I set a breakpoint at that particular line, the program ran fine till then, but if I pressed &quot;next line&quot; it never went ahead, just gave a sigsev and crashed.</p><p>And well, I didn&#39;t make the libs myself (as I said, downloaded them from this forum) so not sure if they are debug, but they work well enough. I replaced all the old 5.0.10 libs with the new 5.1.8 ones, so I&#39;m only linking to one of them (new one).</p><p>And lastly, static linking it is.</p><p>EDIT : <a href="https://www.allegro.cc/forums/thread/613773/995477#target">https://www.allegro.cc/forums/thread/613773/995477#target</a><br />This was from where I downloaded the binaries. I replaced the old includes, and replaced the old allegro libs with the ones given here (for instance, replaced liballegro_acodec-5.0.10-static-mt.a with liballegro_acodec-static.a . However, liballegro_main-static.a, liballegro_video-static.a and libtheora.a have not been linked, since they were not present in 5.0.10, and I wasn&#39;t sure of the order of linking these libs.</p><p>EDIT 2 : Okay, so I cleaned the entire allegro installation and placed the files again, linked to ALL the files, but still the same problem. The program directly crashed with a sigsev - I can&#39;t even use al_get_shader_log() to get the error. Maybe I&#39;m doing something wrong in my code... care to take a look?
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  2</span>    <span class="k2">{</span>
<span class="number">  3</span>        MessageBox<span class="k2">(</span>NULL, <span class="s">"Could not initialize Allegro!"</span>, <span class="s">"Error!"</span>, MB_OK <span class="k3">|</span> MB_ICONERROR<span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>        <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number">  5</span>    <span class="k2">}</span>
<span class="number">  6</span>
<span class="number">  7</span>    <a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span><span class="k2">(</span>IS_FULLSCREEN? ALLEGRO_FULLSCREEN: ALLEGRO_WINDOWED<span class="k2">)</span> <span class="k3">|</span> ALLEGRO_OPENGL_3_0<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/al_set_new_window_position"><span class="a">al_set_new_window_position</span></a><span class="k2">(</span><span class="n">683</span> <span class="k3">-</span> SCREEN_WIDTH<span class="k3">/</span><span class="n">2</span>, <span class="n">384</span> <span class="k3">-</span> SCREEN_HEIGHT<span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>    GAME_DISPLAY <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span>SCREEN_WIDTH, SCREEN_HEIGHT<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>    <span class="k1">if</span><span class="k2">(</span>GAME_DISPLAY <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 12</span>    <span class="k2">{</span>
<span class="number"> 13</span>        MessageBox<span class="k2">(</span>NULL, <span class="s">"Could not create screen for display!"</span>, <span class="s">"Error!"</span>, MB_OK <span class="k3">|</span> MB_ICONERROR<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>        <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 15</span>    <span class="k2">}</span>
<span class="number"> 16</span>
<span class="number"> 17</span>    <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>    <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>    <a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>    <a href="http://www.allegro.cc/manual/al_install_mouse"><span class="a">al_install_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> icon <span class="k3">=</span> NAMESPACE::LoadImageFromFile<span class="k2">(</span><span class="s">"Assets\\icon.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>    <a href="http://www.allegro.cc/manual/al_set_display_icon"><span class="a">al_set_display_icon</span></a><span class="k2">(</span>GAME_DISPLAY, icon<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>    <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>icon<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>
<span class="number"> 27</span>    NAMESPACE::ShowLoadingScreen<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>
<span class="number"> 29</span>    LoadAssets<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>    
<span class="number"> 31</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_739.html" target="_blank">srand</a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>    ALLEGRO_SHADER<span class="k3">*</span> shader <span class="k3">=</span> al_create_shader<span class="k2">(</span>ALLEGRO_SHADER_GLSL<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>    <span class="k1">if</span><span class="k2">(</span>shader <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 35</span>    <span class="k2">{</span>
<span class="number"> 36</span>        MessageBox<span class="k2">(</span>NULL, <span class="s">"Could not create shaders!"</span>, <span class="s">"Error!"</span>, MB_OK <span class="k3">|</span> MB_ICONERROR<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>        <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 38</span>    <span class="k2">}</span>
<span class="number"> 39</span>    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_attach_shader_source_file<span class="k2">(</span>shader, ALLEGRO_VERTEX_SHADER, <span class="s">"Assets\\shaders\\tempVert.vert"</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 40</span>        std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> al_get_shader_log<span class="k2">(</span>shader<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 41</span>    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_attach_shader_source_file<span class="k2">(</span>shader, ALLEGRO_PIXEL_SHADER, <span class="s">"Assets\\shaders\\tempFrag.frag"</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 42</span>        std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> al_get_shader_log<span class="k2">(</span>shader<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 43</span>    al_build_shader<span class="k2">(</span>shader<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 44</span>    al_use_shader<span class="k2">(</span>shader<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Wed, 09 Jul 2014 15:56:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure if that&#39;s the issue, but the <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a></span><span class="ref"><sup>[<a href="#">1</a>]</sup></span> documentation states you need to set ALLEGRO_PROGRAMMABLE_PIPELINE if you want to use ALLEGRO_SHADER objects, so that may be it.
</p><div class="ref-block"><h2>References</h2><ol><li>note that clicking that link will bring you to 5.0 documentation and not 5.1, you should look at <span class="ref"><sup>[<a href="#">2</a>]</sup></span> for that.</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Wed, 09 Jul 2014 16:47:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I did try the ALLEGRO_PROGRAMMABLE_PIPELINE flag initially, but the &quot;al_set_display_icon(GAME_DISPLAY, icon);&quot; line throws a SIGSEV in that case, and I don&#39;t even reach the shader part.</p><p>EDIT : Okay, to test the theory I moved the shader code between the icon part and the create display part. Still the error.</p><p>EDIT 2 : Okay, so I tried an allegro example (ex_shader.cpp), and was surprised to find that al_create_shader(ALLEGRO_SHADER_AUTO) gives me a ALLEGRO_SHADER_HLSL shader instead of ALLEGRO_SHADER_GLSL, and replacing ALLEGRO_SHADER_AUTO with ALLEGRO_SHADER_GLSL actually causes the program to crash. Why this surprises me is because I have set the ALLEGRO_OPENGL_3_0 flag. So, is there any way to force the creation of OpenGL display (I really don&#39;t want to be creating 2 shaders - one glsl, and one hlsl), and also, what&#39;s the method to check if my display is opengl or directX based?</p><p>EDIT 3 : Holy <span class="cuss"><span><span class="cuss"><span>shit</span></span></span></span>, I just figured out the problem - ALLEGRO_OPENGL_3_0 flag is <span class="cuss"><span><span class="cuss"><span>shit</span></span></span></span>! ALLEGRO_OPENGL works like a charm, and I get no more errors.</p><p>Not sure why that is, but either way, I&#39;m good to go for now <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Wed, 09 Jul 2014 17:40:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s really confusing, but ALLEGRO_OPENGL_3_0 doesn&#39;t give you opengl. You still have to combine it with ALLEGRO_OPENGL. IMO, it should be included with ALLEGRO_OPENGL_3_0 automatically.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 09 Jul 2014 22:46:05 +0000</pubDate>
	</item>
</rss>
