@@ -40,22 +40,33 @@ int16_t Object_LoadExtra(z64_game_t* play, int16_t objectId, uint8_t syncDma) {
4040 }
4141 }
4242
43- if (slot != -1 ) {
43+ if (slot != -1 ) {
4444 // Take the found slot
4545 z64_mem_obj_t * newEntry = & play -> obj_ctxt .objects [slot ]; // The new object
4646 z64_mem_obj_t * lastEntry = & play -> obj_ctxt .objects [play -> obj_ctxt .n_objects - 1 ]; // Previous last added object
4747 RomFile * lastObjectFile = & gObjectTable [ABS (lastEntry -> id )]; // Get previous object start pointer and size
4848 uint32_t lastSize = lastObjectFile -> vromEnd - lastObjectFile -> vromStart ;
4949 newEntry -> data = (void * )ALIGN16 ((uintptr_t )lastEntry -> data + lastSize ); // Gives pointer to start for the new object data
5050
51- func_800982FC (& play -> obj_ctxt , slot , objectId ); // Set up data for adding the object to the slot on next update
52- play -> obj_ctxt .n_objects ++ ;
51+ // Set up data for adding the object to the slot on next update or now
52+ if (func_800982FC (& play -> obj_ctxt , slot , objectId ) != NULL ) {
53+ play -> obj_ctxt .n_objects ++ ;
5354
54- if (syncDma ) {
55- play -> obj_ctxt .objects [slot ].id = objectId ; // Uninvert the id because it will get loaded now
56- RomFile * objectFile = & gObjectTable [ABS (objectId )]; // Get object start pointer and size
57- uint32_t size = objectFile -> vromEnd - objectFile -> vromStart ;
58- DmaMgr_RequestSync (newEntry -> data , objectFile -> vromStart , size );
55+ if (syncDma ) {
56+ play -> obj_ctxt .objects [slot ].id = objectId ; // Uninvert the id because it will get loaded now
57+ RomFile * objectFile = & gObjectTable [objectId ]; // Get object start pointer and size
58+ uint32_t size = objectFile -> vromEnd - objectFile -> vromStart ;
59+ DmaMgr_RequestSync (newEntry -> data , objectFile -> vromStart , size );
60+ }
61+
62+ } else { // Loading new object would exceed object space
63+ #ifdef DEBUG_MODE
64+ char msg [256 ];
65+ sprintf (msg , "Obj %d slot %d" , objectId , slot );
66+ Fault_AddHungupAndCrashImpl ("Object_LoadExtra: No memory" , msg );
67+ #endif
68+
69+ return -1 ; // Don't crash non-debug mode for now but this should not happen!
5970 }
6071 }
6172
0 commit comments