Compare commits
3
Commits
5e4dda2a77
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a143cbe90a | ||
|
|
c767d363de | ||
|
|
207d8c2078 |
No files matched your search
@@ -3648,6 +3648,8 @@ static void project_set_dir(const char* path) {
|
|||||||
if (!path || !path[0] || strlen(path) >= sizeof(buf)) return;
|
if (!path || !path[0] || strlen(path) >= sizeof(buf)) return;
|
||||||
strcpy(buf, path);
|
strcpy(buf, path);
|
||||||
char* slash = strrchr(buf, '/');
|
char* slash = strrchr(buf, '/');
|
||||||
|
char* bslash = strrchr(buf, '\\'); /* Windows usa \ */
|
||||||
|
if (bslash && (!slash || bslash > slash)) slash = bslash;
|
||||||
if (!slash) return;
|
if (!slash) return;
|
||||||
*slash = '\0';
|
*slash = '\0';
|
||||||
if (buf[0]) tb_path_set_base(buf);
|
if (buf[0]) tb_path_set_base(buf);
|
||||||
|
|||||||
@@ -711,8 +711,22 @@ static void be_shutdown(void) {
|
|||||||
s_be_inited = false;
|
s_be_inited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Encolhe a janela para caber na tela (deixa espaco para a barra de titulo e
|
||||||
|
as bordas), senao numa tela pequena (ex.: 1024x768) a janela de 1280x800
|
||||||
|
sai com a barra de titulo fora do visivel e nao da para clicar nos botoes. */
|
||||||
|
static void clamp_to_display(int* w, int* h) {
|
||||||
|
SDL_DisplayMode dm;
|
||||||
|
if (SDL_GetDesktopDisplayMode(0, &dm) != 0 || dm.w <= 0 || dm.h <= 0) return;
|
||||||
|
int maxw = dm.w - 16, maxh = dm.h - 64;
|
||||||
|
if (*w > maxw) *w = maxw;
|
||||||
|
if (*h > maxh) *h = maxh;
|
||||||
|
if (*w < 320) *w = 320;
|
||||||
|
if (*h < 240) *h = 240;
|
||||||
|
}
|
||||||
|
|
||||||
static void* be_window_open(const char* title, int w, int h) {
|
static void* be_window_open(const char* title, int w, int h) {
|
||||||
if (!be_init()) return NULL;
|
if (!be_init()) return NULL;
|
||||||
|
clamp_to_display(&w, &h);
|
||||||
SdlWin* sw = (SdlWin*)calloc(1, sizeof(SdlWin));
|
SdlWin* sw = (SdlWin*)calloc(1, sizeof(SdlWin));
|
||||||
if (!sw) return NULL;
|
if (!sw) return NULL;
|
||||||
sw->win = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
sw->win = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
@@ -1140,6 +1154,7 @@ static void eval_sdl2_app(TinyBlocks_Block* self, TinyBlocks* rt) {
|
|||||||
? vtitle.as.text : "TinyBlocks";
|
? vtitle.as.text : "TinyBlocks";
|
||||||
int win_w = (int)(vw.kind == TB_VALUE_INTEGER ? vw.as.integer : 1280);
|
int win_w = (int)(vw.kind == TB_VALUE_INTEGER ? vw.as.integer : 1280);
|
||||||
int win_h = (int)(vh.kind == TB_VALUE_INTEGER ? vh.as.integer : 720);
|
int win_h = (int)(vh.kind == TB_VALUE_INTEGER ? vh.as.integer : 720);
|
||||||
|
clamp_to_display(&win_w, &win_h);
|
||||||
|
|
||||||
TinyBlocks_Block* scene = (vscene.kind == TB_VALUE_BLOCK) ? vscene.as.block : NULL;
|
TinyBlocks_Block* scene = (vscene.kind == TB_VALUE_BLOCK) ? vscene.as.block : NULL;
|
||||||
TinyBlocks_Block* ev_blk = (vevents.kind == TB_VALUE_BLOCK) ? vevents.as.block : NULL;
|
TinyBlocks_Block* ev_blk = (vevents.kind == TB_VALUE_BLOCK) ? vevents.as.block : NULL;
|
||||||
|
|||||||
@@ -66,7 +66,16 @@ static StageCmd* push(StageCmdKind kind) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void stage_release_images(void) {
|
||||||
|
for (int i = 0; i < s_stage.n; i++)
|
||||||
|
if (s_stage.cmds[i].kind == SC_IMAGE && s_stage.cmds[i].img) {
|
||||||
|
tb_image_release((TinyBlocks_Image*)s_stage.cmds[i].img);
|
||||||
|
s_stage.cmds[i].img = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tb_stage_clear(void) {
|
void tb_stage_clear(void) {
|
||||||
|
stage_release_images();
|
||||||
s_stage.n = 0;
|
s_stage.n = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +121,10 @@ bool tb_stage_image_zoom(const TinyBlocks_Image* img, float x, float y, float zo
|
|||||||
c->a = x; c->b = y;
|
c->a = x; c->b = y;
|
||||||
c->d = zoom > 0.f ? zoom : 1.f;
|
c->d = zoom > 0.f ? zoom : 1.f;
|
||||||
c->img = img;
|
c->img = img;
|
||||||
|
/* O palco guarda a imagem: o bloco que a produziu pode ser destruido
|
||||||
|
(parar/limpar) antes do proximo desenho, e a lista retida continua
|
||||||
|
apontando para ela. Sem isto era uso-apos-liberacao (crash no Windows). */
|
||||||
|
tb_image_retain((TinyBlocks_Image*)img);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +155,7 @@ bool tb_stage_view_to_stage(float vx, float vy, float* sx, float* sy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tb_stage_reset(void) {
|
void tb_stage_reset(void) {
|
||||||
|
stage_release_images();
|
||||||
free(s_stage.cmds);
|
free(s_stage.cmds);
|
||||||
s_stage.cmds = NULL; s_stage.n = 0; s_stage.cap = 0;
|
s_stage.cmds = NULL; s_stage.n = 0; s_stage.cap = 0;
|
||||||
s_stage.bg[0] = s_stage.bg[1] = s_stage.bg[2] = 1.f;
|
s_stage.bg[0] = s_stage.bg[1] = s_stage.bg[2] = 1.f;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <tb_imglib.h>
|
#include <tb_imglib.h>
|
||||||
#include <tb_ppm.h>
|
#include <tb_ppm.h>
|
||||||
#include <tb_bmp.h>
|
#include <tb_bmp.h>
|
||||||
|
#include <tinyblocks/tb_stage.h>
|
||||||
|
|
||||||
static int fails = 0;
|
static int fails = 0;
|
||||||
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
|
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
|
||||||
@@ -139,6 +140,21 @@ int main(void) {
|
|||||||
tinyblocks_deinit(&rt2);
|
tinyblocks_deinit(&rt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -- Palco retem a imagem (regressao: uso-apos-liberacao ao parar) ---
|
||||||
|
* O bloco que produz a imagem (ex.: "3D.Image") e destruido no "parar",
|
||||||
|
* mas a lista retida do palco continua apontando para ela. Sem o retain
|
||||||
|
* no palco, isto era um use-after-free (crash no Windows). */
|
||||||
|
{
|
||||||
|
TinyBlocks_Image* si = tb_image_new(4, 4, 4);
|
||||||
|
tb_imglib_fill(si, 1, 2, 3, 255);
|
||||||
|
CHECK(tb_stage_image(si, 0.f, 0.f), "palco aceita a imagem");
|
||||||
|
tb_image_release(si); /* agora so o palco segura */
|
||||||
|
const uint8_t* px = tb_image_data_const(si);
|
||||||
|
CHECK(px && px[20] == 1 && px[21] == 2 && px[22] == 3,
|
||||||
|
"imagem segue valida depois que o palco a retem");
|
||||||
|
tb_stage_clear(); /* o palco solta a referencia */
|
||||||
|
}
|
||||||
|
|
||||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||||
else printf("\nTUDO OK\n");
|
else printf("\nTUDO OK\n");
|
||||||
return fails != 0;
|
return fails != 0;
|
||||||
|
|||||||
Reference in new issue
Block a user