<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Bitmap usage with memset and memcpy</title>
		<link>http://www.allegro.cc/forums/view/618812</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 20 Apr 2023 19:00:41 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi!</p><p>I want to combine Allegro with CEF, I almost got it working but I seem to be unable to write to bitmaps in the way I expect it to work according to the docs.</p><p>I need the memory to be in CPU space since CEF and Allegro both need to access it; I also know that i can only use the drawing functions for it from the opengl thread that created the display, which won&#39;t gel well with CEFs drawing system.</p><p>So, that said, why does this not work:
</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">auto</span>   m_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>width, height<span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span>  
<span class="number">  4</span>
<span class="number">  5</span> <span class="k1">auto</span>   m_osr_buffer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span>BASE_WIDTH, BASE_HEIGHT<span class="k2">)</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_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_MEMORY_BITMAP<span class="k2">)</span><span class="k2">;</span> <span class="c">// use memory bitmap for OSR buffer</span>
<span class="number">  8</span>
<span class="number">  9</span>        <span class="c">// clear entire bitmap to white</span>
<span class="number"> 10</span>        <span class="k1">auto</span> locked_region <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a><span class="k2">(</span>m_osr_buffer, ALLEGRO_PIXEL_FORMAT_RGBA_8888, ALLEGRO_LOCK_WRITEONLY<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_569.html" target="_blank">memset</a><span class="k2">(</span>locked_region-&gt;data, <span class="n">0</span>, width <span class="k3">*</span> height <span class="k3">*</span> locked_region-&gt;pixel_size<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>        <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span>m_osr_buffer<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

Code above doesn&#39;t even have anything to do with CEF or smth, its just the main thread creating a display and trying to manipulate the data directly. as far as i can tell the locking is done correctly and the range is also correct. But i get a segfault on the memset... is there an init period for the buffer ? The memory pointer looks valid to me though.<br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Sidenote here: CEF uses a weird pixel format <br /><a href="https://magpcss.org/ceforum/apidocs/projects/(default)/CefRenderHandler.html#OnPaint">https://magpcss.org/ceforum/apidocs/projects/(default)/CefRenderHandler.html#OnPaint</a><br />BGRA <br />Can i create a custom pixel format or do i need to handle this manually ? (this is not so important as the above crash)</p><p>EDIT:<br />I can&#39;t figure out how to post a reply;<br />My problem: I set the new flags after creating the bitmapo <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ZweiEuro)</author>
		<pubDate>Thu, 20 Apr 2023 14:31:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ZweiEuro, welcome.</p><p>Locked bitmaps may have a negative pitch, which means subsequent rows come before not after the previous. You have to memset each line of the bitmap to be sure.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 20 Apr 2023 19:00:41 +0000</pubDate>
	</item>
</rss>
