Web target builds, but fails on arena issue. Web debugging is broken

main
Cameron Murphy Reikes 9 months ago
parent 4584b5a1ee
commit 2c718d4de1

@ -15,3 +15,25 @@ You must clone with git lfs is, and download git lfs files in this repository. I
Open `art.blend`, go to the scripting tab and hit the play button run the script and export all the 3d assets. Then, make sure that when you build, you also build and run the codegen so that said assets and other files are copied and imported. For debug builds on windows, that's `call build_desktop_debug.bat codegen`, the codegen argument to the build script causing it to run codegen
To enable codegen error messages, change @echo off to @echo on in run_codegen.bat
# Debugging in the web
To get this working, you're going to need to follow flooh's answer linked [here](https://groups.google.com/g/emscripten-discuss/c/DEmpyGoq6kE/m/Bx44ZmfmAAAJ), and copy pasted for redundancy here:
```
It should definitely work on Vanilla Chrome, but setting everything up can be a bit finicky:
- install the Debugging extension: https://chrome.google.com/webstore/detail/cc%20%20-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb
- in the Dev Tools settings, search for 'WebAssembly Debugging' and check that box
- compile your code with '-O0 -g' (no optimization, and debug info enabled'
- IMPORTANT: in the Chrome debugger, there's a 'Filesystem' tab on the left side which is very easy to miss. Here you need to navigate to your project directory and allow Chrome to access that area of your filesystem.
(I think/hope these are all steps)
When you load your application you should see something like this on the Dev Tools console:
[C/C++ DevTools Support (DWARF)] Loading debug symbols for http://localhost:8080/cube-sapp.wasm...
[C/C++ DevTools Support (DWARF)] Loaded debug symbols for http://localhost:8080/cube-sapp.wasm, found 91 source file(s)
...and if everything works it should look roughly like this in the debugger:
```

@ -1,7 +1,7 @@
call run_codegen.bat || goto :error
copy marketing_page\favicon.ico %OUTPUT_FOLDER%\favicon.ico
copy main.c %OUTPUT_FOLDER%\main.c || goto :error
@REM copy main.c %OUTPUT_FOLDER%\main.c || goto :error
@echo on
emcc ^

@ -4,7 +4,7 @@ rmdir /S /q build_web
mkdir build_web
@REM set FLAGS=-fsanitize=undefined -fsanitize=address
set FLAGS=-O0 --source-map-base http://localhost:8000/ -g3 -gdwarf -DDEVTOOLS
set FLAGS=-O0 -g -DDEVTOOLS
set OUTPUT_FOLDER=build_web

@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdbool.h>
#define DESKTOP
#include "better_assert.h"
#include "utility.h"
#include "buff.h"
@ -23,8 +23,6 @@
#pragma warning(pop)
#define Log(...) { printf("Codegen: "); printf(__VA_ARGS__); }
void dump(MD_Node* from) {
printf("/ %.*s\n", MD_S8VArg(from->string));
int d = 0;

@ -28,6 +28,8 @@
#define SOKOL_GLES2
#endif
#include "utility.h"
#ifdef WINDOWS
@ -132,7 +134,14 @@ void *web_arena_push(WebArena *arena, size_t amount)
}
void *to_return = arena->data + arena->pos;
arena->pos += amount;
assert(arena->pos < arena->cap);
bool arena_ok = arena->pos < arena->cap;
if(!arena_ok)
{
Log("Arena size: %lu\n", arena->cap);
Log("Arena pos: %lu\n", arena->pos);
}
assert(arena_ok);
return to_return;
}
@ -5588,13 +5597,14 @@ void frame(void)
// draw the 3d render
draw_quad((DrawParams){quad_at(V2(0.0, screen_size().y), screen_size()), IMG(state.threedee_pass_image), WHITE, .layer = LAYER_WORLD, .custom_pipeline = state.twodee_colorcorrect_pip });
draw_quad((DrawParams){quad_at(V2(0.0, screen_size().y), screen_size()), IMG(state.outline_pass_image), WHITE, .layer = LAYER_UI_FG, .custom_pipeline = state.twodee_outline_pip, .layer = LAYER_UI});
draw_quad((DrawParams){quad_at(V2(0.0, screen_size().y), screen_size()), IMG(state.outline_pass_image), WHITE, .custom_pipeline = state.twodee_outline_pip, .layer = LAYER_UI});
// 2d drawing TODO move this to when the drawing is flushed.
sg_begin_default_pass(&state.clear_depth_buffer_pass_action, sapp_width(), sapp_height());
sg_apply_pipeline(state.twodee_pip);
// @Place(text input drawing)
#ifdef DESKTOP
draw_quad((DrawParams){quad_at(V2(0,screen_size().y), screen_size()), IMG(image_white_square), blendalpha(BLACK, text_input_fade*0.3f), .layer = LAYER_UI_FG});
Vec2 edge_of_text = MulV2F(screen_size(), 0.5f);
if(text_input_buffer_length > 0)
@ -5604,6 +5614,7 @@ void frame(void)
}
Vec2 cursor_center = V2(edge_of_text.x,screen_size().y/2.0f);
draw_quad((DrawParams){quad_centered(cursor_center, V2(3.0f, 80.0f)), IMG(image_white_square), blendalpha(WHITE, text_input_fade * (sinf((float)elapsed_time*8.0f)/2.0f + 0.5f)), .layer = LAYER_UI_FG});
#endif
// Draw Tilemap draw tilemap tilemap drawing
#if 0
@ -6407,6 +6418,7 @@ ISANERROR("Don't know how to do this stuff on this platform.")
it->generation = gen;
}
}
ENTITIES_ITER(gs.entities)
{
if (it->perceptions_dirty && !npc_does_dialog(it))
@ -6445,7 +6457,6 @@ ISANERROR("Don't know how to do this stuff on this platform.")
#endif
#ifdef DESKTOP
// desktop http request, no more mocking
MD_ArenaTemp scratch = MD_GetScratch(0, 0);
MD_String8 ai_response = {0};
@ -6475,63 +6486,43 @@ ISANERROR("Don't know how to do this stuff on this platform.")
char *target = characters[it->memories_last->context.author_npc_kind].name;
target = characters[NPC_Player].name;
ai_response = FmtWithLint(frame_arena, "{\"target\": \"%s\", \"action\": \"%s\", \"action_argument\": \"The Player\", \"speech\": \"%s\"}", target, action, next_dialog);
#ifdef DESKTOP
it->times_talked_to += 1;
#endif
}
else
{
ai_response = MD_S8Lit("{\"target\": \"nobody\", \"action\": \"none\", \"speech\": \"\"}");
}
}
else
{
MD_String8 post_request_body = FmtWithLint(scratch.arena, "|%.*s", MD_S8VArg(prompt_str));
it->gen_request_id = make_generation_request(post_request_body);
}
// something to mock
if (ai_response.size > 0)
{
Log("Mocking...\n");
Action a = {0};
MD_String8 error_message = MD_S8Lit("Something really bad happened bro. File " STRINGIZE(__FILE__) " Line " STRINGIZE(__LINE__));
if (succeeded)
// something to mock
if (ai_response.size > 0)
{
error_message = parse_chatgpt_response(scratch.arena, it, ai_response, &a);
}
Log("Mocking...\n");
Action a = {0};
MD_String8 error_message = MD_S8Lit("Something really bad happened bro. File " STRINGIZE(__FILE__) " Line " STRINGIZE(__LINE__));
if (succeeded)
{
error_message = parse_chatgpt_response(scratch.arena, it, ai_response, &a);
}
if (mocking_the_ai_response)
{
assert(succeeded);
assert(error_message.size == 0);
assert(succeeded);
assert(error_message.size == 0);
MD_String8 valid_str = is_action_valid(frame_arena, it, a);
assert(valid_str.size == 0);
perform_action(&gs, it, a);
MD_String8 valid_str = is_action_valid(frame_arena, it, a);
assert(valid_str.size == 0);
perform_action(&gs, it, a);
}
}
else
{
if(succeeded)
{
if (error_message.size == 0)
{
perform_action(&gs, it, a);
}
else
{
Log("There was an error with the AI: %.*s", MD_S8VArg(error_message));
append_to_errors(it, error_message);
}
}
MD_String8 post_request_body = FmtWithLint(scratch.arena, "|%.*s", MD_S8VArg(prompt_str));
it->gen_request_id = make_generation_request(post_request_body);
}
}
MD_ReleaseScratch(scratch);
#undef SAY
#endif }
}
#endif // desktop endif
}
}
else
{

@ -2,7 +2,7 @@
#include "buff.h"
#include "HandmadeMath.h" // vector types in entity struct definition
#include "better_assert.h"
#include "utility.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h> // atoi
@ -13,9 +13,6 @@
#define DO_CHATGPT_PARSING
#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }
// Never expected such a stupid stuff from such a great director. If there is 0 stari can give that or -200 to this movie. Its worst to see and unnecessary loss of money
#define PushWithLint(arena, list, ...) { MD_S8ListPushFmt(arena, list, __VA_ARGS__); if(false) printf( __VA_ARGS__); }

@ -0,0 +1,12 @@
#include <stdlib.h>
void assert_less(int x, int y) {
if (x >= y) {
abort();
}
}
int main() {
assert_less(10, 20);
assert_less(30, 20);
}

@ -49,7 +49,7 @@
#define MAXIMUM_THREEDEE_THINGS 1024
#define ANIMATION_BLEND_TIME 0.15f
#define REMEMBERED_MEMORIES 32
#define REMEMBERED_MEMORIES 64
#define REMEMBERED_ERRORS 6
#define MAX_AFTERIMAGES 6

@ -1,16 +1,21 @@
#pragma once
#include <stdio.h>
#include <stdbool.h>
#ifdef WEB
#include <assert.h>
//#include <assert.h>
#include <signal.h>
#endif
static inline void assert_impl(bool cond, const char *expression)
static void assert_impl(bool cond, const char *expression)
{
if(!cond)
{
fprintf(stderr, "Assertion failed: %s\n", expression);
#ifdef WEB
assert(false);
raise(SIGTRAP);
//assert(false);
#elif defined(DESKTOP)
__debugbreak();
#else
@ -23,3 +28,5 @@ static inline void assert_impl(bool cond, const char *expression)
#endif
#define assert(cond) assert_impl(cond, #cond)
#define Log(...) { printf("%s Log %d | ", __FILE__, __LINE__); printf(__VA_ARGS__); }

@ -216,7 +216,7 @@ body {
};
window.onerror = function(event) {
console.log("onerror: " + event.message);
for(;;) {}
//for(;;) {}
};
</script>
<script type="text/javascript">

Loading…
Cancel
Save