[過去ログ] SDLスレ (987レス)
前次1-
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
755: 名前は開発中のものです。 [] 05/02/19 17:54:05 ID:vHiopGBS(1/5) AAS
どうしてもわからないので教えてください。
SDL_CreateRGBSurfaceFrom ないしは、 SDL_CreateRGBSurface を
使用しようと、してるのですがなぜか
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
といわれてしまいます。
少々ながいのですが、sample 乗せますので、どこがわるいのか
識者のかた、見ていただけないでしょうか?
------- cut here ----------------------------------------
#include <SDL.h>
#include <stdlib.h>
#include <string.h>
#define XXX (60)
int main( void )
{
int j;
Uint16 **data;
Uint32 rmask = 0x0000001f;
Uint32 gmask = 0x000007E0;
Uint32 bmask = 0x0000F800;
Uint32 amask = 0x00000000;
SDL_Surface * screen;

if ( 0 < SDL_Init( SDL_INIT_VIDEO|SDL_INIT_TIMER ) ) {
fprintf( stderr, "Colud not initialize: %s\n", SDL_GetError() );
exit(3);
}
atexit( SDL_Quit );
if ( NULL == SDL_SetVideoMode( 800, 600, 16, SDL_ANYFORMAT ) ) {
fprintf( stderr, "Could not set video mode... :%s\n", SDL_GetError() );
exit(4);
}
data = (Uint16 **)malloc(sizeof(Uint16) * XXX);
756: 名前は開発中のものです。 [sage] 05/02/19 17:56:23 ID:vHiopGBS(2/5) AAS
if ( NULL == data )
exit(10);
for (j = 0; j < XXX; ++j) {
data[ j ] = (Uint16 *)malloc(sizeof(Uint16) * 80 * 80 );
if ( NULL == data[ j ] )
exit(10);
memset( data[ j ], 0xff, sizeof(Uint16) * 80 * 80 );
}
screen = SDL_GetVideoSurface();
for ( j = 0; j < XXX; ++j ) {
int z;
SDL_Rect r = { 0, 0, 0, 0 };
printf("sprite index[%d] ...\n", j );
// SDL_Surface * surface = SDL_CreateRGBSurfaceFrom(data[ j ], 80, 80, 16, 80 * sizeof(Uint16),
// rmask, gmask, bmask, amask);
SDL_Surface * surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
80, 80, 16, rmask, gmask, bmask, amask);

if ( SDL_MUSTLOCK( surface ) ) {
if ( 0 < SDL_LockSurface( surface ) ) {
fprintf( stderr, "Could not lock surface.: %s\n", SDL_GetError() );
return 0 ;
}
}
for ( z = 0; z < 80 * 80; ++z)
((Uint16*)(surface->pixels))[ z ] = data[ j ][ z ];
if ( SDL_MUSTLOCK( surface ) ) {
SDL_UnlockSurface( surface );
}
757: 名前は開発中のものです。 [sage] 05/02/19 17:56:54 ID:vHiopGBS(3/5) AAS
SDL_FillRect( screen, NULL, SDL_MapRGB( surface->format, 0x00, 0x00, 0x00) );
if ( NULL == surface ) {
fprintf( stderr, "Could not make surface...:%s\n", SDL_GetError() );
exit(1);
}
if ( j >= 10 ) {
int xx = j % 10;
int yy = j / 10;
r.x = xx * 80;
r.y = yy * 80;
} else {
r.x = j * 80;
r.y = 0;
}
SDL_BlitSurface( surface, NULL, screen, &r );
SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
SDL_Delay( 100 );
SDL_FreeSurface( surface );
}
return 0;
}
758
(1): 名前は開発中のものです。 [sage] 05/02/19 18:07:41 ID:vHiopGBS(4/5) AAS
XXX の値は小さければ 10 以下であれば、問題ないようでした。
環境は、FreeBSD 5.3 STABLE です。
SDL は ports からインストールしました。
バックトレースは以下のようなものでした。

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1 (LWP 100099)]
0x08048b93 in main () at test.c:50
50 ((Uint16*)(surface->pixels))[ z ] = data[ j ][ z ];
上の SDL_CreateRGBSurfaceFrom を使用すると、
今度は、blit 中に落ちてしまいます。
回避方法がわからないので、メモリ中のイメージを 60 個程度q
surface にするにはどうすればいいのでしょうか?
760: 名前は開発中のものです。 [sage] 05/02/19 18:27:19 ID:vHiopGBS(5/5) AAS
>>759
759(1): 名前は開発中のものです。 [sage] 05/02/19 18:17:41 ID:La4+fv3Q(1) AAS
>>758
とりあえず
- data = (Uint16 **)malloc(sizeof(Uint16) * XXX);
+ data = (Uint16 **)malloc(sizeof(Uint16*) * XXX);
他にも何かあるかもしらんが、調べてない。

どうでもいいが、何でループ変数がいきなりjとかzなのか理解に苦しむな。
ビンゴです。ほんとにありがとうございました。
SDL スレ汚してごめんなさい。

>>どうでもいいが、何でループ変数がいきなりjとかzなのか理解に苦しむな。
精進します。。。
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.030s